mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-02-01 11:59:26 +00:00
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
This commit is contained in:
parent
8353032129
commit
68572f1076
@ -925,6 +925,9 @@
|
||||
<File
|
||||
RelativePath=".\..\src\newgrf.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\..\src\newgrf_cargo.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\..\src\newgrf_config.cpp">
|
||||
</File>
|
||||
|
@ -448,11 +448,11 @@
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\..\src\autoreplace_cmd.cpp"
|
||||
RelativePath=".\..\src\aystar.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\..\src\aystar.cpp"
|
||||
RelativePath=".\..\src\autoreplace_cmd.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
@ -1455,6 +1455,10 @@
|
||||
RelativePath=".\..\src\newgrf.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\..\src\newgrf_cargo.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\..\src\newgrf_config.cpp"
|
||||
>
|
||||
|
@ -279,6 +279,7 @@ ai/trolly/trolly.cpp
|
||||
|
||||
# NewGRF
|
||||
newgrf.cpp
|
||||
newgrf_cargo.cpp
|
||||
newgrf_config.cpp
|
||||
newgrf_engine.cpp
|
||||
newgrf_house.cpp
|
||||
|
@ -42,6 +42,7 @@ struct CargoSpec {
|
||||
SpriteID sprite;
|
||||
|
||||
uint16 classes;
|
||||
const struct SpriteGroup *group;
|
||||
|
||||
bool IsValid() const;
|
||||
};
|
||||
|
@ -2217,6 +2217,7 @@ static void NewSpriteGroup(byte *buf, int len)
|
||||
case GSF_SHIP:
|
||||
case GSF_AIRCRAFT:
|
||||
case GSF_STATION:
|
||||
case GSF_CARGOS:
|
||||
{
|
||||
byte sprites = _cur_grffile->spriteset_numents;
|
||||
byte num_loaded = type;
|
||||
@ -2556,6 +2557,33 @@ static void TownHouseMapSpriteGroup(byte *buf, uint8 idcount, uint8 cidcount)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void CargoMapSpriteGroup(byte *buf, uint8 idcount, uint8 cidcount)
|
||||
{
|
||||
byte *bp = &buf[4 + idcount + cidcount * 3];
|
||||
uint16 groupid = grf_load_word(&bp);
|
||||
|
||||
if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
|
||||
grfmsg(1, "FeatureMapSpriteGroup: Spriteset 0x%04X out of range 0x%X or empty, skipping.",
|
||||
groupid, _cur_grffile->spritegroups_count);
|
||||
return;
|
||||
}
|
||||
|
||||
for (uint i = 0; i < idcount; i++) {
|
||||
CargoID cid = buf[3 + i];
|
||||
|
||||
if (cid >= NUM_CARGO) {
|
||||
grfmsg(1, "FeatureMapSpriteGroup: Cargo ID %d out of range, skipping");
|
||||
continue;
|
||||
}
|
||||
|
||||
CargoSpec *cs = &_cargo[cid];
|
||||
cs->grfid = _cur_grffile->grfid;
|
||||
cs->group = _cur_grffile->spritegroups[groupid];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Action 0x03 */
|
||||
static void FeatureMapSpriteGroup(byte *buf, int len)
|
||||
{
|
||||
@ -2614,6 +2642,10 @@ static void FeatureMapSpriteGroup(byte *buf, int len)
|
||||
TownHouseMapSpriteGroup(buf, idcount, cidcount);
|
||||
return;
|
||||
|
||||
case GSF_CARGOS:
|
||||
CargoMapSpriteGroup(buf, idcount, cidcount);
|
||||
return;
|
||||
|
||||
default:
|
||||
grfmsg(1, "FeatureMapSpriteGroup: Unsupported feature %d, skipping", feature);
|
||||
return;
|
||||
|
93
src/newgrf_cargo.cpp
Normal file
93
src/newgrf_cargo.cpp
Normal file
@ -0,0 +1,93 @@
|
||||
/* $Id$ */
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "openttd.h"
|
||||
#include "cargotype.h"
|
||||
#include "newgrf.h"
|
||||
#include "newgrf_callbacks.h"
|
||||
#include "newgrf_spritegroup.h"
|
||||
#include "newgrf_cargo.h"
|
||||
|
||||
|
||||
static uint32 CargoGetRandomBits(const ResolverObject *object)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static uint32 CargoGetTriggers(const ResolverObject *object)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void CargoSetTriggers(const ResolverObject *object, int triggers)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
static uint32 CargoGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available)
|
||||
{
|
||||
*available = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static const SpriteGroup *CargoResolveReal(const ResolverObject *object, const SpriteGroup *group)
|
||||
{
|
||||
/* Cargo action 2s should always have only 1 "loaded" state */
|
||||
if (group->g.real.num_loaded == 0) return NULL;
|
||||
|
||||
return group->g.real.loaded[0];
|
||||
}
|
||||
|
||||
|
||||
static void NewCargoResolver(ResolverObject *res, const CargoSpec *cs)
|
||||
{
|
||||
res->GetRandomBits = &CargoGetRandomBits;
|
||||
res->GetTriggers = &CargoGetTriggers;
|
||||
res->SetTriggers = &CargoSetTriggers;
|
||||
res->GetVariable = &CargoGetVariable;
|
||||
res->ResolveReal = &CargoResolveReal;
|
||||
|
||||
res->u.cargo.cs = cs;
|
||||
|
||||
res->callback = 0;
|
||||
res->callback_param1 = 0;
|
||||
res->callback_param2 = 0;
|
||||
res->last_value = 0;
|
||||
res->trigger = 0;
|
||||
res->reseed = 0;
|
||||
}
|
||||
|
||||
|
||||
SpriteID GetCustomCargoSprite(const CargoSpec *cs)
|
||||
{
|
||||
const SpriteGroup *group;
|
||||
ResolverObject object;
|
||||
|
||||
NewCargoResolver(&object, cs);
|
||||
|
||||
group = Resolve(cs->group, &object);
|
||||
if (group == NULL || group->type != SGT_RESULT) return 0;
|
||||
|
||||
return group->g.result.sprite;
|
||||
}
|
||||
|
||||
|
||||
uint16 GetCargoCallback(uint16 callback, uint32 param1, uint32 param2, const CargoSpec *cs)
|
||||
{
|
||||
ResolverObject object;
|
||||
const SpriteGroup *group;
|
||||
|
||||
NewCargoResolver(&object, cs);
|
||||
object.callback = callback;
|
||||
object.callback_param1 = param1;
|
||||
object.callback_param2 = param2;
|
||||
|
||||
group = Resolve(cs->group, &object);
|
||||
if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED;
|
||||
|
||||
return group->g.callback.result;
|
||||
}
|
@ -21,4 +21,9 @@ static const CargoID CT_DEFAULT = NUM_CARGO + 0;
|
||||
static const CargoID CT_PURCHASE = NUM_CARGO + 1;
|
||||
static const CargoID CT_DEFAULT_NA = NUM_CARGO + 2;
|
||||
|
||||
typedef struct CargoSpec;
|
||||
|
||||
SpriteID GetCustomCargoSprite(const CargoSpec *cs);
|
||||
uint16 GetCargoCallback(uint16 callback, uint32 param1, uint32 param2, const CargoSpec *cs);
|
||||
|
||||
#endif /* NEWGRF_CARGO_H */
|
||||
|
@ -191,6 +191,9 @@ struct ResolverObject {
|
||||
Town *town;
|
||||
HouseID house_id;
|
||||
} house;
|
||||
struct {
|
||||
const struct CargoSpec *cs;
|
||||
} cargo;
|
||||
} u;
|
||||
|
||||
uint32 (*GetRandomBits)(const struct ResolverObject*);
|
||||
|
@ -674,7 +674,16 @@ static void DrawCargoIcons(CargoID i, uint waiting, int x, int y)
|
||||
if (num == 0) return;
|
||||
|
||||
const CargoSpec *cs = GetCargo(i);
|
||||
SpriteID sprite = cs->sprite;
|
||||
SpriteID sprite;
|
||||
|
||||
if (cs->sprite == 0xFFFF) {
|
||||
/* A value of 0xFFFF indicates we should draw a custom icon */
|
||||
sprite = GetCustomCargoSprite(cs);
|
||||
} else {
|
||||
sprite = cs->sprite;
|
||||
}
|
||||
|
||||
if (sprite == 0) return;
|
||||
|
||||
do {
|
||||
DrawSprite(sprite, PAL_NONE, x, y);
|
||||
|
@ -3,7 +3,7 @@
|
||||
/* Table of all default cargo types */
|
||||
|
||||
#define MK(bt, label, c, e, f, g, h, fr, te, ks1, ks2, ks3, ks4, ks5, l, m) \
|
||||
{bt, label, 0, c, c, e, f, {g, h}, fr, te, 0, 0, ks1, ks2, ks3, ks4, ks5, l, m}
|
||||
{bt, label, 0, c, c, e, f, {g, h}, fr, te, 0, 0, ks1, ks2, ks3, ks4, ks5, l, m, NULL}
|
||||
static const CargoSpec _default_cargo[] = {
|
||||
MK( 0, 'PASS', 152, 1, 3185, 0, 24, false, TE_PASSENGERS,
|
||||
STR_000F_PASSENGERS, STR_002F_PASSENGER, STR_PASSENGERS, STR_QUANTITY_PASSENGERS, STR_ABBREV_PASSENGERS,
|
||||
|
Loading…
Reference in New Issue
Block a user