2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2005-02-05 15:58:59 +00:00
|
|
|
#include "debug.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "gfx.h"
|
|
|
|
#include "fileio.h"
|
2005-07-22 07:02:20 +00:00
|
|
|
#include "functions.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "engine.h"
|
2005-08-15 11:39:13 +00:00
|
|
|
#include "spritecache.h"
|
2004-11-14 09:07:15 +00:00
|
|
|
#include "station.h"
|
2004-11-14 16:42:08 +00:00
|
|
|
#include "sprite.h"
|
2004-11-17 18:49:55 +00:00
|
|
|
#include "newgrf.h"
|
2005-07-21 22:15:02 +00:00
|
|
|
#include "variables.h"
|
2006-04-16 11:33:26 +00:00
|
|
|
#include "string.h"
|
2006-05-11 16:27:46 +00:00
|
|
|
#include "table/strings.h"
|
2005-10-01 17:38:48 +00:00
|
|
|
#include "bridge.h"
|
2005-10-12 07:27:56 +00:00
|
|
|
#include "economy.h"
|
2006-02-03 12:55:21 +00:00
|
|
|
#include "newgrf_engine.h"
|
2006-04-18 05:16:13 +00:00
|
|
|
#include "vehicle.h"
|
2006-04-21 03:00:20 +00:00
|
|
|
#include "newgrf_text.h"
|
2006-05-01 16:54:18 +00:00
|
|
|
#include "table/sprites.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-20 20:51:57 +00:00
|
|
|
#include "newgrf_spritegroup.h"
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
/* TTDPatch extended GRF format codec
|
|
|
|
* (c) Petr Baudis 2004 (GPL'd)
|
2004-11-12 15:15:56 +00:00
|
|
|
* Changes by Florian octo Forster are (c) by the OpenTTD development team.
|
|
|
|
*
|
2004-08-09 17:04:08 +00:00
|
|
|
* Contains portions of documentation by TTDPatch team.
|
|
|
|
* Thanks especially to Josef Drexler for the documentation as well as a lot
|
|
|
|
* of help at #tycoon. Also thanks to Michael Blunck for is GRF files which
|
|
|
|
* served as subject to the initial testing of this codec. */
|
|
|
|
|
2004-11-17 20:08:13 +00:00
|
|
|
|
2005-08-15 11:39:13 +00:00
|
|
|
uint16 _custom_sprites_base;
|
|
|
|
static int _skip_sprites; // XXX
|
|
|
|
static uint _file_index; // XXX
|
2006-04-23 15:57:34 +00:00
|
|
|
SpriteID _signal_base = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-08-14 18:10:18 +00:00
|
|
|
static GRFFile *_cur_grffile;
|
2005-03-10 07:01:43 +00:00
|
|
|
GRFFile *_first_grffile;
|
2006-04-22 13:17:13 +00:00
|
|
|
GRFConfig *_first_grfconfig;
|
2006-05-01 16:52:43 +00:00
|
|
|
static SpriteID _cur_spriteid;
|
2004-11-12 23:26:02 +00:00
|
|
|
static int _cur_stage;
|
2006-04-15 21:27:59 +00:00
|
|
|
static uint32 _nfo_line;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-05-11 12:41:02 +00:00
|
|
|
/* Miscellaneous GRF features, set by Action 0x0D, parameter 0x9E */
|
|
|
|
static byte _misc_grf_features = 0;
|
|
|
|
|
2004-11-12 19:03:37 +00:00
|
|
|
/* 32 * 8 = 256 flags. Apparently TTDPatch uses this many.. */
|
|
|
|
static uint32 _ttdpatch_flags[8];
|
|
|
|
|
|
|
|
|
2005-03-10 07:01:43 +00:00
|
|
|
typedef enum grfspec_feature {
|
2004-11-13 12:38:38 +00:00
|
|
|
GSF_TRAIN,
|
|
|
|
GSF_ROAD,
|
|
|
|
GSF_SHIP,
|
|
|
|
GSF_AIRCRAFT,
|
|
|
|
GSF_STATION,
|
2005-09-20 09:38:09 +00:00
|
|
|
GSF_CANAL,
|
2004-11-14 10:03:21 +00:00
|
|
|
GSF_BRIDGE,
|
|
|
|
GSF_TOWNHOUSE,
|
2005-10-12 07:27:56 +00:00
|
|
|
GSF_GLOBALVAR,
|
2006-04-22 06:54:25 +00:00
|
|
|
GSF_INDUSTRYTILES,
|
|
|
|
GSF_INDUSTRIES,
|
|
|
|
GSF_CARGOS,
|
|
|
|
GSF_SOUNDFX,
|
2005-03-10 07:01:43 +00:00
|
|
|
} grfspec_feature;
|
2004-11-13 12:38:38 +00:00
|
|
|
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
typedef void (*SpecialSpriteHandler)(byte *buf, int len);
|
|
|
|
|
2004-11-13 12:21:32 +00:00
|
|
|
static const int _vehcounts[4] = {
|
2004-11-13 12:38:38 +00:00
|
|
|
/* GSF_TRAIN */ NUM_TRAIN_ENGINES,
|
|
|
|
/* GSF_ROAD */ NUM_ROAD_ENGINES,
|
|
|
|
/* GSF_SHIP */ NUM_SHIP_ENGINES,
|
|
|
|
/* GSF_AIRCRAFT */ NUM_AIRCRAFT_ENGINES
|
2004-11-13 12:21:32 +00:00
|
|
|
};
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
static const int _vehshifts[4] = {
|
2004-11-13 12:38:38 +00:00
|
|
|
/* GSF_TRAIN */ 0,
|
|
|
|
/* GSF_ROAD */ ROAD_ENGINES_INDEX,
|
|
|
|
/* GSF_SHIP */ SHIP_ENGINES_INDEX,
|
|
|
|
/* GSF_AIRCRAFT */ AIRCRAFT_ENGINES_INDEX,
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2006-05-06 22:20:16 +00:00
|
|
|
enum {
|
|
|
|
MAX_STATIONS = 256,
|
|
|
|
};
|
|
|
|
|
2005-11-06 13:42:26 +00:00
|
|
|
static uint16 cargo_allowed[TOTAL_NUM_ENGINES];
|
|
|
|
static uint16 cargo_disallowed[TOTAL_NUM_ENGINES];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-11-13 18:08:45 +00:00
|
|
|
/* Debugging messages policy:
|
|
|
|
*
|
|
|
|
* These should be the severities used for direct DEBUG() calls
|
|
|
|
* (there is room for exceptions, but you have to have a good cause):
|
|
|
|
*
|
|
|
|
* 0..2 - dedicated to grfmsg()
|
|
|
|
* 3
|
|
|
|
* 4
|
|
|
|
* 5
|
|
|
|
* 6 - action handler entry reporting - one per action
|
|
|
|
* 7 - basic action progress reporting - in loops, only single one allowed
|
|
|
|
* 8 - more detailed progress reporting - less important stuff, in deep loops etc
|
|
|
|
* 9 - extremely detailed progress reporting - detailed reports inside of deep loops and so
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2005-03-10 07:01:43 +00:00
|
|
|
typedef enum grfmsg_severity {
|
2004-08-09 17:04:08 +00:00
|
|
|
GMS_NOTICE,
|
|
|
|
GMS_WARN,
|
|
|
|
GMS_ERROR,
|
|
|
|
GMS_FATAL,
|
2005-03-10 07:01:43 +00:00
|
|
|
} grfmsg_severity;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-03-10 07:01:43 +00:00
|
|
|
static void CDECL grfmsg(grfmsg_severity severity, const char *str, ...)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-03-10 07:01:43 +00:00
|
|
|
static const char* const severitystr[] = {
|
|
|
|
"Notice",
|
|
|
|
"Warning",
|
|
|
|
"Error",
|
|
|
|
"Fatal"
|
|
|
|
};
|
2004-11-13 12:21:32 +00:00
|
|
|
int export_severity = 0;
|
2004-08-16 14:48:35 +00:00
|
|
|
char buf[1024];
|
2004-08-09 17:04:08 +00:00
|
|
|
va_list va;
|
|
|
|
|
|
|
|
va_start(va, str);
|
2005-03-10 07:01:43 +00:00
|
|
|
vsnprintf(buf, sizeof(buf), str, va);
|
2004-08-09 17:04:08 +00:00
|
|
|
va_end(va);
|
2004-11-13 12:21:32 +00:00
|
|
|
|
|
|
|
export_severity = 2 - (severity == GMS_FATAL ? 2 : severity);
|
2006-04-15 16:40:54 +00:00
|
|
|
DEBUG(grf, export_severity) ("[%s:%d][%s] %s", _cur_grffile->filename, _nfo_line, severitystr[severity], buf);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2004-11-12 15:36:49 +00:00
|
|
|
|
|
|
|
#define check_length(real, wanted, where) \
|
|
|
|
do { \
|
|
|
|
if (real < wanted) { \
|
2006-01-13 18:40:39 +00:00
|
|
|
grfmsg(GMS_ERROR, "%s: Invalid special sprite length %d (expected %d)!", \
|
|
|
|
where, real, wanted); \
|
2004-11-12 15:36:49 +00:00
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
2004-11-24 13:19:48 +00:00
|
|
|
static inline byte grf_load_byte(byte **buf)
|
2004-11-12 23:26:02 +00:00
|
|
|
{
|
2004-08-09 17:04:08 +00:00
|
|
|
return *(*buf)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint16 grf_load_word(byte **buf)
|
|
|
|
{
|
2006-05-01 21:45:35 +00:00
|
|
|
uint16 val = grf_load_byte(buf);
|
|
|
|
return val | (grf_load_byte(buf) << 8);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-08-15 22:48:33 +00:00
|
|
|
static uint16 grf_load_extended(byte** buf)
|
|
|
|
{
|
|
|
|
uint16 val;
|
|
|
|
val = grf_load_byte(buf);
|
|
|
|
if (val == 0xFF) val = grf_load_word(buf);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2005-08-11 12:51:59 +00:00
|
|
|
static uint32 grf_load_dword(byte **buf)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-05-01 21:45:35 +00:00
|
|
|
uint32 val = grf_load_word(buf);
|
|
|
|
return val | (grf_load_word(buf) << 16);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-04-26 20:44:28 +00:00
|
|
|
static uint32 grf_load_var(byte size, byte **buf)
|
|
|
|
{
|
|
|
|
switch (size) {
|
|
|
|
case 1: return grf_load_byte(buf);
|
|
|
|
case 2: return grf_load_word(buf);
|
|
|
|
case 4: return grf_load_dword(buf);
|
|
|
|
default:
|
|
|
|
NOT_REACHED();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2004-11-12 15:36:49 +00:00
|
|
|
|
2005-03-10 07:01:43 +00:00
|
|
|
static GRFFile *GetFileByGRFID(uint32 grfid)
|
2004-11-12 22:28:19 +00:00
|
|
|
{
|
2005-03-10 07:01:43 +00:00
|
|
|
GRFFile *file;
|
2004-11-12 22:28:19 +00:00
|
|
|
|
2005-03-10 07:01:43 +00:00
|
|
|
for (file = _first_grffile; file != NULL; file = file->next) {
|
|
|
|
if (file->grfid == grfid) break;
|
|
|
|
}
|
2004-11-12 22:28:19 +00:00
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
2005-03-10 07:01:43 +00:00
|
|
|
static GRFFile *GetFileByFilename(const char *filename)
|
2004-11-12 22:28:19 +00:00
|
|
|
{
|
2005-03-10 07:01:43 +00:00
|
|
|
GRFFile *file;
|
2004-11-12 22:28:19 +00:00
|
|
|
|
2005-03-10 07:01:43 +00:00
|
|
|
for (file = _first_grffile; file != NULL; file = file->next) {
|
|
|
|
if (strcmp(file->filename, filename) == 0) break;
|
|
|
|
}
|
2004-11-12 22:28:19 +00:00
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-12 18:43:12 +00:00
|
|
|
typedef bool (*VCI_Handler)(uint engine, int numinfo, int prop, byte **buf, int len);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-11-17 01:00:04 +00:00
|
|
|
#define FOR_EACH_OBJECT for (i = 0; i < numinfo; i++)
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
static void dewagonize(int condition, int engine)
|
|
|
|
{
|
|
|
|
EngineInfo *ei = &_engine_info[engine];
|
|
|
|
RailVehicleInfo *rvi = &_rail_vehicle_info[engine];
|
|
|
|
|
2004-11-13 12:21:32 +00:00
|
|
|
if (condition != 0) {
|
2004-08-09 17:04:08 +00:00
|
|
|
ei->unk2 &= ~0x80;
|
|
|
|
rvi->flags &= ~2;
|
|
|
|
} else {
|
|
|
|
ei->unk2 |= 0x80;
|
|
|
|
rvi->flags |= 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-12 18:43:12 +00:00
|
|
|
static bool RailVehicleChangeInfo(uint engine, int numinfo, int prop, byte **bufp, int len)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
EngineInfo *ei = &_engine_info[engine];
|
|
|
|
RailVehicleInfo *rvi = &_rail_vehicle_info[engine];
|
|
|
|
byte *buf = *bufp;
|
|
|
|
int i;
|
2004-11-12 18:43:12 +00:00
|
|
|
bool ret = false;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
switch (prop) {
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x05: /* Track type */
|
2004-11-17 01:00:04 +00:00
|
|
|
FOR_EACH_OBJECT {
|
2004-08-09 17:04:08 +00:00
|
|
|
uint8 tracktype = grf_load_byte(&buf);
|
|
|
|
|
2006-02-15 12:53:36 +00:00
|
|
|
switch (tracktype) {
|
|
|
|
case 0: ei[i].railtype = RAILTYPE_RAIL; break;
|
|
|
|
case 1: ei[i].railtype = RAILTYPE_MONO; break;
|
|
|
|
case 2: ei[i].railtype = RAILTYPE_MAGLEV; break;
|
|
|
|
default:
|
|
|
|
grfmsg(GMS_WARN, "RailVehicleChangeInfo: Invalid track type %d specified, ignoring.", tracktype);
|
|
|
|
break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2006-02-15 12:53:36 +00:00
|
|
|
break;
|
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x08: /* AI passenger service */
|
2004-08-09 17:04:08 +00:00
|
|
|
/* TODO */
|
2006-02-27 15:35:22 +00:00
|
|
|
FOR_EACH_OBJECT grf_load_byte(&buf);
|
2004-11-12 18:43:12 +00:00
|
|
|
ret = true;
|
2006-02-27 15:35:22 +00:00
|
|
|
break;
|
|
|
|
|
2006-04-09 18:08:20 +00:00
|
|
|
case 0x09: /* Speed (1 unit is 1 kmh) */
|
2004-11-17 01:00:04 +00:00
|
|
|
FOR_EACH_OBJECT {
|
2004-08-09 17:04:08 +00:00
|
|
|
uint16 speed = grf_load_word(&buf);
|
2006-02-18 14:41:24 +00:00
|
|
|
if (speed == 0xFFFF) speed = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
rvi[i].max_speed = speed;
|
|
|
|
}
|
2006-02-27 15:35:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x0B: /* Power */
|
2004-11-17 01:00:04 +00:00
|
|
|
FOR_EACH_OBJECT {
|
2004-08-09 17:04:08 +00:00
|
|
|
uint16 power = grf_load_word(&buf);
|
|
|
|
|
2006-02-18 14:41:24 +00:00
|
|
|
if (rvi[i].flags & RVI_MULTIHEAD) power /= 2;
|
2005-06-02 21:38:50 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
rvi[i].power = power;
|
|
|
|
dewagonize(power, engine + i);
|
|
|
|
}
|
2006-02-27 15:35:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x0D: /* Running cost factor */
|
2004-11-17 01:00:04 +00:00
|
|
|
FOR_EACH_OBJECT {
|
2004-08-09 17:04:08 +00:00
|
|
|
uint8 runcostfact = grf_load_byte(&buf);
|
|
|
|
|
2006-02-18 14:41:24 +00:00
|
|
|
if (rvi[i].flags & RVI_MULTIHEAD) runcostfact /= 2;
|
2006-01-07 13:20:02 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
rvi[i].running_cost_base = runcostfact;
|
|
|
|
}
|
2006-02-27 15:35:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x0E: /* Running cost base */
|
2004-11-17 01:00:04 +00:00
|
|
|
FOR_EACH_OBJECT {
|
2004-08-09 17:04:08 +00:00
|
|
|
uint32 base = grf_load_dword(&buf);
|
|
|
|
|
|
|
|
switch (base) {
|
2006-01-07 16:47:59 +00:00
|
|
|
case 0x4C30: rvi[i].running_cost_class = 0; break;
|
|
|
|
case 0x4C36: rvi[i].running_cost_class = 1; break;
|
|
|
|
case 0x4C3C: rvi[i].running_cost_class = 2; break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
2006-02-27 15:35:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x12: /* Sprite ID */
|
2004-11-17 01:00:04 +00:00
|
|
|
FOR_EACH_OBJECT {
|
2004-08-09 17:04:08 +00:00
|
|
|
uint8 spriteid = grf_load_byte(&buf);
|
|
|
|
|
2006-01-27 07:13:58 +00:00
|
|
|
/* TTD sprite IDs point to a location in a 16bit array, but we use it
|
|
|
|
* as an array index, so we need it to be half the original value. */
|
2006-02-18 14:41:24 +00:00
|
|
|
if (spriteid < 0xFD) spriteid >>= 1;
|
2006-01-27 07:13:58 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
rvi[i].image_index = spriteid;
|
|
|
|
}
|
2006-02-27 15:35:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x13: /* Dual-headed */
|
2004-11-17 01:00:04 +00:00
|
|
|
FOR_EACH_OBJECT {
|
2004-08-09 17:04:08 +00:00
|
|
|
uint8 dual = grf_load_byte(&buf);
|
|
|
|
|
2004-11-13 12:21:32 +00:00
|
|
|
if (dual != 0) {
|
2006-01-07 13:20:02 +00:00
|
|
|
if (!(rvi[i].flags & RVI_MULTIHEAD)) {
|
|
|
|
// adjust power and running cost if needed
|
2005-06-02 21:38:50 +00:00
|
|
|
rvi[i].power /= 2;
|
2006-01-07 13:20:02 +00:00
|
|
|
rvi[i].running_cost_base /= 2;
|
|
|
|
}
|
2005-06-02 21:38:50 +00:00
|
|
|
rvi[i].flags |= RVI_MULTIHEAD;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2006-01-07 13:20:02 +00:00
|
|
|
if (rvi[i].flags & RVI_MULTIHEAD) {
|
|
|
|
// adjust power and running cost if needed
|
2005-06-02 21:38:50 +00:00
|
|
|
rvi[i].power *= 2;
|
2006-01-07 16:47:59 +00:00
|
|
|
rvi[i].running_cost_base *= 2;
|
2006-01-07 13:20:02 +00:00
|
|
|
}
|
2005-06-02 21:38:50 +00:00
|
|
|
rvi[i].flags &= ~RVI_MULTIHEAD;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
2006-02-27 15:35:22 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x14: /* Cargo capacity */
|
|
|
|
FOR_EACH_OBJECT rvi[i].capacity = grf_load_byte(&buf);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x15: /* Cargo type */
|
2004-11-17 01:00:04 +00:00
|
|
|
FOR_EACH_OBJECT {
|
2004-08-09 17:04:08 +00:00
|
|
|
uint8 ctype = grf_load_byte(&buf);
|
|
|
|
|
2006-01-12 07:57:40 +00:00
|
|
|
if (ctype < NUM_CARGO) {
|
|
|
|
rvi[i].cargo_type = ctype;
|
|
|
|
} else {
|
|
|
|
grfmsg(GMS_NOTICE, "RailVehicleChangeInfo: Invalid cargo type %d, ignoring.", ctype);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2006-02-27 15:35:22 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x16: /* Weight */
|
|
|
|
FOR_EACH_OBJECT SB(rvi[i].weight, 0, 8, grf_load_byte(&buf));
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x17: /* Cost factor */
|
|
|
|
FOR_EACH_OBJECT rvi[i].base_cost = grf_load_byte(&buf);
|
|
|
|
break;
|
2006-02-13 22:19:23 +00:00
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x18: /* AI rank */
|
|
|
|
FOR_EACH_OBJECT rvi[i].ai_rank = grf_load_byte(&buf);
|
2006-02-13 22:19:23 +00:00
|
|
|
break;
|
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x19: /* Engine traction type */
|
2006-01-07 13:26:52 +00:00
|
|
|
/* What do the individual numbers mean?
|
|
|
|
* 0x00 .. 0x07: Steam
|
|
|
|
* 0x08 .. 0x27: Diesel
|
|
|
|
* 0x28 .. 0x31: Electric
|
|
|
|
* 0x32 .. 0x37: Monorail
|
|
|
|
* 0x38 .. 0x41: Maglev
|
|
|
|
*/
|
2004-11-17 01:00:04 +00:00
|
|
|
FOR_EACH_OBJECT {
|
2004-08-09 17:04:08 +00:00
|
|
|
uint8 traction = grf_load_byte(&buf);
|
|
|
|
int engclass;
|
|
|
|
|
2006-02-18 14:41:24 +00:00
|
|
|
if (traction <= 0x07) {
|
2004-08-09 17:04:08 +00:00
|
|
|
engclass = 0;
|
2006-02-18 14:41:24 +00:00
|
|
|
} else if (traction <= 0x27) {
|
2004-08-09 17:04:08 +00:00
|
|
|
engclass = 1;
|
2006-03-29 16:30:26 +00:00
|
|
|
} else if (traction <= 0x31) {
|
|
|
|
engclass = 2;
|
|
|
|
ei[i].railtype = RAILTYPE_ELECTRIC;
|
2006-02-18 14:41:24 +00:00
|
|
|
} else if (traction <= 0x41) {
|
2004-08-09 17:04:08 +00:00
|
|
|
engclass = 2;
|
2006-02-18 14:41:24 +00:00
|
|
|
} else {
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
2006-02-18 14:41:24 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
rvi[i].engclass = engclass;
|
|
|
|
}
|
2006-02-27 15:35:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x1A: /* Alter purchase list sort order */
|
2006-02-04 21:48:46 +00:00
|
|
|
FOR_EACH_OBJECT {
|
|
|
|
EngineID pos = grf_load_byte(&buf);
|
|
|
|
|
|
|
|
if (pos < NUM_TRAIN_ENGINES) {
|
|
|
|
AlterRailVehListOrder(engine + i, pos);
|
|
|
|
} else {
|
|
|
|
grfmsg(GMS_NOTICE, "RailVehicleChangeInfo: Invalid train engine ID %d, ignoring.", pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x1B: /* Powered wagons power bonus */
|
|
|
|
FOR_EACH_OBJECT rvi[i].pow_wag_power = grf_load_word(&buf);
|
|
|
|
break;
|
2005-06-06 00:19:24 +00:00
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x1D: /* Refit cargo */
|
2006-02-28 08:13:15 +00:00
|
|
|
FOR_EACH_OBJECT ei[i].refit_mask = grf_load_dword(&buf);
|
2006-02-27 15:35:22 +00:00
|
|
|
break;
|
2004-11-17 01:09:15 +00:00
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x1E: /* Callback */
|
|
|
|
FOR_EACH_OBJECT rvi[i].callbackmask = grf_load_byte(&buf);
|
|
|
|
break;
|
2005-06-06 22:44:11 +00:00
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x21: /* Shorter vehicle */
|
|
|
|
FOR_EACH_OBJECT rvi[i].shorten_factor = grf_load_byte(&buf);
|
|
|
|
break;
|
2005-06-06 22:44:11 +00:00
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x22: /* Visual effect */
|
2005-06-06 00:19:24 +00:00
|
|
|
// see note in engine.h about rvi->visual_effect
|
2006-02-27 15:35:22 +00:00
|
|
|
FOR_EACH_OBJECT rvi[i].visual_effect = grf_load_byte(&buf);
|
|
|
|
break;
|
2005-06-06 00:19:24 +00:00
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x23: /* Powered wagons weight bonus */
|
|
|
|
FOR_EACH_OBJECT rvi[i].pow_wag_weight = grf_load_byte(&buf);
|
|
|
|
break;
|
2005-06-06 00:19:24 +00:00
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x24: /* High byte of vehicle weight */
|
2005-10-20 15:15:58 +00:00
|
|
|
FOR_EACH_OBJECT {
|
|
|
|
byte weight = grf_load_byte(&buf);
|
|
|
|
|
2005-10-20 19:44:41 +00:00
|
|
|
if (weight > 4) {
|
2005-10-20 15:15:58 +00:00
|
|
|
grfmsg(GMS_NOTICE, "RailVehicleChangeInfo: Nonsensical weight of %d tons, ignoring.", weight << 8);
|
|
|
|
} else {
|
|
|
|
SB(rvi[i].weight, 8, 8, weight);
|
|
|
|
}
|
|
|
|
}
|
2006-02-27 15:35:22 +00:00
|
|
|
break;
|
|
|
|
|
2006-05-17 08:20:36 +00:00
|
|
|
case 0x25: /* User-defined bit mask to set when checking veh. var. 42 */
|
|
|
|
FOR_EACH_OBJECT rvi[i].user_def_data = grf_load_byte(&buf);
|
|
|
|
break;
|
|
|
|
|
2006-02-28 08:13:15 +00:00
|
|
|
case 0x27: /* Miscellaneous flags */
|
|
|
|
FOR_EACH_OBJECT ei[i].misc_flags = grf_load_byte(&buf);
|
|
|
|
break;
|
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x28: /* Cargo classes allowed */
|
|
|
|
FOR_EACH_OBJECT cargo_allowed[engine + i] = grf_load_word(&buf);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x29: /* Cargo classes disallowed */
|
|
|
|
FOR_EACH_OBJECT cargo_disallowed[engine + i] = grf_load_word(&buf);
|
|
|
|
break;
|
|
|
|
|
2005-06-06 00:19:24 +00:00
|
|
|
/* TODO */
|
2004-08-09 17:04:08 +00:00
|
|
|
/* Fall-through for unimplemented one byte long properties. */
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x1C: /* Refit cost */
|
|
|
|
case 0x1F: /* Tractive effort */
|
|
|
|
case 0x20: /* Air drag */
|
|
|
|
case 0x26: /* Retire vehicle early */
|
2004-08-09 17:04:08 +00:00
|
|
|
/* TODO */
|
2006-02-27 15:35:22 +00:00
|
|
|
FOR_EACH_OBJECT grf_load_byte(&buf);
|
2004-11-12 18:43:12 +00:00
|
|
|
ret = true;
|
2006-02-27 15:35:22 +00:00
|
|
|
break;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
default:
|
2004-11-12 18:43:12 +00:00
|
|
|
ret = true;
|
2006-02-27 15:35:22 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
*bufp = buf;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-11-13 18:01:33 +00:00
|
|
|
static bool RoadVehicleChangeInfo(uint engine, int numinfo, int prop, byte **bufp, int len)
|
|
|
|
{
|
2006-02-28 08:13:15 +00:00
|
|
|
EngineInfo *ei = &_engine_info[ROAD_ENGINES_INDEX + engine];
|
2004-11-13 18:01:33 +00:00
|
|
|
RoadVehicleInfo *rvi = &_road_vehicle_info[engine];
|
|
|
|
byte *buf = *bufp;
|
|
|
|
int i;
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
switch (prop) {
|
2006-04-09 18:08:20 +00:00
|
|
|
case 0x08: /* Speed (1 unit is 0.5 kmh) */
|
|
|
|
FOR_EACH_OBJECT rvi[i].max_speed = grf_load_byte(&buf);
|
2006-02-27 15:35:22 +00:00
|
|
|
break;
|
2004-11-13 18:01:33 +00:00
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x09: /* Running cost factor */
|
|
|
|
FOR_EACH_OBJECT rvi[i].running_cost = grf_load_byte(&buf);
|
|
|
|
break;
|
2004-11-13 18:01:33 +00:00
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x0A: /* Running cost base */
|
2004-11-13 18:01:33 +00:00
|
|
|
/* TODO: I have no idea. --pasky */
|
2006-02-27 15:35:22 +00:00
|
|
|
FOR_EACH_OBJECT grf_load_dword(&buf);
|
2004-11-13 18:01:33 +00:00
|
|
|
ret = true;
|
2006-02-27 15:35:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x0E: /* Sprite ID */
|
2004-11-17 01:00:04 +00:00
|
|
|
FOR_EACH_OBJECT {
|
2004-11-13 18:01:33 +00:00
|
|
|
uint8 spriteid = grf_load_byte(&buf);
|
|
|
|
|
2006-02-18 14:41:24 +00:00
|
|
|
// cars have different custom id in the GRF file
|
|
|
|
if (spriteid == 0xFF) spriteid = 0xFD;
|
2004-11-13 18:01:33 +00:00
|
|
|
|
2006-02-18 14:41:24 +00:00
|
|
|
if (spriteid < 0xFD) spriteid >>= 1;
|
2006-01-27 07:13:58 +00:00
|
|
|
|
2004-11-13 18:01:33 +00:00
|
|
|
rvi[i].image_index = spriteid;
|
|
|
|
}
|
2006-02-27 15:35:22 +00:00
|
|
|
break;
|
2004-11-13 18:01:33 +00:00
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x0F: /* Cargo capacity */
|
|
|
|
FOR_EACH_OBJECT rvi[i].capacity = grf_load_byte(&buf);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x10: /* Cargo type */
|
2004-11-17 01:00:04 +00:00
|
|
|
FOR_EACH_OBJECT {
|
2004-11-13 18:01:33 +00:00
|
|
|
uint8 cargo = grf_load_byte(&buf);
|
|
|
|
|
2006-01-12 07:57:40 +00:00
|
|
|
if (cargo < NUM_CARGO) {
|
|
|
|
rvi[i].cargo_type = cargo;
|
|
|
|
} else {
|
|
|
|
grfmsg(GMS_NOTICE, "RoadVehicleChangeInfo: Invalid cargo type %d, ignoring.", cargo);
|
|
|
|
}
|
2004-11-13 18:01:33 +00:00
|
|
|
}
|
2006-02-27 15:35:22 +00:00
|
|
|
break;
|
2004-11-13 18:01:33 +00:00
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x11: /* Cost factor */
|
|
|
|
FOR_EACH_OBJECT rvi[i].base_cost = grf_load_byte(&buf); // ?? is it base_cost?
|
|
|
|
break;
|
2004-11-13 18:01:33 +00:00
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x12: /* SFX */
|
|
|
|
FOR_EACH_OBJECT rvi[i].sfx = grf_load_byte(&buf);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x13: /* Power in 10hp */
|
|
|
|
case 0x14: /* Weight in 1/4 tons */
|
|
|
|
case 0x15: /* Speed in mph*0.8 */
|
2004-11-13 18:01:33 +00:00
|
|
|
/* TODO: Support for road vehicles realistic power
|
|
|
|
* computations (called rvpower in TTDPatch) is just
|
|
|
|
* missing in OTTD yet. --pasky */
|
2006-02-27 15:35:22 +00:00
|
|
|
FOR_EACH_OBJECT grf_load_byte(&buf);
|
2004-11-13 18:01:33 +00:00
|
|
|
ret = true;
|
|
|
|
break;
|
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x16: /* Cargos available for refitting */
|
2006-02-28 08:13:15 +00:00
|
|
|
FOR_EACH_OBJECT ei[i].refit_mask = grf_load_dword(&buf);
|
2006-02-27 15:35:22 +00:00
|
|
|
break;
|
2006-02-11 07:34:05 +00:00
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x17: /* Callback mask */
|
|
|
|
FOR_EACH_OBJECT rvi[i].callbackmask = grf_load_byte(&buf);
|
2006-02-11 07:34:05 +00:00
|
|
|
break;
|
|
|
|
|
2006-02-28 08:13:15 +00:00
|
|
|
case 0x1C: /* Miscellaneous flags */
|
|
|
|
FOR_EACH_OBJECT ei[i].misc_flags = grf_load_byte(&buf);
|
|
|
|
break;
|
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x1D: /* Cargo classes allowed */
|
|
|
|
FOR_EACH_OBJECT cargo_allowed[ROAD_ENGINES_INDEX + engine + i] = grf_load_word(&buf);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x1E: /* Cargo classes disallowed */
|
|
|
|
FOR_EACH_OBJECT cargo_disallowed[ROAD_ENGINES_INDEX + engine + i] = grf_load_word(&buf);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x18: /* Tractive effort */
|
|
|
|
case 0x19: /* Air drag */
|
|
|
|
case 0x1A: /* Refit cost */
|
|
|
|
case 0x1B: /* Retire vehicle early */
|
2004-11-13 18:01:33 +00:00
|
|
|
/* TODO */
|
2006-02-27 15:35:22 +00:00
|
|
|
FOR_EACH_OBJECT grf_load_byte(&buf);
|
2004-11-13 18:01:33 +00:00
|
|
|
ret = true;
|
|
|
|
break;
|
2006-02-27 15:35:22 +00:00
|
|
|
|
2004-11-13 18:01:33 +00:00
|
|
|
default:
|
|
|
|
ret = true;
|
2006-02-27 15:35:22 +00:00
|
|
|
break;
|
2004-11-13 18:01:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*bufp = buf;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-11-12 18:43:12 +00:00
|
|
|
static bool ShipVehicleChangeInfo(uint engine, int numinfo, int prop, byte **bufp, int len)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-02-28 08:13:15 +00:00
|
|
|
EngineInfo *ei = &_engine_info[SHIP_ENGINES_INDEX + engine];
|
2004-08-09 17:04:08 +00:00
|
|
|
ShipVehicleInfo *svi = &_ship_vehicle_info[engine];
|
|
|
|
byte *buf = *bufp;
|
|
|
|
int i;
|
2004-11-12 18:43:12 +00:00
|
|
|
bool ret = false;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
//printf("e %x prop %x?\n", engine, prop);
|
|
|
|
switch (prop) {
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x08: /* Sprite ID */
|
2004-11-17 01:00:04 +00:00
|
|
|
FOR_EACH_OBJECT {
|
2004-08-09 17:04:08 +00:00
|
|
|
uint8 spriteid = grf_load_byte(&buf);
|
|
|
|
|
2006-02-18 14:41:24 +00:00
|
|
|
// ships have different custom id in the GRF file
|
|
|
|
if (spriteid == 0xFF) spriteid = 0xFD;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-18 14:41:24 +00:00
|
|
|
if (spriteid < 0xFD) spriteid >>= 1;
|
2006-01-27 07:13:58 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
svi[i].image_index = spriteid;
|
|
|
|
}
|
2006-02-27 15:35:22 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x09: /* Refittable */
|
|
|
|
FOR_EACH_OBJECT svi[i].refittable = grf_load_byte(&buf);
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x0A: /* Cost factor */
|
|
|
|
FOR_EACH_OBJECT svi[i].base_cost = grf_load_byte(&buf); // ?? is it base_cost?
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-09 18:08:20 +00:00
|
|
|
case 0x0B: /* Speed (1 unit is 0.5 kmh) */
|
|
|
|
FOR_EACH_OBJECT svi[i].max_speed = grf_load_byte(&buf);
|
2006-02-27 15:35:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x0C: /* Cargo type */
|
2004-11-17 01:00:04 +00:00
|
|
|
FOR_EACH_OBJECT {
|
2004-08-09 17:04:08 +00:00
|
|
|
uint8 cargo = grf_load_byte(&buf);
|
|
|
|
|
|
|
|
// XXX: Need to consult this with patchman yet.
|
|
|
|
#if 0
|
|
|
|
// Documentation claims this is already the
|
|
|
|
// per-landscape cargo type id, but newships.grf
|
|
|
|
// assume otherwise.
|
|
|
|
cargo = local_cargo_id_ctype[cargo];
|
|
|
|
#endif
|
2006-01-12 07:57:40 +00:00
|
|
|
if (cargo < NUM_CARGO) {
|
|
|
|
svi[i].cargo_type = cargo;
|
|
|
|
} else {
|
|
|
|
grfmsg(GMS_NOTICE, "ShipVehicleChangeInfo: Invalid cargo type %d, ignoring.", cargo);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2006-02-27 15:35:22 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x0D: /* Cargo capacity */
|
|
|
|
FOR_EACH_OBJECT svi[i].capacity = grf_load_word(&buf);
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x0F: /* Running cost factor */
|
|
|
|
FOR_EACH_OBJECT svi[i].running_cost = grf_load_byte(&buf);
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x10: /* SFX */
|
|
|
|
FOR_EACH_OBJECT svi[i].sfx = grf_load_byte(&buf);
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x11: /* Cargos available for refitting */
|
2006-02-28 08:13:15 +00:00
|
|
|
FOR_EACH_OBJECT ei[i].refit_mask = grf_load_dword(&buf);
|
2006-02-27 15:35:22 +00:00
|
|
|
break;
|
2006-02-11 07:34:05 +00:00
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x12: /* Callback mask */
|
|
|
|
FOR_EACH_OBJECT svi[i].callbackmask = grf_load_byte(&buf);
|
|
|
|
break;
|
|
|
|
|
2006-02-28 08:13:15 +00:00
|
|
|
case 0x17: /* Miscellaneous flags */
|
|
|
|
FOR_EACH_OBJECT ei[i].misc_flags = grf_load_byte(&buf);
|
|
|
|
break;
|
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x18: /* Cargo classes allowed */
|
|
|
|
FOR_EACH_OBJECT cargo_allowed[SHIP_ENGINES_INDEX + engine + i] = grf_load_word(&buf);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x19: /* Cargo classes disallowed */
|
|
|
|
FOR_EACH_OBJECT cargo_disallowed[SHIP_ENGINES_INDEX + engine + i] = grf_load_word(&buf);
|
2006-02-11 07:34:05 +00:00
|
|
|
break;
|
|
|
|
|
2005-05-29 20:36:11 +00:00
|
|
|
case 0x13: /* Refit cost */
|
|
|
|
case 0x14: /* Ocean speed fraction */
|
|
|
|
case 0x15: /* Canal speed fraction */
|
|
|
|
case 0x16: /* Retire vehicle early */
|
|
|
|
/* TODO */
|
2006-02-27 15:35:22 +00:00
|
|
|
FOR_EACH_OBJECT grf_load_byte(&buf);
|
2004-11-12 18:43:12 +00:00
|
|
|
ret = true;
|
2006-02-27 15:35:22 +00:00
|
|
|
break;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
default:
|
2004-11-12 18:43:12 +00:00
|
|
|
ret = true;
|
2006-02-27 15:35:22 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*bufp = buf;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-11-13 20:37:57 +00:00
|
|
|
static bool AircraftVehicleChangeInfo(uint engine, int numinfo, int prop, byte **bufp, int len)
|
|
|
|
{
|
2006-02-28 08:13:15 +00:00
|
|
|
EngineInfo *ei = &_engine_info[AIRCRAFT_ENGINES_INDEX + engine];
|
2004-11-13 20:37:57 +00:00
|
|
|
AircraftVehicleInfo *avi = &_aircraft_vehicle_info[engine];
|
|
|
|
byte *buf = *bufp;
|
|
|
|
int i;
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
//printf("e %x prop %x?\n", engine, prop);
|
|
|
|
switch (prop) {
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x08: /* Sprite ID */
|
2004-11-17 01:00:04 +00:00
|
|
|
FOR_EACH_OBJECT {
|
2004-11-13 20:37:57 +00:00
|
|
|
uint8 spriteid = grf_load_byte(&buf);
|
|
|
|
|
2006-02-18 14:41:24 +00:00
|
|
|
// aircraft have different custom id in the GRF file
|
|
|
|
if (spriteid == 0xFF) spriteid = 0xFD;
|
2004-11-13 20:37:57 +00:00
|
|
|
|
2006-02-18 14:41:24 +00:00
|
|
|
if (spriteid < 0xFD) spriteid >>= 1;
|
2006-01-27 07:13:58 +00:00
|
|
|
|
2004-11-13 20:37:57 +00:00
|
|
|
avi[i].image_index = spriteid;
|
|
|
|
}
|
2006-02-27 15:35:22 +00:00
|
|
|
break;
|
2004-11-13 20:37:57 +00:00
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x09: /* Helicopter */
|
|
|
|
FOR_EACH_OBJECT SB(avi[i].subtype, 0, 1, (grf_load_byte(&buf) != 0 ? 1 : 0));
|
|
|
|
break;
|
2004-11-13 20:37:57 +00:00
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x0A: /* Large */
|
|
|
|
FOR_EACH_OBJECT SB(avi[i].subtype, 1, 1, (grf_load_byte(&buf) != 0 ? 1 : 0));
|
|
|
|
break;
|
2004-11-13 20:37:57 +00:00
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x0B: /* Cost factor */
|
|
|
|
FOR_EACH_OBJECT avi[i].base_cost = grf_load_byte(&buf); // ?? is it base_cost?
|
|
|
|
break;
|
2004-11-13 20:37:57 +00:00
|
|
|
|
2006-04-09 18:08:20 +00:00
|
|
|
case 0x0C: /* Speed (1 unit is 8 mph) */
|
|
|
|
FOR_EACH_OBJECT avi[i].max_speed = grf_load_byte(&buf);
|
2006-02-27 15:35:22 +00:00
|
|
|
break;
|
2004-11-13 20:37:57 +00:00
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x0D: /* Acceleration */
|
|
|
|
FOR_EACH_OBJECT avi[i].acceleration = grf_load_byte(&buf);
|
|
|
|
break;
|
2004-11-13 20:37:57 +00:00
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x0E: /* Running cost factor */
|
|
|
|
FOR_EACH_OBJECT avi[i].running_cost = grf_load_byte(&buf);
|
|
|
|
break;
|
2004-11-13 20:37:57 +00:00
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x0F: /* Passenger capacity */
|
|
|
|
FOR_EACH_OBJECT avi[i].passenger_capacity = grf_load_word(&buf);
|
|
|
|
break;
|
2004-11-13 20:37:57 +00:00
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x11: /* Mail capacity */
|
|
|
|
FOR_EACH_OBJECT avi[i].mail_capacity = grf_load_byte(&buf);
|
|
|
|
break;
|
2006-02-11 07:34:05 +00:00
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x12: /* SFX */
|
|
|
|
FOR_EACH_OBJECT avi[i].sfx = grf_load_byte(&buf);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x13: /* Cargos available for refitting */
|
2006-02-28 08:13:15 +00:00
|
|
|
FOR_EACH_OBJECT ei[i].refit_mask = grf_load_dword(&buf);
|
2006-02-27 15:35:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x14: /* Callback mask */
|
|
|
|
FOR_EACH_OBJECT avi[i].callbackmask = grf_load_byte(&buf);
|
|
|
|
break;
|
|
|
|
|
2006-02-28 08:13:15 +00:00
|
|
|
case 0x17: /* Miscellaneous flags */
|
|
|
|
FOR_EACH_OBJECT ei[i].misc_flags = grf_load_byte(&buf);
|
|
|
|
break;
|
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x18: /* Cargo classes allowed */
|
|
|
|
FOR_EACH_OBJECT cargo_allowed[AIRCRAFT_ENGINES_INDEX + engine + i] = grf_load_word(&buf);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x19: /* Cargo classes disallowed */
|
|
|
|
FOR_EACH_OBJECT cargo_disallowed[AIRCRAFT_ENGINES_INDEX + engine + i] = grf_load_word(&buf);
|
2006-02-11 07:34:05 +00:00
|
|
|
break;
|
|
|
|
|
2005-05-29 20:36:11 +00:00
|
|
|
case 0x15: /* Refit cost */
|
|
|
|
case 0x16: /* Retire vehicle early */
|
|
|
|
/* TODO */
|
2006-02-27 15:35:22 +00:00
|
|
|
FOR_EACH_OBJECT grf_load_byte(&buf);
|
2004-11-13 20:37:57 +00:00
|
|
|
ret = true;
|
2006-02-27 15:35:22 +00:00
|
|
|
break;
|
|
|
|
|
2004-11-13 20:37:57 +00:00
|
|
|
default:
|
|
|
|
ret = true;
|
2006-02-27 15:35:22 +00:00
|
|
|
break;
|
2004-11-13 20:37:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*bufp = buf;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-11-14 09:07:15 +00:00
|
|
|
static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int len)
|
|
|
|
{
|
2006-05-06 22:20:16 +00:00
|
|
|
StationSpec **statspec;
|
2004-11-14 09:07:15 +00:00
|
|
|
byte *buf = *bufp;
|
|
|
|
int i;
|
2006-04-11 13:00:06 +00:00
|
|
|
bool ret = false;
|
2004-11-14 09:07:15 +00:00
|
|
|
|
2006-05-06 22:20:16 +00:00
|
|
|
if (stid + numinfo > MAX_STATIONS) {
|
|
|
|
grfmsg(GMS_WARN, "StationChangeInfo: Station %u is invalid, max %u, ignoring.", stid + numinfo, MAX_STATIONS);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-04-11 10:05:52 +00:00
|
|
|
/* Allocate station specs if necessary */
|
2006-05-06 22:20:16 +00:00
|
|
|
if (_cur_grffile->stations == NULL) _cur_grffile->stations = calloc(MAX_STATIONS, sizeof(*_cur_grffile->stations));
|
|
|
|
|
|
|
|
statspec = &_cur_grffile->stations[stid];
|
2006-04-11 10:05:52 +00:00
|
|
|
|
2006-05-06 22:20:16 +00:00
|
|
|
if (prop != 0x08) {
|
|
|
|
/* Check that all stations we are modifying are defined. */
|
|
|
|
FOR_EACH_OBJECT {
|
|
|
|
if (statspec[i] == NULL) {
|
|
|
|
grfmsg(GMS_NOTICE, "StationChangeInfo: Attempt to modify undefined station %u, ignoring.", stid + i);
|
|
|
|
return false;
|
|
|
|
}
|
2006-04-11 10:05:52 +00:00
|
|
|
}
|
|
|
|
}
|
2004-11-14 09:07:15 +00:00
|
|
|
|
|
|
|
switch (prop) {
|
2006-04-11 13:00:06 +00:00
|
|
|
case 0x08: /* Class ID */
|
2004-11-17 01:00:04 +00:00
|
|
|
FOR_EACH_OBJECT {
|
2006-05-06 22:20:16 +00:00
|
|
|
uint32 classid;
|
|
|
|
|
|
|
|
/* Property 0x08 is special; it is where the station is allocated */
|
|
|
|
if (statspec[i] == NULL) statspec[i] = calloc(1, sizeof(*statspec[i]));
|
|
|
|
|
2006-05-01 21:45:35 +00:00
|
|
|
/* Swap classid because we read it in BE meaning WAYP or DFLT */
|
2006-05-06 22:20:16 +00:00
|
|
|
classid = grf_load_dword(&buf);
|
|
|
|
statspec[i]->sclass = AllocateStationClass(BSWAP32(classid));
|
2004-11-14 09:07:15 +00:00
|
|
|
}
|
|
|
|
break;
|
2006-04-11 13:00:06 +00:00
|
|
|
|
|
|
|
case 0x09: /* Define sprite layout */
|
2004-11-17 01:00:04 +00:00
|
|
|
FOR_EACH_OBJECT {
|
2006-05-06 22:20:16 +00:00
|
|
|
StationSpec *statspec = _cur_grffile->stations[stid + i];
|
2006-04-16 18:57:07 +00:00
|
|
|
uint t;
|
2004-11-14 13:59:11 +00:00
|
|
|
|
2006-04-27 18:28:56 +00:00
|
|
|
statspec->tiles = grf_load_extended(&buf);
|
|
|
|
statspec->renderdata = calloc(statspec->tiles, sizeof(*statspec->renderdata));
|
2006-05-03 21:07:44 +00:00
|
|
|
statspec->copied_renderdata = false;
|
|
|
|
|
2006-04-27 18:28:56 +00:00
|
|
|
for (t = 0; t < statspec->tiles; t++) {
|
|
|
|
DrawTileSprites *dts = &statspec->renderdata[t];
|
2006-04-16 18:57:07 +00:00
|
|
|
uint seq_count = 0;
|
2004-11-14 09:07:15 +00:00
|
|
|
|
2006-05-03 20:35:41 +00:00
|
|
|
dts->seq = NULL;
|
2006-05-07 10:58:53 +00:00
|
|
|
dts->ground_sprite = grf_load_dword(&buf);
|
|
|
|
if (dts->ground_sprite == 0) continue;
|
2005-11-12 00:19:34 +00:00
|
|
|
|
2004-11-14 09:07:15 +00:00
|
|
|
while (buf < *bufp + len) {
|
|
|
|
DrawTileSeqStruct *dtss;
|
|
|
|
|
|
|
|
// no relative bounding box support
|
|
|
|
dts->seq = realloc((void*)dts->seq, ++seq_count * sizeof(DrawTileSeqStruct));
|
|
|
|
dtss = (DrawTileSeqStruct*) &dts->seq[seq_count - 1];
|
|
|
|
|
|
|
|
dtss->delta_x = grf_load_byte(&buf);
|
|
|
|
if ((byte) dtss->delta_x == 0x80) break;
|
|
|
|
dtss->delta_y = grf_load_byte(&buf);
|
|
|
|
dtss->delta_z = grf_load_byte(&buf);
|
|
|
|
dtss->width = grf_load_byte(&buf);
|
|
|
|
dtss->height = grf_load_byte(&buf);
|
|
|
|
dtss->unk = grf_load_byte(&buf);
|
2006-05-06 22:55:21 +00:00
|
|
|
dtss->image = grf_load_dword(&buf);
|
|
|
|
|
2006-05-07 10:58:53 +00:00
|
|
|
/* Remap flags as ours collide */
|
|
|
|
if (HASBIT(dtss->image, 31)) {
|
|
|
|
CLRBIT(dtss->image, 31);
|
|
|
|
SETBIT(dtss->image, 30);
|
|
|
|
}
|
2006-05-06 22:55:21 +00:00
|
|
|
if (HASBIT(dtss->image, 14)) {
|
|
|
|
CLRBIT(dtss->image, 14);
|
|
|
|
SETBIT(dtss->image, 31);
|
|
|
|
}
|
2004-11-14 09:07:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2006-04-11 13:00:06 +00:00
|
|
|
|
|
|
|
case 0x0A: /* Copy sprite layout */
|
2004-11-17 01:00:04 +00:00
|
|
|
FOR_EACH_OBJECT {
|
2006-05-06 22:20:16 +00:00
|
|
|
StationSpec *statspec = _cur_grffile->stations[stid + i];
|
2004-11-14 13:59:11 +00:00
|
|
|
byte srcid = grf_load_byte(&buf);
|
2006-05-06 22:20:16 +00:00
|
|
|
const StationSpec *srcstatspec = _cur_grffile->stations[srcid];
|
2004-11-14 13:59:11 +00:00
|
|
|
|
2006-04-27 18:28:56 +00:00
|
|
|
statspec->tiles = srcstatspec->tiles;
|
2006-05-03 20:42:45 +00:00
|
|
|
statspec->renderdata = srcstatspec->renderdata;
|
2006-05-03 21:07:44 +00:00
|
|
|
statspec->copied_renderdata = true;
|
2004-11-14 09:07:15 +00:00
|
|
|
}
|
|
|
|
break;
|
2006-04-11 13:00:06 +00:00
|
|
|
|
|
|
|
case 0x0B: /* Callback mask */
|
2006-05-06 22:20:16 +00:00
|
|
|
FOR_EACH_OBJECT statspec[i]->callbackmask = grf_load_byte(&buf);
|
2004-11-14 09:07:15 +00:00
|
|
|
break;
|
2004-11-17 18:03:33 +00:00
|
|
|
|
2006-04-11 13:00:06 +00:00
|
|
|
case 0x0C: /* Disallowed number of platforms */
|
2006-05-06 22:20:16 +00:00
|
|
|
FOR_EACH_OBJECT statspec[i]->disallowed_platforms = grf_load_byte(&buf);
|
2004-11-14 09:07:15 +00:00
|
|
|
break;
|
2004-11-17 18:03:33 +00:00
|
|
|
|
2006-04-11 13:00:06 +00:00
|
|
|
case 0x0D: /* Disallowed platform lengths */
|
2006-05-06 22:20:16 +00:00
|
|
|
FOR_EACH_OBJECT statspec[i]->disallowed_lengths = grf_load_byte(&buf);
|
2004-11-14 09:07:15 +00:00
|
|
|
break;
|
2006-04-11 13:00:06 +00:00
|
|
|
|
|
|
|
case 0x0E: /* Define custom layout */
|
2004-11-17 01:00:04 +00:00
|
|
|
FOR_EACH_OBJECT {
|
2006-05-06 22:20:16 +00:00
|
|
|
StationSpec *statspec = _cur_grffile->stations[stid + i];
|
2004-11-17 18:03:33 +00:00
|
|
|
|
2004-11-14 09:07:15 +00:00
|
|
|
while (buf < *bufp + len) {
|
|
|
|
byte length = grf_load_byte(&buf);
|
|
|
|
byte number = grf_load_byte(&buf);
|
2004-11-17 18:03:33 +00:00
|
|
|
StationLayout layout;
|
2006-04-16 18:57:07 +00:00
|
|
|
uint l, p;
|
2004-11-17 18:03:33 +00:00
|
|
|
|
|
|
|
if (length == 0 || number == 0) break;
|
|
|
|
|
|
|
|
//debug("l %d > %d ?", length, stat->lengths);
|
2006-04-27 18:28:56 +00:00
|
|
|
if (length > statspec->lengths) {
|
|
|
|
statspec->platforms = realloc(statspec->platforms, length);
|
|
|
|
memset(statspec->platforms + statspec->lengths, 0, length - statspec->lengths);
|
2004-11-17 18:03:33 +00:00
|
|
|
|
2006-04-27 18:28:56 +00:00
|
|
|
statspec->layouts = realloc(statspec->layouts, length * sizeof(*statspec->layouts));
|
|
|
|
memset(statspec->layouts + statspec->lengths, 0,
|
|
|
|
(length - statspec->lengths) * sizeof(*statspec->layouts));
|
2004-11-17 18:03:33 +00:00
|
|
|
|
2006-04-27 18:28:56 +00:00
|
|
|
statspec->lengths = length;
|
2004-11-17 18:03:33 +00:00
|
|
|
}
|
|
|
|
l = length - 1; // index is zero-based
|
|
|
|
|
|
|
|
//debug("p %d > %d ?", number, stat->platforms[l]);
|
2006-04-27 18:28:56 +00:00
|
|
|
if (number > statspec->platforms[l]) {
|
|
|
|
statspec->layouts[l] = realloc(statspec->layouts[l],
|
|
|
|
number * sizeof(**statspec->layouts));
|
2004-11-17 18:03:33 +00:00
|
|
|
// We expect NULL being 0 here, but C99 guarantees that.
|
2006-04-27 18:28:56 +00:00
|
|
|
memset(statspec->layouts[l] + statspec->platforms[l], 0,
|
|
|
|
(number - statspec->platforms[l]) * sizeof(**statspec->layouts));
|
2004-11-17 18:03:33 +00:00
|
|
|
|
2006-04-27 18:28:56 +00:00
|
|
|
statspec->platforms[l] = number;
|
2004-11-17 18:03:33 +00:00
|
|
|
}
|
|
|
|
|
2004-12-04 15:02:45 +00:00
|
|
|
p = 0;
|
2004-11-17 18:03:33 +00:00
|
|
|
layout = malloc(length * number);
|
2006-02-18 14:41:24 +00:00
|
|
|
for (l = 0; l < length; l++) {
|
|
|
|
for (p = 0; p < number; p++) {
|
2004-11-17 18:03:33 +00:00
|
|
|
layout[l * number + p] = grf_load_byte(&buf);
|
2006-02-18 14:41:24 +00:00
|
|
|
}
|
|
|
|
}
|
2004-11-14 09:07:15 +00:00
|
|
|
|
2004-11-17 18:03:33 +00:00
|
|
|
l--;
|
|
|
|
p--;
|
2006-04-27 18:28:56 +00:00
|
|
|
free(statspec->layouts[l][p]);
|
|
|
|
statspec->layouts[l][p] = layout;
|
2004-11-14 09:07:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2006-04-11 13:00:06 +00:00
|
|
|
|
|
|
|
case 0x0F: /* Copy custom layout */
|
2004-11-14 09:07:15 +00:00
|
|
|
/* TODO */
|
2004-11-17 01:00:04 +00:00
|
|
|
FOR_EACH_OBJECT {
|
2004-11-14 09:07:15 +00:00
|
|
|
grf_load_byte(&buf);
|
|
|
|
}
|
2006-04-11 13:00:06 +00:00
|
|
|
ret = true;
|
2004-11-14 09:07:15 +00:00
|
|
|
break;
|
2006-04-11 13:00:06 +00:00
|
|
|
|
|
|
|
case 0x10: /* Little/lots cargo threshold */
|
2006-05-06 22:20:16 +00:00
|
|
|
FOR_EACH_OBJECT statspec[i]->cargo_threshold = grf_load_word(&buf);
|
2004-11-14 09:07:15 +00:00
|
|
|
break;
|
2006-04-11 13:00:06 +00:00
|
|
|
|
|
|
|
case 0x11: /* Pylon placement */
|
2006-05-06 22:20:16 +00:00
|
|
|
FOR_EACH_OBJECT statspec[i]->pylons = grf_load_byte(&buf);
|
2004-11-17 01:00:04 +00:00
|
|
|
break;
|
2006-04-11 13:00:06 +00:00
|
|
|
|
|
|
|
case 0x12: /* Cargo types for random triggers */
|
2006-05-06 22:20:16 +00:00
|
|
|
FOR_EACH_OBJECT statspec[i]->cargo_triggers = grf_load_dword(&buf);
|
2004-11-17 01:00:04 +00:00
|
|
|
break;
|
2006-04-11 13:00:06 +00:00
|
|
|
|
|
|
|
case 0x13: /* General flags */
|
2006-05-06 22:20:16 +00:00
|
|
|
FOR_EACH_OBJECT statspec[i]->flags = grf_load_byte(&buf);
|
2006-04-11 13:00:06 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x14: /* Overhead wire placement */
|
2006-05-06 22:20:16 +00:00
|
|
|
FOR_EACH_OBJECT statspec[i]->wires = grf_load_byte(&buf);
|
2006-04-11 13:00:06 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x15: /* Blocked tiles */
|
2006-05-06 22:20:16 +00:00
|
|
|
FOR_EACH_OBJECT statspec[i]->blocked = grf_load_byte(&buf);
|
2006-04-11 13:00:06 +00:00
|
|
|
break;
|
|
|
|
|
2004-11-14 09:07:15 +00:00
|
|
|
default:
|
2006-04-11 13:00:06 +00:00
|
|
|
ret = true;
|
2004-11-14 09:07:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
*bufp = buf;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-10-01 17:38:48 +00:00
|
|
|
static bool BridgeChangeInfo(uint brid, int numinfo, int prop, byte **bufp, int len)
|
|
|
|
{
|
|
|
|
byte *buf = *bufp;
|
|
|
|
int i;
|
2006-04-11 10:53:07 +00:00
|
|
|
bool ret = false;
|
2005-10-01 17:38:48 +00:00
|
|
|
|
|
|
|
switch (prop) {
|
|
|
|
case 0x08: /* Year of availability */
|
2006-02-27 15:35:22 +00:00
|
|
|
FOR_EACH_OBJECT _bridge[brid + i].avail_year = grf_load_byte(&buf);
|
2005-10-01 17:38:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x09: /* Minimum length */
|
2006-02-27 15:35:22 +00:00
|
|
|
FOR_EACH_OBJECT _bridge[brid + i].min_length = grf_load_byte(&buf);
|
2005-10-01 17:38:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x0A: /* Maximum length */
|
2006-02-27 15:35:22 +00:00
|
|
|
FOR_EACH_OBJECT _bridge[brid + i].max_length = grf_load_byte(&buf);
|
2005-10-01 17:38:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x0B: /* Cost factor */
|
2006-02-27 15:35:22 +00:00
|
|
|
FOR_EACH_OBJECT _bridge[brid + i].price = grf_load_byte(&buf);
|
2005-10-01 17:38:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x0C: /* Maximum speed */
|
2006-02-27 15:35:22 +00:00
|
|
|
FOR_EACH_OBJECT _bridge[brid + i].speed = grf_load_word(&buf);
|
2005-10-01 17:38:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x0D: /* Bridge sprite tables */
|
|
|
|
FOR_EACH_OBJECT {
|
|
|
|
Bridge *bridge = &_bridge[brid + i];
|
|
|
|
byte tableid = grf_load_byte(&buf);
|
|
|
|
byte numtables = grf_load_byte(&buf);
|
|
|
|
|
|
|
|
if (bridge->sprite_table == NULL) {
|
2006-04-15 16:03:45 +00:00
|
|
|
/* Allocate memory for sprite table pointers and zero out */
|
|
|
|
bridge->sprite_table = calloc(7, sizeof(*bridge->sprite_table));
|
2005-10-01 17:38:48 +00:00
|
|
|
}
|
|
|
|
|
2006-04-15 16:03:45 +00:00
|
|
|
for (; numtables-- != 0; tableid++) {
|
|
|
|
byte sprite;
|
2005-10-01 17:38:48 +00:00
|
|
|
|
2006-04-15 16:03:45 +00:00
|
|
|
if (tableid >= 7) { // skip invalid data
|
|
|
|
grfmsg(GMS_WARN, "BridgeChangeInfo: Table %d >= 7, skipping.", tableid);
|
|
|
|
for (sprite = 0; sprite < 32; sprite++) grf_load_dword(&buf);
|
|
|
|
continue;
|
2005-10-02 12:00:30 +00:00
|
|
|
}
|
2006-04-15 16:03:45 +00:00
|
|
|
|
|
|
|
if (bridge->sprite_table[tableid] == NULL) {
|
|
|
|
bridge->sprite_table[tableid] = malloc(32 * sizeof(**bridge->sprite_table));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (sprite = 0; sprite < 32; sprite++)
|
|
|
|
bridge->sprite_table[tableid][sprite] = grf_load_dword(&buf);
|
2005-10-01 17:38:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x0E: /* Flags; bit 0 - disable far pillars */
|
2006-02-27 15:35:22 +00:00
|
|
|
FOR_EACH_OBJECT _bridge[brid + i].flags = grf_load_byte(&buf);
|
2005-10-01 17:38:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2006-04-11 10:53:07 +00:00
|
|
|
ret = true;
|
2005-10-01 17:38:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*bufp = buf;
|
|
|
|
return ret;
|
|
|
|
}
|
2004-11-14 09:07:15 +00:00
|
|
|
|
2006-05-12 00:27:12 +00:00
|
|
|
static bool CargosChangeInfo(uint gvid, int numinfo, int prop, byte **bufp, int len)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-10-12 07:27:56 +00:00
|
|
|
static bool GlobalVarChangeInfo(uint gvid, int numinfo, int prop, byte **bufp, int len)
|
|
|
|
{
|
|
|
|
byte *buf = *bufp;
|
|
|
|
int i;
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
switch (prop) {
|
2006-04-11 10:53:07 +00:00
|
|
|
case 0x08: /* Cost base factor */
|
2005-10-12 07:27:56 +00:00
|
|
|
FOR_EACH_OBJECT {
|
|
|
|
byte factor = grf_load_byte(&buf);
|
2005-10-12 09:54:29 +00:00
|
|
|
uint price = gvid + i;
|
2005-10-12 07:27:56 +00:00
|
|
|
|
2005-10-12 09:54:29 +00:00
|
|
|
if (price < NUM_PRICES) {
|
|
|
|
SetPriceBaseMultiplier(price, factor);
|
|
|
|
} else {
|
|
|
|
grfmsg(GMS_WARN, "GlobalVarChangeInfo: Price %d out of range, ignoring.", price);
|
|
|
|
}
|
2005-10-12 07:27:56 +00:00
|
|
|
}
|
2006-04-11 10:53:07 +00:00
|
|
|
break;
|
|
|
|
|
2005-10-12 07:27:56 +00:00
|
|
|
default:
|
|
|
|
ret = true;
|
|
|
|
}
|
2006-04-11 10:53:07 +00:00
|
|
|
|
2005-10-12 07:27:56 +00:00
|
|
|
*bufp = buf;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-11-12 15:15:56 +00:00
|
|
|
/* Action 0x00 */
|
2004-08-09 17:04:08 +00:00
|
|
|
static void VehicleChangeInfo(byte *buf, int len)
|
|
|
|
{
|
|
|
|
byte *bufend = buf + len;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* <00> <feature> <num-props> <num-info> <id> (<property <new-info>)...
|
|
|
|
*
|
|
|
|
* B feature 0, 1, 2 or 3 for trains, road vehicles, ships or planes
|
|
|
|
* 4 for defining new train station sets
|
|
|
|
* B num-props how many properties to change per vehicle/station
|
|
|
|
* B num-info how many vehicles/stations to change
|
|
|
|
* B id ID of first vehicle/station to change, if num-info is
|
|
|
|
* greater than one, this one and the following
|
|
|
|
* vehicles/stations will be changed
|
|
|
|
* B property what property to change, depends on the feature
|
|
|
|
* V new-info new bytes of info (variable size; depends on properties) */
|
2004-11-14 10:03:21 +00:00
|
|
|
/* TODO: Bridges, town houses. */
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-09-20 09:38:09 +00:00
|
|
|
static const VCI_Handler handler[] = {
|
2006-05-12 00:27:12 +00:00
|
|
|
/* GSF_TRAIN */ RailVehicleChangeInfo,
|
|
|
|
/* GSF_ROAD */ RoadVehicleChangeInfo,
|
|
|
|
/* GSF_SHIP */ ShipVehicleChangeInfo,
|
|
|
|
/* GSF_AIRCRAFT */ AircraftVehicleChangeInfo,
|
|
|
|
/* GSF_STATION */ StationChangeInfo,
|
|
|
|
/* GSF_CANAL */ NULL,
|
|
|
|
/* GSF_BRIDGE */ BridgeChangeInfo,
|
|
|
|
/* GSF_TOWNHOUSE */ NULL,
|
|
|
|
/* GSF_GLOBALVAR */ GlobalVarChangeInfo,
|
|
|
|
/* GSF_INDUSTRYTILES */NULL,
|
|
|
|
/* GSF_INDUSTRIES */ NULL,
|
|
|
|
/* GSF_CARGOS */ CargosChangeInfo,
|
|
|
|
/* GSF_SOUNDFX */ NULL,
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
2004-11-12 18:43:12 +00:00
|
|
|
|
2004-11-12 15:36:49 +00:00
|
|
|
uint8 feature;
|
|
|
|
uint8 numprops;
|
|
|
|
uint8 numinfo;
|
|
|
|
byte engine;
|
2004-12-04 15:02:45 +00:00
|
|
|
EngineInfo *ei = NULL;
|
2004-11-12 15:36:49 +00:00
|
|
|
|
2004-11-14 13:11:38 +00:00
|
|
|
if (len == 1) {
|
|
|
|
DEBUG(grf, 8) ("Silently ignoring one-byte special sprite 0x00.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-11-12 15:36:49 +00:00
|
|
|
check_length(len, 6, "VehicleChangeInfo");
|
2006-05-02 09:18:51 +00:00
|
|
|
buf++;
|
|
|
|
feature = grf_load_byte(&buf);
|
|
|
|
numprops = grf_load_byte(&buf);
|
|
|
|
numinfo = grf_load_byte(&buf);
|
|
|
|
engine = grf_load_byte(&buf);
|
2004-11-12 15:36:49 +00:00
|
|
|
|
2004-11-13 18:01:33 +00:00
|
|
|
DEBUG(grf, 6) ("VehicleChangeInfo: Feature %d, %d properties, to apply to %d+%d",
|
|
|
|
feature, numprops, engine, numinfo);
|
|
|
|
|
2005-09-20 17:33:57 +00:00
|
|
|
if (feature >= lengthof(handler) || handler[feature] == NULL) {
|
2004-11-14 10:03:21 +00:00
|
|
|
grfmsg(GMS_WARN, "VehicleChangeInfo: Unsupported feature %d, skipping.", feature);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-09-20 11:07:33 +00:00
|
|
|
if (feature <= GSF_AIRCRAFT) {
|
|
|
|
if (engine + numinfo > _vehcounts[feature]) {
|
|
|
|
grfmsg(GMS_ERROR, "VehicleChangeInfo: Last engine ID %d out of bounds (max %d), skipping.", engine + numinfo, _vehcounts[feature]);
|
|
|
|
return;
|
|
|
|
}
|
2004-11-14 09:07:15 +00:00
|
|
|
ei = &_engine_info[engine + _vehshifts[feature]];
|
2005-09-20 11:07:33 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-11-12 15:36:49 +00:00
|
|
|
while (numprops-- && buf < bufend) {
|
|
|
|
uint8 prop = grf_load_byte(&buf);
|
2005-09-13 09:23:23 +00:00
|
|
|
bool ignoring = false;
|
|
|
|
|
|
|
|
switch (feature) {
|
|
|
|
case GSF_TRAIN:
|
|
|
|
case GSF_ROAD:
|
|
|
|
case GSF_SHIP:
|
|
|
|
case GSF_AIRCRAFT:
|
|
|
|
/* Common properties for vehicles */
|
|
|
|
switch (prop) {
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x00: /* Introduction date */
|
|
|
|
FOR_EACH_OBJECT ei[i].base_intro = grf_load_word(&buf);
|
|
|
|
break;
|
2005-09-13 09:23:23 +00:00
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x02: /* Decay speed */
|
|
|
|
FOR_EACH_OBJECT SB(ei[i].unk2, 0, 7, grf_load_byte(&buf) & 0x7F);
|
|
|
|
break;
|
2005-09-13 09:23:23 +00:00
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x03: /* Vehicle life */
|
|
|
|
FOR_EACH_OBJECT ei[i].lifelength = grf_load_byte(&buf);
|
|
|
|
break;
|
2005-09-13 09:23:23 +00:00
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x04: /* Model life */
|
|
|
|
FOR_EACH_OBJECT ei[i].base_life = grf_load_byte(&buf);
|
|
|
|
break;
|
2005-09-13 09:23:23 +00:00
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x06: /* Climates available */
|
|
|
|
FOR_EACH_OBJECT ei[i].climates = grf_load_byte(&buf);
|
|
|
|
break;
|
2005-09-13 09:23:23 +00:00
|
|
|
|
2006-02-27 15:35:22 +00:00
|
|
|
case 0x07: /* Loading speed */
|
2005-09-13 09:23:23 +00:00
|
|
|
/* TODO */
|
|
|
|
/* Hyronymus explained me what does
|
|
|
|
* this mean and insists on having a
|
|
|
|
* credit ;-). --pasky */
|
|
|
|
/* TODO: This needs to be supported by
|
|
|
|
* LoadUnloadVehicle() first. */
|
2006-02-27 15:35:22 +00:00
|
|
|
FOR_EACH_OBJECT grf_load_byte(&buf);
|
2005-09-13 09:23:23 +00:00
|
|
|
ignoring = true;
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-09-13 09:23:23 +00:00
|
|
|
default:
|
|
|
|
if (handler[feature](engine, numinfo, prop, &buf, bufend - buf))
|
|
|
|
ignoring = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-09-13 09:23:23 +00:00
|
|
|
default:
|
|
|
|
if (handler[feature](engine, numinfo, prop, &buf, bufend - buf))
|
|
|
|
ignoring = true;
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-09-13 09:23:23 +00:00
|
|
|
|
|
|
|
if (ignoring)
|
2006-04-22 13:56:16 +00:00
|
|
|
grfmsg(GMS_NOTICE, "VehicleChangeInfo: Ignoring property 0x%02X (not implemented).", prop);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-17 01:00:04 +00:00
|
|
|
#undef FOR_EACH_OBJECT
|
|
|
|
|
2005-06-01 11:34:37 +00:00
|
|
|
/**
|
|
|
|
* Creates a spritegroup representing a callback result
|
|
|
|
* @param value The value that was used to represent this callback result
|
|
|
|
* @return A spritegroup representing that callback result
|
|
|
|
*/
|
2005-12-14 06:20:23 +00:00
|
|
|
static SpriteGroup* NewCallBackResultSpriteGroup(uint16 value)
|
2005-06-01 11:34:37 +00:00
|
|
|
{
|
2006-04-20 20:51:57 +00:00
|
|
|
SpriteGroup *group = AllocateSpriteGroup();
|
2005-06-01 11:34:37 +00:00
|
|
|
|
2005-10-04 19:52:26 +00:00
|
|
|
group->type = SGT_CALLBACK;
|
2005-06-01 11:34:37 +00:00
|
|
|
|
|
|
|
// Old style callback results have the highest byte 0xFF so signify it is a callback result
|
|
|
|
// New style ones only have the highest bit set (allows 15-bit results, instead of just 8)
|
2006-02-18 14:41:24 +00:00
|
|
|
if ((value >> 8) == 0xFF) {
|
|
|
|
value &= ~0xFF00;
|
|
|
|
} else {
|
2005-06-01 11:34:37 +00:00
|
|
|
value &= ~0x8000;
|
2006-02-18 14:41:24 +00:00
|
|
|
}
|
2005-06-01 11:34:37 +00:00
|
|
|
|
2005-10-04 19:52:26 +00:00
|
|
|
group->g.callback.result = value;
|
2005-06-01 11:34:37 +00:00
|
|
|
|
|
|
|
return group;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-10-04 20:38:26 +00:00
|
|
|
/**
|
|
|
|
* Creates a spritegroup representing a sprite number result.
|
|
|
|
* @param value The sprite number.
|
|
|
|
* @param sprites The number of sprites per set.
|
|
|
|
* @return A spritegroup representing the sprite number result.
|
|
|
|
*/
|
2006-04-26 20:44:28 +00:00
|
|
|
static SpriteGroup* NewResultSpriteGroup(SpriteID sprite, byte num_sprites)
|
2005-10-04 20:38:26 +00:00
|
|
|
{
|
2006-04-20 20:51:57 +00:00
|
|
|
SpriteGroup *group = AllocateSpriteGroup();
|
2005-10-04 20:38:26 +00:00
|
|
|
group->type = SGT_RESULT;
|
2006-04-26 20:44:28 +00:00
|
|
|
group->g.result.sprite = sprite;
|
|
|
|
group->g.result.num_sprites = num_sprites;
|
2005-10-04 20:38:26 +00:00
|
|
|
return group;
|
|
|
|
}
|
|
|
|
|
2004-11-12 15:15:56 +00:00
|
|
|
/* Action 0x01 */
|
2004-11-12 23:59:51 +00:00
|
|
|
static void NewSpriteSet(byte *buf, int len)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
/* <01> <feature> <num-sets> <num-ent>
|
|
|
|
*
|
|
|
|
* B feature feature to define sprites for
|
|
|
|
* 0, 1, 2, 3: veh-type, 4: train stations
|
|
|
|
* B num-sets number of sprite sets
|
2005-08-15 22:48:33 +00:00
|
|
|
* E num-ent how many entries per sprite set
|
2004-08-09 17:04:08 +00:00
|
|
|
* For vehicles, this is the number of different
|
|
|
|
* vehicle directions in each sprite set
|
|
|
|
* Set num-dirs=8, unless your sprites are symmetric.
|
|
|
|
* In that case, use num-dirs=4.
|
|
|
|
* For stations, must be 12 (hex) for the eighteen
|
|
|
|
* different sprites that make up a station */
|
|
|
|
/* TODO: No stations support. */
|
2004-11-12 15:36:49 +00:00
|
|
|
uint8 feature;
|
2005-08-15 11:39:13 +00:00
|
|
|
uint num_sets;
|
|
|
|
uint num_ents;
|
|
|
|
uint i;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-11-13 12:21:32 +00:00
|
|
|
check_length(len, 4, "NewSpriteSet");
|
2005-08-15 22:48:33 +00:00
|
|
|
buf++;
|
|
|
|
feature = grf_load_byte(&buf);
|
|
|
|
num_sets = grf_load_byte(&buf);
|
|
|
|
num_ents = grf_load_extended(&buf);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-08-15 11:39:13 +00:00
|
|
|
_cur_grffile->spriteset_start = _cur_spriteid;
|
2004-11-14 09:07:15 +00:00
|
|
|
_cur_grffile->spriteset_feature = feature;
|
2005-08-15 11:39:13 +00:00
|
|
|
_cur_grffile->spriteset_numsets = num_sets;
|
|
|
|
_cur_grffile->spriteset_numents = num_ents;
|
|
|
|
|
|
|
|
DEBUG(grf, 7) (
|
|
|
|
"New sprite set at %d of type %d, "
|
|
|
|
"consisting of %d sets with %d views each (total %d)",
|
|
|
|
_cur_spriteid, feature, num_sets, num_ents, num_sets * num_ents
|
|
|
|
);
|
|
|
|
|
|
|
|
for (i = 0; i < num_sets * num_ents; i++) {
|
|
|
|
LoadNextSprite(_cur_spriteid++, _file_index);
|
2006-04-15 16:40:54 +00:00
|
|
|
_nfo_line++;
|
2005-08-15 11:39:13 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-04-26 19:42:05 +00:00
|
|
|
/* Helper function to either create a callback or link to a previously
|
|
|
|
* defined spritegroup. */
|
|
|
|
static SpriteGroup* GetGroupFromGroupID(byte setid, byte type, uint16 groupid)
|
|
|
|
{
|
|
|
|
if (HASBIT(groupid, 15)) return NewCallBackResultSpriteGroup(groupid);
|
|
|
|
|
|
|
|
if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
|
|
|
|
grfmsg(GMS_WARN, "NewSpriteGroup(0x%02X:0x%02X): Groupid 0x%04X does not exist, leaving empty.", setid, type, groupid);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return _cur_grffile->spritegroups[groupid];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Helper function to either create a callback or a result sprite group. */
|
2006-05-10 06:23:43 +00:00
|
|
|
static SpriteGroup* CreateGroupFromGroupID(byte feature, byte setid, byte type, uint16 spriteid, uint16 num_sprites)
|
2006-04-26 19:42:05 +00:00
|
|
|
{
|
|
|
|
if (HASBIT(spriteid, 15)) return NewCallBackResultSpriteGroup(spriteid);
|
|
|
|
|
2006-04-26 20:18:29 +00:00
|
|
|
if (spriteid >= _cur_grffile->spriteset_numsets) {
|
|
|
|
grfmsg(GMS_WARN, "NewSpriteGroup(0x%02X:0x%02X): Sprite set %u invalid, max %u", setid, type, spriteid, _cur_grffile->spriteset_numsets);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-04-26 19:42:05 +00:00
|
|
|
/* Check if the sprite is within range. This can fail if the Action 0x01
|
|
|
|
* is skipped, as TTDPatch mandates that Action 0x02s must be processed.
|
|
|
|
* We don't have that rule, but must live by the Patch... */
|
|
|
|
if (_cur_grffile->spriteset_start + spriteid * num_sprites + num_sprites > _cur_spriteid) {
|
|
|
|
grfmsg(GMS_WARN, "NewSpriteGroup(0x%02X:0x%02X): Real Sprite IDs 0x%04X - 0x%04X do not (all) exist (max 0x%04X), leaving empty.",
|
|
|
|
setid, type,
|
|
|
|
_cur_grffile->spriteset_start + spriteid * num_sprites,
|
|
|
|
_cur_grffile->spriteset_start + spriteid * num_sprites + num_sprites - 1, _cur_spriteid - 1);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-05-10 06:23:43 +00:00
|
|
|
if (feature != _cur_grffile->spriteset_feature) {
|
|
|
|
grfmsg(GMS_WARN, "NewSpriteGroup(0x%02X:0x%02X): Sprite set feature 0x%02X does not match action feature 0x%02X, skipping.",
|
|
|
|
_cur_grffile->spriteset_feature, feature);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-04-26 19:42:05 +00:00
|
|
|
return NewResultSpriteGroup(_cur_grffile->spriteset_start + spriteid * num_sprites, num_sprites);
|
|
|
|
}
|
|
|
|
|
2004-11-12 15:15:56 +00:00
|
|
|
/* Action 0x02 */
|
2004-11-12 23:59:51 +00:00
|
|
|
static void NewSpriteGroup(byte *buf, int len)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
/* <02> <feature> <set-id> <type/num-entries> <feature-specific-data...>
|
|
|
|
*
|
|
|
|
* B feature see action 1
|
|
|
|
* B set-id ID of this particular definition
|
|
|
|
* B type/num-entries
|
|
|
|
* if 80 or greater, this is a randomized or variational
|
|
|
|
* list definition, see below
|
|
|
|
* otherwise it specifies a number of entries, the exact
|
|
|
|
* meaning depends on the feature
|
|
|
|
* V feature-specific-data (huge mess, don't even look it up --pasky) */
|
2004-11-12 15:36:49 +00:00
|
|
|
uint8 feature;
|
|
|
|
uint8 setid;
|
2006-04-23 09:46:23 +00:00
|
|
|
uint8 type;
|
|
|
|
SpriteGroup *group = NULL;
|
|
|
|
byte *bufend = buf + len;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-11-13 12:21:32 +00:00
|
|
|
check_length(len, 5, "NewSpriteGroup");
|
2006-04-23 09:46:23 +00:00
|
|
|
buf++;
|
|
|
|
|
|
|
|
feature = grf_load_byte(&buf);
|
|
|
|
setid = grf_load_byte(&buf);
|
|
|
|
type = grf_load_byte(&buf);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-09-22 20:35:20 +00:00
|
|
|
if (setid >= _cur_grffile->spritegroups_count) {
|
2005-10-04 19:52:26 +00:00
|
|
|
// Allocate memory for new sprite group references.
|
|
|
|
_cur_grffile->spritegroups = realloc(_cur_grffile->spritegroups, (setid + 1) * sizeof(*_cur_grffile->spritegroups));
|
|
|
|
// Initialise new space to NULL
|
|
|
|
for (; _cur_grffile->spritegroups_count < (setid + 1); _cur_grffile->spritegroups_count++)
|
|
|
|
_cur_grffile->spritegroups[_cur_grffile->spritegroups_count] = NULL;
|
2005-09-22 20:35:20 +00:00
|
|
|
}
|
|
|
|
|
2006-04-23 09:46:23 +00:00
|
|
|
switch (type) {
|
|
|
|
/* Deterministic Sprite Group */
|
|
|
|
case 0x81: // Self scope, byte
|
|
|
|
case 0x82: // Parent scope, byte
|
2006-04-26 20:44:28 +00:00
|
|
|
case 0x85: // Self scope, word
|
|
|
|
case 0x86: // Parent scope, word
|
|
|
|
case 0x89: // Self scope, dword
|
|
|
|
case 0x8A: // Parent scope, dword
|
2006-04-23 09:46:23 +00:00
|
|
|
{
|
2006-04-26 20:44:28 +00:00
|
|
|
byte varadjust;
|
|
|
|
byte varsize;
|
|
|
|
uint i;
|
2006-04-23 09:46:23 +00:00
|
|
|
|
2006-04-26 20:44:28 +00:00
|
|
|
/* Check we can load the var size parameter */
|
|
|
|
check_length(bufend - buf, 1, "NewSpriteGroup (Deterministic) (1)");
|
2006-04-23 09:46:23 +00:00
|
|
|
|
|
|
|
group = AllocateSpriteGroup();
|
|
|
|
group->type = SGT_DETERMINISTIC;
|
2006-04-26 20:44:28 +00:00
|
|
|
group->g.determ.var_scope = HASBIT(type, 1) ? VSG_SCOPE_PARENT : VSG_SCOPE_SELF;
|
|
|
|
|
|
|
|
switch (GB(type, 2, 2)) {
|
2006-04-27 06:33:21 +00:00
|
|
|
default: NOT_REACHED();
|
2006-04-26 20:44:28 +00:00
|
|
|
case 0: group->g.determ.size = DSG_SIZE_BYTE; varsize = 1; break;
|
|
|
|
case 1: group->g.determ.size = DSG_SIZE_WORD; varsize = 2; break;
|
|
|
|
case 2: group->g.determ.size = DSG_SIZE_DWORD; varsize = 4; break;
|
2006-04-23 09:46:23 +00:00
|
|
|
}
|
2004-11-14 18:18:28 +00:00
|
|
|
|
2006-04-26 20:44:28 +00:00
|
|
|
check_length(bufend - buf, 2 + (varsize * 3) + 2, "NewSpriteGroup (Deterministic) (2)");
|
|
|
|
|
|
|
|
/* Loop through the var adjusts. Unfortunately we don't know how many we have
|
|
|
|
* from the outset, so we shall have to keep reallocing. */
|
|
|
|
do {
|
|
|
|
DeterministicSpriteGroupAdjust *adjust;
|
|
|
|
|
|
|
|
if (group->g.determ.num_adjusts > 0) {
|
2006-04-30 18:39:31 +00:00
|
|
|
check_length(bufend - buf, 2 + varsize + 3, "NewSpriteGroup (Deterministic) (3)");
|
2006-04-26 20:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
group->g.determ.num_adjusts++;
|
|
|
|
group->g.determ.adjusts = realloc(group->g.determ.adjusts, group->g.determ.num_adjusts * sizeof(*group->g.determ.adjusts));
|
|
|
|
|
|
|
|
adjust = &group->g.determ.adjusts[group->g.determ.num_adjusts - 1];
|
|
|
|
|
|
|
|
/* The first var adjust doesn't have an operation specified, so we set it to add. */
|
|
|
|
adjust->operation = group->g.determ.num_adjusts == 1 ? DSGA_OP_ADD : grf_load_byte(&buf);
|
|
|
|
adjust->variable = grf_load_byte(&buf);
|
|
|
|
adjust->parameter = IS_BYTE_INSIDE(adjust->variable, 0x60, 0x80) ? grf_load_byte(&buf) : 0;
|
|
|
|
|
|
|
|
varadjust = grf_load_byte(&buf);
|
|
|
|
adjust->shift_num = GB(varadjust, 0, 5);
|
|
|
|
adjust->type = GB(varadjust, 6, 2);
|
|
|
|
adjust->and_mask = grf_load_var(varsize, &buf);
|
|
|
|
|
|
|
|
if (adjust->type != DSGA_TYPE_NONE) {
|
|
|
|
adjust->add_val = grf_load_var(varsize, &buf);
|
|
|
|
adjust->divmod_val = grf_load_var(varsize, &buf);
|
|
|
|
} else {
|
|
|
|
adjust->add_val = 0;
|
|
|
|
adjust->divmod_val = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Continue reading var adjusts while bit 5 is set. */
|
|
|
|
} while (HASBIT(varadjust, 5));
|
|
|
|
|
|
|
|
group->g.determ.num_ranges = grf_load_byte(&buf);
|
|
|
|
group->g.determ.ranges = calloc(group->g.determ.num_ranges, sizeof(*group->g.determ.ranges));
|
2006-04-23 09:46:23 +00:00
|
|
|
|
2006-04-26 20:44:28 +00:00
|
|
|
check_length(bufend - buf, 2 + (2 + 2 * varsize) * group->g.determ.num_ranges, "NewSpriteGroup (Deterministic)");
|
|
|
|
|
|
|
|
for (i = 0; i < group->g.determ.num_ranges; i++) {
|
|
|
|
group->g.determ.ranges[i].group = GetGroupFromGroupID(setid, type, grf_load_word(&buf));
|
|
|
|
group->g.determ.ranges[i].low = grf_load_var(varsize, &buf);
|
|
|
|
group->g.determ.ranges[i].high = grf_load_var(varsize, &buf);
|
2006-04-23 09:46:23 +00:00
|
|
|
}
|
2004-11-14 23:14:44 +00:00
|
|
|
|
2006-04-26 20:44:28 +00:00
|
|
|
group->g.determ.default_group = GetGroupFromGroupID(setid, type, grf_load_word(&buf));
|
2006-04-23 09:46:23 +00:00
|
|
|
break;
|
2004-11-14 18:18:28 +00:00
|
|
|
}
|
|
|
|
|
2006-04-23 09:46:23 +00:00
|
|
|
/* Randomized Sprite Group */
|
|
|
|
case 0x80: // Self scope
|
|
|
|
case 0x83: // Parent scope
|
|
|
|
{
|
2006-04-26 20:44:28 +00:00
|
|
|
byte triggers;
|
|
|
|
uint i;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-26 20:44:28 +00:00
|
|
|
check_length(bufend - buf, 7, "NewSpriteGroup (Randomized) (1)");
|
2004-11-17 08:52:47 +00:00
|
|
|
|
2006-04-23 09:46:23 +00:00
|
|
|
group = AllocateSpriteGroup();
|
|
|
|
group->type = SGT_RANDOMIZED;
|
2006-04-26 20:44:28 +00:00
|
|
|
group->g.random.var_scope = HASBIT(type, 1) ? VSG_SCOPE_PARENT : VSG_SCOPE_SELF;
|
2004-11-17 08:52:47 +00:00
|
|
|
|
2006-04-26 20:44:28 +00:00
|
|
|
triggers = grf_load_byte(&buf);
|
|
|
|
group->g.random.triggers = GB(triggers, 0, 7);
|
|
|
|
group->g.random.cmp_mode = HASBIT(triggers, 7) ? RSG_CMP_ALL : RSG_CMP_ANY;
|
|
|
|
group->g.random.lowest_randbit = grf_load_byte(&buf);
|
|
|
|
group->g.random.num_groups = grf_load_byte(&buf);
|
|
|
|
group->g.random.groups = calloc(group->g.random.num_groups, sizeof(*group->g.random.groups));
|
2004-11-17 08:52:47 +00:00
|
|
|
|
2006-04-26 20:44:28 +00:00
|
|
|
check_length(bufend - buf, 2 * group->g.random.num_groups, "NewSpriteGroup (Randomized) (2)");
|
2004-11-17 08:52:47 +00:00
|
|
|
|
2006-04-26 20:44:28 +00:00
|
|
|
for (i = 0; i < group->g.random.num_groups; i++) {
|
|
|
|
group->g.random.groups[i] = GetGroupFromGroupID(setid, type, grf_load_word(&buf));
|
2006-04-23 09:46:23 +00:00
|
|
|
}
|
2004-11-17 08:52:47 +00:00
|
|
|
|
2006-04-23 09:46:23 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-11-17 08:52:47 +00:00
|
|
|
|
2006-04-26 20:44:28 +00:00
|
|
|
/* Neither a variable or randomized sprite group... must be a real group */
|
2006-04-23 09:46:23 +00:00
|
|
|
default:
|
|
|
|
{
|
2006-05-10 06:23:43 +00:00
|
|
|
|
|
|
|
|
2006-04-26 20:44:28 +00:00
|
|
|
switch (feature) {
|
|
|
|
case GSF_TRAIN:
|
|
|
|
case GSF_ROAD:
|
|
|
|
case GSF_SHIP:
|
|
|
|
case GSF_AIRCRAFT:
|
|
|
|
case GSF_STATION:
|
|
|
|
{
|
|
|
|
byte sprites = _cur_grffile->spriteset_numents;
|
|
|
|
byte num_loaded = type;
|
|
|
|
byte num_loading = grf_load_byte(&buf);
|
|
|
|
uint i;
|
|
|
|
|
|
|
|
if (_cur_grffile->spriteset_start == 0) {
|
|
|
|
grfmsg(GMS_ERROR, "NewSpriteGroup: No sprite set to work on! Skipping.");
|
|
|
|
return;
|
|
|
|
}
|
2006-04-23 09:46:23 +00:00
|
|
|
|
2006-04-26 20:44:28 +00:00
|
|
|
check_length(bufend - buf, 2 * num_loaded + 2 * num_loading, "NewSpriteGroup (Real) (1)");
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-26 20:44:28 +00:00
|
|
|
group = AllocateSpriteGroup();
|
|
|
|
group->type = SGT_REAL;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-26 20:44:28 +00:00
|
|
|
group->g.real.num_loaded = num_loaded;
|
|
|
|
group->g.real.num_loading = num_loading;
|
|
|
|
if (num_loaded > 0) group->g.real.loaded = calloc(num_loaded, sizeof(*group->g.real.loaded));
|
|
|
|
if (num_loading > 0) group->g.real.loading = calloc(num_loading, sizeof(*group->g.real.loading));
|
2004-11-12 15:36:49 +00:00
|
|
|
|
2006-04-26 20:44:28 +00:00
|
|
|
DEBUG(grf, 6) ("NewSpriteGroup: New SpriteGroup 0x%02X, %u views, %u loaded, %u loading",
|
|
|
|
setid, sprites, num_loaded, num_loading);
|
2006-04-23 09:46:23 +00:00
|
|
|
|
2006-04-26 20:44:28 +00:00
|
|
|
for (i = 0; i < num_loaded; i++) {
|
|
|
|
uint16 spriteid = grf_load_word(&buf);
|
2006-05-10 06:23:43 +00:00
|
|
|
group->g.real.loaded[i] = CreateGroupFromGroupID(feature, setid, type, spriteid, sprites);
|
2006-04-26 20:44:28 +00:00
|
|
|
DEBUG(grf, 8) ("NewSpriteGroup: + rg->loaded[%i] = subset %u", i, spriteid);
|
|
|
|
}
|
2006-04-23 09:46:23 +00:00
|
|
|
|
2006-04-26 20:44:28 +00:00
|
|
|
for (i = 0; i < num_loading; i++) {
|
|
|
|
uint16 spriteid = grf_load_word(&buf);
|
2006-05-10 06:23:43 +00:00
|
|
|
group->g.real.loading[i] = CreateGroupFromGroupID(feature, setid, type, spriteid, sprites);
|
2006-04-26 20:44:28 +00:00
|
|
|
DEBUG(grf, 8) ("NewSpriteGroup: + rg->loading[%i] = subset %u", i, spriteid);
|
|
|
|
}
|
2006-04-23 09:46:23 +00:00
|
|
|
|
2006-04-26 20:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-26 20:44:28 +00:00
|
|
|
/* Loading of Tile Layout and Production Callback groups would happen here */
|
|
|
|
default:
|
|
|
|
grfmsg(GMS_WARN, "NewSpriteGroup: Unsupported feature %d, skipping.", feature);
|
|
|
|
}
|
2005-10-04 20:38:26 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-09-22 20:35:20 +00:00
|
|
|
|
|
|
|
_cur_grffile->spritegroups[setid] = group;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2004-11-12 15:15:56 +00:00
|
|
|
/* Action 0x03 */
|
2004-11-12 23:59:51 +00:00
|
|
|
static void NewVehicle_SpriteGroupMapping(byte *buf, int len)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
/* <03> <feature> <n-id> <ids>... <num-cid> [<cargo-type> <cid>]... <def-cid>
|
2004-11-12 15:15:56 +00:00
|
|
|
* id-list := [<id>] [id-list]
|
|
|
|
* cargo-list := <cargo-type> <cid> [cargo-list]
|
2004-08-09 17:04:08 +00:00
|
|
|
*
|
|
|
|
* B feature see action 0
|
|
|
|
* B n-id bits 0-6: how many IDs this definition applies to
|
|
|
|
* bit 7: if set, this is a wagon override definition (see below)
|
|
|
|
* B ids the IDs for which this definition applies
|
2004-11-12 23:59:51 +00:00
|
|
|
* B num-cid number of cargo IDs (sprite group IDs) in this definition
|
2004-08-09 17:04:08 +00:00
|
|
|
* can be zero, in that case the def-cid is used always
|
|
|
|
* B cargo-type type of this cargo type (e.g. mail=2, wood=7, see below)
|
2004-11-12 23:59:51 +00:00
|
|
|
* W cid cargo ID (sprite group ID) for this type of cargo
|
|
|
|
* W def-cid default cargo ID (sprite group ID) */
|
2004-11-14 10:03:21 +00:00
|
|
|
/* TODO: Bridges, town houses. */
|
2004-08-09 17:04:08 +00:00
|
|
|
/* TODO: Multiple cargo support could be useful even for trains/cars -
|
|
|
|
* cargo id 0xff is used for showing images in the build train list. */
|
|
|
|
|
|
|
|
static byte *last_engines;
|
|
|
|
static int last_engines_count;
|
2004-11-12 15:36:49 +00:00
|
|
|
uint8 feature;
|
|
|
|
uint8 idcount;
|
2004-11-13 18:08:45 +00:00
|
|
|
bool wagover;
|
2004-11-12 15:36:49 +00:00
|
|
|
uint8 cidcount;
|
|
|
|
int c, i;
|
|
|
|
|
2006-05-07 17:43:03 +00:00
|
|
|
check_length(len, 6, "VehicleMapSpriteGroup");
|
2004-11-12 15:36:49 +00:00
|
|
|
feature = buf[1];
|
2004-11-12 18:43:12 +00:00
|
|
|
idcount = buf[2] & 0x7F;
|
2004-11-13 18:08:45 +00:00
|
|
|
wagover = (buf[2] & 0x80) == 0x80;
|
2004-11-13 12:21:32 +00:00
|
|
|
check_length(len, 3 + idcount, "VehicleMapSpriteGroup");
|
2006-05-07 17:43:03 +00:00
|
|
|
|
|
|
|
/* If ``n-id'' (or ``idcount'') is zero, this is a ``feature
|
|
|
|
* callback''. */
|
|
|
|
if (idcount == 0) {
|
|
|
|
grfmsg(GMS_WARN, "VehicleMapSpriteGroup: Feature callbacks not implemented yet.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-11-12 15:36:49 +00:00
|
|
|
cidcount = buf[3 + idcount];
|
2004-11-13 12:21:32 +00:00
|
|
|
check_length(len, 4 + idcount + cidcount * 3, "VehicleMapSpriteGroup");
|
2004-11-12 15:36:49 +00:00
|
|
|
|
2004-11-13 18:08:45 +00:00
|
|
|
DEBUG(grf, 6) ("VehicleMapSpriteGroup: Feature %d, %d ids, %d cids, wagon override %d.",
|
|
|
|
feature, idcount, cidcount, wagover);
|
|
|
|
|
2004-11-14 10:03:21 +00:00
|
|
|
if (feature > GSF_STATION) {
|
|
|
|
grfmsg(GMS_WARN, "VehicleMapSpriteGroup: Unsupported feature %d, skipping.", feature);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-11-14 09:07:15 +00:00
|
|
|
|
2004-11-13 12:38:38 +00:00
|
|
|
if (feature == GSF_STATION) {
|
2004-11-14 09:07:15 +00:00
|
|
|
// We do things differently for stations.
|
|
|
|
|
|
|
|
for (i = 0; i < idcount; i++) {
|
|
|
|
uint8 stid = buf[3 + i];
|
2006-05-06 22:20:16 +00:00
|
|
|
StationSpec *statspec = _cur_grffile->stations[stid];
|
2004-11-14 16:11:48 +00:00
|
|
|
byte *bp = &buf[4 + idcount];
|
|
|
|
|
|
|
|
for (c = 0; c < cidcount; c++) {
|
|
|
|
uint8 ctype = grf_load_byte(&bp);
|
|
|
|
uint16 groupid = grf_load_word(&bp);
|
|
|
|
|
2005-10-15 07:40:22 +00:00
|
|
|
if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
|
2006-04-22 13:56:16 +00:00
|
|
|
grfmsg(GMS_WARN, "VehicleMapSpriteGroup: Spriteset 0x%04X out of range 0x%X or empty, skipping.",
|
2004-11-14 16:11:48 +00:00
|
|
|
groupid, _cur_grffile->spritegroups_count);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-05-04 19:15:02 +00:00
|
|
|
if (ctype == 0xFE) ctype = GC_DEFAULT_NA;
|
|
|
|
if (ctype == 0xFF) ctype = GC_PURCHASE;
|
2004-11-14 16:11:48 +00:00
|
|
|
|
2006-05-04 19:15:02 +00:00
|
|
|
statspec->spritegroup[ctype] = _cur_grffile->spritegroups[groupid];
|
2004-11-14 16:11:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
byte *bp = buf + 4 + idcount + cidcount * 3;
|
|
|
|
uint16 groupid = grf_load_word(&bp);
|
2004-11-14 09:07:15 +00:00
|
|
|
|
2005-10-15 07:40:22 +00:00
|
|
|
if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
|
2006-04-22 13:56:16 +00:00
|
|
|
grfmsg(GMS_WARN, "VehicleMapSpriteGroup: Spriteset 0x%04X out of range 0x%X or empty, skipping.",
|
2004-11-14 13:45:38 +00:00
|
|
|
groupid, _cur_grffile->spritegroups_count);
|
2004-11-14 09:07:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-11-14 16:11:48 +00:00
|
|
|
for (i = 0; i < idcount; i++) {
|
|
|
|
uint8 stid = buf[3 + i];
|
2006-05-06 22:20:16 +00:00
|
|
|
StationSpec *statspec = _cur_grffile->stations[stid];
|
2004-11-14 09:07:15 +00:00
|
|
|
|
2006-05-04 19:15:02 +00:00
|
|
|
statspec->spritegroup[GC_DEFAULT] = _cur_grffile->spritegroups[groupid];
|
2006-05-07 10:58:53 +00:00
|
|
|
statspec->groundgroup = _cur_grffile->spritegroups[0];
|
2006-04-27 18:28:56 +00:00
|
|
|
statspec->grfid = _cur_grffile->grfid;
|
|
|
|
statspec->localidx = stid;
|
|
|
|
SetCustomStationSpec(statspec);
|
2004-11-14 09:07:15 +00:00
|
|
|
}
|
|
|
|
}
|
2004-11-12 15:36:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-11-12 15:36:49 +00:00
|
|
|
// FIXME: Tropicset contains things like:
|
|
|
|
// 03 00 01 19 01 00 00 00 00 - this is missing one 00 at the end,
|
|
|
|
// what should we exactly do with that? --pasky
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-23 11:13:06 +00:00
|
|
|
if (_cur_grffile->spriteset_start == 0 || _cur_grffile->spritegroups == 0) {
|
2004-11-12 23:59:51 +00:00
|
|
|
grfmsg(GMS_WARN, "VehicleMapSpriteGroup: No sprite set to work on! Skipping.");
|
2004-11-12 15:36:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-11-12 15:36:49 +00:00
|
|
|
if (!wagover && last_engines_count != idcount) {
|
|
|
|
last_engines = realloc(last_engines, idcount);
|
|
|
|
last_engines_count = idcount;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-11-13 18:08:45 +00:00
|
|
|
if (wagover) {
|
2004-11-13 12:21:32 +00:00
|
|
|
if (last_engines_count == 0) {
|
|
|
|
grfmsg(GMS_ERROR, "VehicleMapSpriteGroup: WagonOverride: No engine to do override with.");
|
|
|
|
return;
|
|
|
|
}
|
2004-11-13 18:08:45 +00:00
|
|
|
DEBUG(grf, 6) ("VehicleMapSpriteGroup: WagonOverride: %u engines, %u wagons.",
|
|
|
|
last_engines_count, idcount);
|
2004-11-13 12:21:32 +00:00
|
|
|
}
|
2004-11-14 13:59:11 +00:00
|
|
|
|
2004-11-13 12:21:32 +00:00
|
|
|
|
2004-11-12 15:36:49 +00:00
|
|
|
for (i = 0; i < idcount; i++) {
|
2004-11-13 12:21:32 +00:00
|
|
|
uint8 engine_id = buf[3 + i];
|
|
|
|
uint8 engine = engine_id + _vehshifts[feature];
|
2004-11-12 15:36:49 +00:00
|
|
|
byte *bp = &buf[4 + idcount];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-11-13 12:21:32 +00:00
|
|
|
if (engine_id > _vehcounts[feature]) {
|
2006-04-22 13:56:16 +00:00
|
|
|
grfmsg(GMS_ERROR, "Id %u for feature 0x%02X is out of bounds.", engine_id, feature);
|
2004-11-13 12:21:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-11-13 18:08:45 +00:00
|
|
|
DEBUG(grf, 7) ("VehicleMapSpriteGroup: [%d] Engine %d...", i, engine);
|
|
|
|
|
2004-11-12 15:36:49 +00:00
|
|
|
for (c = 0; c < cidcount; c++) {
|
|
|
|
uint8 ctype = grf_load_byte(&bp);
|
2004-11-12 23:59:51 +00:00
|
|
|
uint16 groupid = grf_load_word(&bp);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-22 13:56:16 +00:00
|
|
|
DEBUG(grf, 8) ("VehicleMapSpriteGroup: * [%d] Cargo type 0x%X, group id 0x%02X", c, ctype, groupid);
|
2004-11-13 18:08:45 +00:00
|
|
|
|
2005-10-15 07:40:22 +00:00
|
|
|
if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
|
2006-04-22 13:56:16 +00:00
|
|
|
grfmsg(GMS_WARN, "VehicleMapSpriteGroup: Spriteset 0x%04X out of range 0x%X or empty, skipping.", groupid, _cur_grffile->spritegroups_count);
|
2004-11-12 15:36:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-14 12:36:16 +00:00
|
|
|
if (ctype == GC_INVALID) ctype = GC_PURCHASE;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-11-13 18:08:45 +00:00
|
|
|
if (wagover) {
|
2004-11-12 15:36:49 +00:00
|
|
|
// TODO: No multiple cargo types per vehicle yet. --pasky
|
2005-09-22 20:35:20 +00:00
|
|
|
SetWagonOverrideSprites(engine, _cur_grffile->spritegroups[groupid], last_engines, last_engines_count);
|
2004-11-12 15:36:49 +00:00
|
|
|
} else {
|
2005-09-22 20:35:20 +00:00
|
|
|
SetCustomEngineSprites(engine, ctype, _cur_grffile->spritegroups[groupid]);
|
2004-11-12 15:36:49 +00:00
|
|
|
last_engines[i] = engine;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
2004-11-12 15:36:49 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-11-12 15:36:49 +00:00
|
|
|
{
|
|
|
|
byte *bp = buf + 4 + idcount + cidcount * 3;
|
2004-11-12 23:59:51 +00:00
|
|
|
uint16 groupid = grf_load_word(&bp);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-22 13:56:16 +00:00
|
|
|
DEBUG(grf, 8) ("-- Default group id 0x%04X", groupid);
|
2004-11-13 18:08:45 +00:00
|
|
|
|
2004-11-12 15:36:49 +00:00
|
|
|
for (i = 0; i < idcount; i++) {
|
|
|
|
uint8 engine = buf[3 + i] + _vehshifts[feature];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-11-12 15:36:49 +00:00
|
|
|
// Don't tell me you don't love duplicated code!
|
2005-10-15 07:40:22 +00:00
|
|
|
if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
|
2006-04-22 13:56:16 +00:00
|
|
|
grfmsg(GMS_WARN, "VehicleMapSpriteGroup: Spriteset 0x%04X out of range 0x%X or empty, skipping.", groupid, _cur_grffile->spritegroups_count);
|
2004-11-12 15:36:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-11-13 18:08:45 +00:00
|
|
|
if (wagover) {
|
2006-04-30 18:41:16 +00:00
|
|
|
/* If the ID for this action 3 is the same as the vehicle ID,
|
|
|
|
* this indicates we have a helicopter rotor override. */
|
|
|
|
if (feature == GSF_AIRCRAFT && engine == last_engines[i]) {
|
|
|
|
SetRotorOverrideSprites(engine, _cur_grffile->spritegroups[groupid]);
|
|
|
|
} else {
|
|
|
|
// TODO: No multiple cargo types per vehicle yet. --pasky
|
|
|
|
SetWagonOverrideSprites(engine, _cur_grffile->spritegroups[groupid], last_engines, last_engines_count);
|
|
|
|
}
|
2004-11-12 15:36:49 +00:00
|
|
|
} else {
|
2005-09-22 20:35:20 +00:00
|
|
|
SetCustomEngineSprites(engine, GC_DEFAULT, _cur_grffile->spritegroups[groupid]);
|
2006-05-02 21:58:02 +00:00
|
|
|
SetEngineGRF(engine, _cur_grffile->grfid);
|
2004-11-12 15:36:49 +00:00
|
|
|
last_engines[i] = engine;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-12 15:15:56 +00:00
|
|
|
/* Action 0x04 */
|
2004-08-09 17:04:08 +00:00
|
|
|
static void VehicleNewName(byte *buf, int len)
|
|
|
|
{
|
|
|
|
/* <04> <veh-type> <language-id> <num-veh> <offset> <data...>
|
|
|
|
*
|
2006-04-21 03:00:20 +00:00
|
|
|
* B veh-type see action 0 (as 00..07, + 0A
|
|
|
|
* But IF veh-type = 48, then generic text
|
|
|
|
* B language-id If bit 6 is set, This is the extended language scheme,
|
|
|
|
with up to 64 language.
|
|
|
|
Otherwise, it is a mapping where set bits have meaning
|
|
|
|
0 = american, 1 = english, 2 = german, 3 = french, 4 = spanish
|
|
|
|
Bit 7 set means this is a generic text, not a vehicle one (or else)
|
2004-08-09 17:04:08 +00:00
|
|
|
* B num-veh number of vehicles which are getting a new name
|
2005-08-15 22:48:33 +00:00
|
|
|
* B/W offset number of the first vehicle that gets a new name
|
2006-04-21 03:00:20 +00:00
|
|
|
* Byte : ID of vehicle to change
|
|
|
|
* Word : ID of string to change/add
|
2004-08-09 17:04:08 +00:00
|
|
|
* S data new texts, each of them zero-terminated, after
|
|
|
|
* which the next name begins. */
|
|
|
|
/* TODO: No support for changing non-vehicle text. Perhaps we shouldn't
|
|
|
|
* implement it at all, but it could be useful for some "modpacks"
|
|
|
|
* (completely new scenarios changing all graphics and logically also
|
|
|
|
* factory names etc). We should then also support all languages (by
|
2006-04-21 03:00:20 +00:00
|
|
|
* name), not only the original four ones. --pasky
|
|
|
|
* All of the above are coming. In Time. Some sooner than others :)*/
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-11-12 15:36:49 +00:00
|
|
|
uint8 feature;
|
|
|
|
uint8 lang;
|
2005-08-15 22:48:33 +00:00
|
|
|
uint8 num;
|
|
|
|
uint16 id;
|
|
|
|
uint16 endid;
|
2005-02-06 22:25:27 +00:00
|
|
|
const char* name;
|
2006-04-23 18:37:53 +00:00
|
|
|
bool new_scheme = _cur_grffile->grf_version >= 7;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-11-12 15:36:49 +00:00
|
|
|
check_length(len, 6, "VehicleNewName");
|
2005-08-15 22:48:33 +00:00
|
|
|
buf++;
|
|
|
|
feature = grf_load_byte(&buf);
|
|
|
|
lang = grf_load_byte(&buf);
|
|
|
|
num = grf_load_byte(&buf);
|
|
|
|
id = (lang & 0x80) ? grf_load_word(&buf) : grf_load_byte(&buf);
|
|
|
|
|
2006-05-06 20:20:02 +00:00
|
|
|
if (feature <= GSF_AIRCRAFT && id < _vehcounts[feature]) {
|
2006-04-21 03:00:20 +00:00
|
|
|
id += _vehshifts[feature];
|
2005-08-15 22:48:33 +00:00
|
|
|
}
|
|
|
|
endid = id + num;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-22 13:56:16 +00:00
|
|
|
DEBUG(grf, 6) ("VehicleNewName: About to rename engines %d..%d (feature %d) in language 0x%02X.",
|
2004-11-13 18:08:45 +00:00
|
|
|
id, endid, feature, lang);
|
|
|
|
|
2006-04-21 03:00:20 +00:00
|
|
|
name = (const char*)buf; /*transfer read value*/
|
2005-08-15 22:48:33 +00:00
|
|
|
len -= (lang & 0x80) ? 6 : 5;
|
2004-11-12 15:36:49 +00:00
|
|
|
for (; id < endid && len > 0; id++) {
|
2005-09-25 09:04:59 +00:00
|
|
|
size_t ofs = strlen(name) + 1;
|
2004-11-12 15:36:49 +00:00
|
|
|
|
2006-05-17 13:05:44 +00:00
|
|
|
if (ofs > 1 && ofs < 128) {
|
2005-02-06 22:25:27 +00:00
|
|
|
DEBUG(grf, 8) ("VehicleNewName: %d <- %s", id, name);
|
2006-04-21 03:00:20 +00:00
|
|
|
|
|
|
|
switch (feature) {
|
|
|
|
case GSF_TRAIN:
|
|
|
|
case GSF_ROAD:
|
|
|
|
case GSF_SHIP:
|
2006-04-21 20:59:04 +00:00
|
|
|
case GSF_AIRCRAFT: {
|
2006-05-11 16:27:46 +00:00
|
|
|
if (id < TOTAL_NUM_ENGINES) {
|
|
|
|
StringID string = AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_8000_KIRBY_PAUL_TANK_STEAM + id);
|
|
|
|
SetCustomEngineName(id, string);
|
|
|
|
} else {
|
|
|
|
AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, id);
|
|
|
|
}
|
2006-04-21 03:00:20 +00:00
|
|
|
break;
|
2006-04-21 20:59:04 +00:00
|
|
|
}
|
2006-04-21 03:00:20 +00:00
|
|
|
|
2006-05-06 20:20:02 +00:00
|
|
|
default:
|
2006-04-21 03:00:20 +00:00
|
|
|
switch (GB(id, 8, 8)) {
|
2006-05-06 20:20:02 +00:00
|
|
|
case 0xC4: /* Station class name */
|
2006-05-06 22:20:16 +00:00
|
|
|
if (_cur_grffile->stations == NULL || _cur_grffile->stations[GB(id, 0, 8)] == NULL) {
|
2006-05-06 20:27:32 +00:00
|
|
|
grfmsg(GMS_WARN, "VehicleNewName: Attempt to name undefined station 0x%X, ignoring.", GB(id, 0, 8));
|
2006-05-06 20:20:02 +00:00
|
|
|
} else {
|
2006-05-06 22:20:16 +00:00
|
|
|
StationClassID sclass = _cur_grffile->stations[GB(id, 0, 8)]->sclass;
|
2006-05-11 16:27:46 +00:00
|
|
|
SetStationClassName(sclass, AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED));
|
2006-05-06 20:20:02 +00:00
|
|
|
}
|
2006-04-21 03:00:20 +00:00
|
|
|
break;
|
|
|
|
|
2006-05-06 20:20:02 +00:00
|
|
|
case 0xC5: /* Station name */
|
2006-05-06 22:20:16 +00:00
|
|
|
if (_cur_grffile->stations == NULL || _cur_grffile->stations[GB(id, 0, 8)] == NULL) {
|
2006-05-06 20:27:32 +00:00
|
|
|
grfmsg(GMS_WARN, "VehicleNewName: Attempt to name undefined station 0x%X, ignoring.", GB(id, 0, 8));
|
2006-05-06 20:20:02 +00:00
|
|
|
} else {
|
2006-05-11 16:27:46 +00:00
|
|
|
_cur_grffile->stations[GB(id, 0, 8)]->name = AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED);
|
2006-05-06 20:20:02 +00:00
|
|
|
}
|
2006-04-21 03:00:20 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2006-04-22 13:56:16 +00:00
|
|
|
DEBUG(grf, 7) ("VehicleNewName: Unsupported ID (0x%04X)", id);
|
2006-04-21 03:00:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2006-04-23 18:37:06 +00:00
|
|
|
#if 0
|
2006-04-21 03:00:20 +00:00
|
|
|
case GSF_CANAL :
|
|
|
|
case GSF_BRIDGE :
|
|
|
|
case GSF_TOWNHOUSE :
|
|
|
|
AddGRFString(_cur_spriteid, id, lang, name);
|
|
|
|
switch (GB(id, 8,8)) {
|
|
|
|
case 0xC9: /* House name */
|
|
|
|
default:
|
2006-04-22 13:56:16 +00:00
|
|
|
DEBUG(grf, 7) ("VehicleNewName: Unsupported ID (0x%04X)", id);
|
2006-04-21 03:00:20 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GSF_INDUSTRIES :
|
|
|
|
case 0x48 : /* for generic strings */
|
|
|
|
AddGRFString(_cur_spriteid, id, lang, name);
|
|
|
|
break;
|
|
|
|
default :
|
2006-04-22 13:56:16 +00:00
|
|
|
DEBUG(grf,7) ("VehicleNewName: Unsupported feature (0x%02X)", feature);
|
2006-04-21 03:00:20 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
}
|
2004-11-13 18:08:45 +00:00
|
|
|
} else {
|
2006-05-17 13:05:44 +00:00
|
|
|
/* ofs is the string length + 1, so if the string is empty, ofs
|
|
|
|
* is 1 */
|
|
|
|
if (ofs == 1) {
|
|
|
|
DEBUG(grf, 7) ("VehicleNewName: Can't add empty name");
|
|
|
|
} else {
|
|
|
|
DEBUG(grf, 7) ("VehicleNewName: Too long a name (%d)", ofs);
|
|
|
|
}
|
2004-11-13 18:08:45 +00:00
|
|
|
}
|
2005-02-06 22:25:27 +00:00
|
|
|
name += ofs;
|
|
|
|
len -= ofs;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-12 15:15:56 +00:00
|
|
|
/* Action 0x05 */
|
2004-08-09 17:04:08 +00:00
|
|
|
static void GraphicsNew(byte *buf, int len)
|
|
|
|
{
|
|
|
|
/* <05> <graphics-type> <num-sprites> <other data...>
|
|
|
|
*
|
|
|
|
* B graphics-type What set of graphics the sprites define.
|
2005-08-15 22:48:33 +00:00
|
|
|
* E num-sprites How many sprites are in this set?
|
2004-08-09 17:04:08 +00:00
|
|
|
* V other data Graphics type specific data. Currently unused. */
|
|
|
|
/* TODO */
|
2004-11-12 15:15:56 +00:00
|
|
|
|
|
|
|
uint8 type;
|
2005-08-15 22:48:33 +00:00
|
|
|
uint16 num;
|
2006-05-01 16:54:18 +00:00
|
|
|
SpriteID replace = 0;
|
2004-11-12 15:15:56 +00:00
|
|
|
|
2004-11-12 15:36:49 +00:00
|
|
|
check_length(len, 2, "GraphicsNew");
|
2005-08-15 22:48:33 +00:00
|
|
|
buf++;
|
|
|
|
type = grf_load_byte(&buf);
|
|
|
|
num = grf_load_extended(&buf);
|
2004-11-12 15:15:56 +00:00
|
|
|
|
2006-04-23 15:57:34 +00:00
|
|
|
switch (type) {
|
|
|
|
case 0x04: /* Signal graphics */
|
|
|
|
if (num != 112 && num != 240) {
|
|
|
|
grfmsg(GMS_WARN, "GraphicsNews: Signal graphics sprite count must be 112 or 240, skipping.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_signal_base = _cur_spriteid;
|
|
|
|
break;
|
|
|
|
|
2006-05-01 16:54:18 +00:00
|
|
|
case 0x05: /* Catenary graphics */
|
|
|
|
if (num != 48) {
|
|
|
|
grfmsg(GMS_WARN, "GraphicsNews: Catenary graphics sprite count must be 48, skipping.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
replace = SPR_ELRAIL_BASE + 3;
|
|
|
|
break;
|
|
|
|
|
2006-05-01 18:57:43 +00:00
|
|
|
case 0x06: /* Foundations */
|
|
|
|
if (num != 74) {
|
|
|
|
grfmsg(GMS_WARN, "GraphicsNews: Foundation graphics sprite count must be 74, skipping.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
replace = SPR_SLOPES_BASE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x08: /* Canal graphics */
|
|
|
|
if (num != 65) {
|
|
|
|
grfmsg(GMS_WARN, "GraphicsNews: Canal graphics sprite count must be 65, skipping.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
replace = SPR_CANALS_BASE + 5;
|
|
|
|
break;
|
|
|
|
|
2006-04-23 15:57:34 +00:00
|
|
|
default:
|
|
|
|
grfmsg(GMS_NOTICE, "GraphicsNew: Custom graphics (type 0x%02X) sprite block of length %u (unimplemented, ignoring).\n",
|
|
|
|
type, num);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-05-01 16:54:18 +00:00
|
|
|
if (replace == 0) {
|
|
|
|
grfmsg(GMS_NOTICE, "GraphicsNew: Loading %u sprites of type 0x%02X at SpriteID 0x%04X", num, type, _cur_spriteid);
|
|
|
|
} else {
|
|
|
|
grfmsg(GMS_NOTICE, "GraphicsNew: Replacing %u sprites of type 0x%02X at SpriteID 0x%04X", num, type, replace);
|
|
|
|
}
|
2006-04-23 15:57:34 +00:00
|
|
|
|
|
|
|
for (; num > 0; num--) {
|
2006-05-01 16:54:18 +00:00
|
|
|
LoadNextSprite(replace == 0 ? _cur_spriteid++ : replace++, _file_index);
|
2006-04-23 15:57:34 +00:00
|
|
|
_nfo_line++;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2004-11-12 15:15:56 +00:00
|
|
|
/* Action 0x06 */
|
2004-08-09 17:04:08 +00:00
|
|
|
static void CfgApply(byte *buf, int len)
|
|
|
|
{
|
|
|
|
/* <06> <param-num> <param-size> <offset> ... <FF>
|
|
|
|
*
|
|
|
|
* B param-num Number of parameter to substitute (First = "zero")
|
|
|
|
* Ignored if that parameter was not specified in newgrf.cfg
|
|
|
|
* B param-size How many bytes to replace. If larger than 4, the
|
|
|
|
* bytes of the following parameter are used. In that
|
|
|
|
* case, nothing is applied unless *all* parameters
|
|
|
|
* were specified.
|
|
|
|
* B offset Offset into data from beginning of next sprite
|
|
|
|
* to place where parameter is to be stored. */
|
|
|
|
/* TODO */
|
2004-11-12 15:15:56 +00:00
|
|
|
grfmsg(GMS_NOTICE, "CfgApply: Ignoring (not implemented).\n");
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-10 21:34:57 +00:00
|
|
|
static uint32 GetParamVal(byte param, uint32 *cond_val)
|
|
|
|
{
|
|
|
|
switch (param) {
|
|
|
|
case 0x83: /* current climate, 0=temp, 1=arctic, 2=trop, 3=toyland */
|
|
|
|
return _opt.landscape;
|
|
|
|
|
|
|
|
case 0x84: /* .grf loading stage, 0=initialization, 1=activation */
|
|
|
|
return _cur_stage;
|
|
|
|
|
2006-05-11 09:54:11 +00:00
|
|
|
case 0x85: /* TTDPatch flags, only for bit tests */
|
|
|
|
if (cond_val == NULL) {
|
|
|
|
/* Supported in Action 0x07 and 0x09, not 0x0D */
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
uint32 param_val = _ttdpatch_flags[*cond_val / 0x20];
|
|
|
|
*cond_val %= 0x20;
|
|
|
|
return param_val;
|
|
|
|
}
|
2006-05-10 21:34:57 +00:00
|
|
|
|
|
|
|
case 0x86: /* road traffic side, bit 4 clear=left, set=right */
|
|
|
|
return _opt.road_side << 4;
|
|
|
|
|
|
|
|
case 0x88: /* GRF ID check */
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case 0x8B: { /* TTDPatch version */
|
|
|
|
uint major = 2;
|
|
|
|
uint minor = 0;
|
|
|
|
uint revision = 10; // special case: 2.0.1 is 2.0.10
|
|
|
|
uint build = 73;
|
|
|
|
return (major << 24) | (minor << 20) | (revision << 16) | (build * 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
case 0x8D: /* TTD Version, 00=DOS, 01=Windows */
|
|
|
|
return !_use_dos_palette;
|
|
|
|
|
|
|
|
case 0x8E: /* Y-offset for train sprites */
|
|
|
|
return _traininfo_vehicle_pitch;
|
|
|
|
|
|
|
|
case 0x92: /* Game mode */
|
|
|
|
return _game_mode;
|
|
|
|
|
|
|
|
case 0x9D: /* TTD Platform, 00=TTDPatch, 01=OpenTTD */
|
|
|
|
return 1;
|
|
|
|
|
2006-05-11 12:41:02 +00:00
|
|
|
case 0x9E: /* Miscellaneous GRF features */
|
|
|
|
return _misc_grf_features;
|
|
|
|
|
2006-05-10 21:34:57 +00:00
|
|
|
default:
|
|
|
|
/* GRF Parameter */
|
|
|
|
if (param < 0x80) return _cur_grffile->param[param];
|
|
|
|
|
|
|
|
/* In-game variable. */
|
|
|
|
grfmsg(GMS_WARN, "Unsupported in-game variable 0x%02X.", param);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-12 15:15:56 +00:00
|
|
|
/* Action 0x07 */
|
|
|
|
/* Action 0x09 */
|
2004-08-09 17:04:08 +00:00
|
|
|
static void SkipIf(byte *buf, int len)
|
|
|
|
{
|
|
|
|
/* <07/09> <param-num> <param-size> <condition-type> <value> <num-sprites>
|
|
|
|
*
|
|
|
|
* B param-num
|
|
|
|
* B param-size
|
|
|
|
* B condition-type
|
|
|
|
* V value
|
|
|
|
* B num-sprites */
|
|
|
|
/* TODO: More params. More condition types. */
|
2004-11-12 15:36:49 +00:00
|
|
|
uint8 param;
|
|
|
|
uint8 paramsize;
|
|
|
|
uint8 condtype;
|
|
|
|
uint8 numsprites;
|
2005-08-13 16:23:07 +00:00
|
|
|
uint32 param_val = 0;
|
|
|
|
uint32 cond_val = 0;
|
2006-05-10 21:34:57 +00:00
|
|
|
uint32 mask = 0;
|
2004-11-12 18:43:12 +00:00
|
|
|
bool result;
|
2006-04-15 21:27:59 +00:00
|
|
|
GRFLabel *label;
|
|
|
|
GRFLabel *choice = NULL;
|
2004-11-12 15:36:49 +00:00
|
|
|
|
|
|
|
check_length(len, 6, "SkipIf");
|
2006-05-02 09:18:51 +00:00
|
|
|
buf++;
|
|
|
|
param = grf_load_byte(&buf);
|
|
|
|
paramsize = grf_load_byte(&buf);
|
|
|
|
condtype = grf_load_byte(&buf);
|
2004-11-12 15:36:49 +00:00
|
|
|
|
2004-11-12 17:27:30 +00:00
|
|
|
if (condtype < 2) {
|
2005-04-01 10:43:20 +00:00
|
|
|
/* Always 1 for bit tests, the given value should be ignored. */
|
2004-11-12 17:27:30 +00:00
|
|
|
paramsize = 1;
|
|
|
|
}
|
|
|
|
|
2005-04-01 10:43:20 +00:00
|
|
|
switch (paramsize) {
|
2006-05-10 21:34:57 +00:00
|
|
|
case 4: cond_val = grf_load_dword(&buf); mask = 0xFFFFFFFF; break;
|
|
|
|
case 2: cond_val = grf_load_word(&buf); mask = 0x0000FFFF; break;
|
|
|
|
case 1: cond_val = grf_load_byte(&buf); mask = 0x000000FF; break;
|
2005-04-01 10:43:20 +00:00
|
|
|
default: break;
|
|
|
|
}
|
2004-11-12 17:27:30 +00:00
|
|
|
|
2006-05-10 21:34:57 +00:00
|
|
|
if (param < 0x80 && _cur_grffile->param_end <= param) {
|
|
|
|
DEBUG(grf, 7) ("Param %d undefined, skipping test", param);
|
|
|
|
return;
|
|
|
|
}
|
2005-08-13 16:23:07 +00:00
|
|
|
|
2006-05-10 21:34:57 +00:00
|
|
|
if (param == 0x88 && GetFileByGRFID(cond_val) == NULL) {
|
|
|
|
DEBUG(grf, 7) ("GRFID 0x%08X unknown, skipping test", BSWAP32(cond_val));
|
|
|
|
return;
|
2004-11-12 15:36:49 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-05-10 21:34:57 +00:00
|
|
|
param_val = GetParamVal(param, &cond_val);
|
|
|
|
|
|
|
|
/* Apply parameter mask, only for GRF parameters. */
|
|
|
|
if (param < 0x80) param_val &= mask;
|
|
|
|
|
2006-04-22 13:56:16 +00:00
|
|
|
DEBUG(grf, 7) ("Test condtype %d, param 0x%08X, condval 0x%08X", condtype, param_val, cond_val);
|
2004-11-12 15:36:49 +00:00
|
|
|
switch (condtype) {
|
2005-03-30 12:27:50 +00:00
|
|
|
case 0: result = !!(param_val & (1 << cond_val));
|
2004-11-12 17:27:30 +00:00
|
|
|
break;
|
|
|
|
case 1: result = !(param_val & (1 << cond_val));
|
|
|
|
break;
|
|
|
|
/* TODO: For the following, make it to work with paramsize>1. */
|
|
|
|
case 2: result = (param_val == cond_val);
|
2004-11-12 15:36:49 +00:00
|
|
|
break;
|
2004-11-12 17:27:30 +00:00
|
|
|
case 3: result = (param_val != cond_val);
|
|
|
|
break;
|
|
|
|
case 4: result = (param_val < cond_val);
|
|
|
|
break;
|
|
|
|
case 5: result = (param_val > cond_val);
|
2004-11-12 15:36:49 +00:00
|
|
|
break;
|
2006-05-10 21:34:57 +00:00
|
|
|
/* Tests 6 to 10 are only for param 0x88, GRFID checks */
|
|
|
|
case 6: /* Is GRFID active? */
|
|
|
|
case 9: /* GRFID is or will be active? */
|
|
|
|
result = (GetFileByGRFID(cond_val)->flags & 1) == 1;
|
|
|
|
break;
|
|
|
|
case 7: /* Is GRFID non-active? */
|
|
|
|
case 10: /* GRFID is not nor will be active */
|
|
|
|
result = (GetFileByGRFID(cond_val)->flags & 1) == 0;
|
|
|
|
break;
|
|
|
|
case 8: /* GRFID is not but will be active? */
|
|
|
|
result = 0;
|
|
|
|
if ((GetFileByGRFID(cond_val)->flags & 1) == 1) {
|
|
|
|
const GRFFile *file;
|
|
|
|
for (file = _first_grffile; file != NULL; file = file->next) {
|
|
|
|
if (file->grfid == cond_val) break;
|
|
|
|
if (file == _cur_grffile) {
|
|
|
|
result = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-11-12 22:28:19 +00:00
|
|
|
break;
|
2004-11-12 15:36:49 +00:00
|
|
|
default:
|
|
|
|
grfmsg(GMS_WARN, "Unsupported test %d. Ignoring.", condtype);
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
2004-11-12 15:36:49 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-03-30 12:30:24 +00:00
|
|
|
if (!result) {
|
2004-11-12 17:27:30 +00:00
|
|
|
grfmsg(GMS_NOTICE, "Not skipping sprites, test was false.");
|
2004-11-12 15:36:49 +00:00
|
|
|
return;
|
2004-11-12 17:27:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
numsprites = grf_load_byte(&buf);
|
2006-04-15 21:27:59 +00:00
|
|
|
|
|
|
|
/* numsprites can be a GOTO label if it has been defined in the GRF
|
|
|
|
* file. The jump will always be the first matching label that follows
|
|
|
|
* the current nfo_line. If no matching label is found, the first matching
|
|
|
|
* label in the file is used. */
|
|
|
|
for (label = _cur_grffile->label; label != NULL; label = label->next) {
|
|
|
|
if (label->label != numsprites) continue;
|
|
|
|
|
|
|
|
/* Remember a goto before the current line */
|
|
|
|
if (choice == NULL) choice = label;
|
|
|
|
/* If we find a label here, this is definitely good */
|
|
|
|
if (label->nfo_line > _nfo_line) {
|
|
|
|
choice = label;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (choice != NULL) {
|
|
|
|
grfmsg(GMS_NOTICE, "Jumping to label 0x%0X at line %d, test was true.", choice->label, choice->nfo_line);
|
|
|
|
FioSeekTo(choice->pos, SEEK_SET);
|
|
|
|
_nfo_line = choice->nfo_line;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-08-15 11:39:13 +00:00
|
|
|
grfmsg(GMS_NOTICE, "Skipping %d sprites, test was true.", numsprites);
|
2004-11-12 15:36:49 +00:00
|
|
|
_skip_sprites = numsprites;
|
|
|
|
if (_skip_sprites == 0) {
|
|
|
|
/* Zero means there are no sprites to skip, so
|
|
|
|
* we use -1 to indicate that all further
|
|
|
|
* sprites should be skipped. */
|
|
|
|
_skip_sprites = -1;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-23 18:03:55 +00:00
|
|
|
/* Action 0x08 */
|
2004-08-09 17:04:08 +00:00
|
|
|
static void GRFInfo(byte *buf, int len)
|
|
|
|
{
|
|
|
|
/* <08> <version> <grf-id> <name> <info>
|
|
|
|
*
|
|
|
|
* B version newgrf version, currently 06
|
|
|
|
* 4*B grf-id globally unique ID of this .grf file
|
|
|
|
* S name name of this .grf set
|
|
|
|
* S info string describing the set, and e.g. author and copyright */
|
|
|
|
/* TODO: Check version. (We should have own versioning done somehow.) */
|
2004-11-12 15:36:49 +00:00
|
|
|
uint8 version;
|
2004-11-12 22:28:19 +00:00
|
|
|
uint32 grfid;
|
2005-02-06 22:25:27 +00:00
|
|
|
const char *name;
|
|
|
|
const char *info;
|
2004-11-12 15:36:49 +00:00
|
|
|
|
2006-05-01 21:45:35 +00:00
|
|
|
check_length(len, 8, "GRFInfo"); buf++;
|
2006-05-01 21:47:30 +00:00
|
|
|
version = grf_load_byte(&buf);
|
2006-05-01 21:45:35 +00:00
|
|
|
grfid = grf_load_dword(&buf);
|
|
|
|
name = (const char*)buf;
|
2004-11-12 15:36:49 +00:00
|
|
|
info = name + strlen(name) + 1;
|
2004-11-12 22:28:19 +00:00
|
|
|
|
|
|
|
_cur_grffile->grfid = grfid;
|
2006-04-23 18:03:55 +00:00
|
|
|
_cur_grffile->grf_version = version;
|
2004-11-12 22:28:19 +00:00
|
|
|
_cur_grffile->flags |= 0x0001; /* set active flag */
|
|
|
|
|
2006-05-01 21:45:35 +00:00
|
|
|
/* Do swap the GRFID for displaying purposes since people expect that */
|
2005-07-05 17:47:10 +00:00
|
|
|
DEBUG(grf, 1) ("[%s] Loaded GRFv%d set %08lx - %s:\n%s",
|
2006-05-01 21:45:35 +00:00
|
|
|
_cur_grffile->filename, version, BSWAP32(grfid), name, info);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-04-23 18:03:55 +00:00
|
|
|
/* Action 0x0A */
|
2004-08-09 17:04:08 +00:00
|
|
|
static void SpriteReplace(byte *buf, int len)
|
|
|
|
{
|
|
|
|
/* <0A> <num-sets> <set1> [<set2> ...]
|
|
|
|
* <set>: <num-sprites> <first-sprite>
|
|
|
|
*
|
|
|
|
* B num-sets How many sets of sprites to replace.
|
|
|
|
* Each set:
|
|
|
|
* B num-sprites How many sprites are in this set
|
|
|
|
* W first-sprite First sprite number to replace */
|
2004-11-12 18:47:19 +00:00
|
|
|
uint8 num_sets;
|
2005-08-15 11:39:13 +00:00
|
|
|
uint i;
|
2004-11-12 18:47:19 +00:00
|
|
|
|
|
|
|
buf++; /* skip action byte */
|
|
|
|
num_sets = grf_load_byte(&buf);
|
|
|
|
|
2005-08-15 11:39:13 +00:00
|
|
|
for (i = 0; i < num_sets; i++) {
|
|
|
|
uint8 num_sprites = grf_load_byte(&buf);
|
|
|
|
uint16 first_sprite = grf_load_word(&buf);
|
|
|
|
uint j;
|
2004-11-14 13:59:11 +00:00
|
|
|
|
2005-08-15 11:39:13 +00:00
|
|
|
grfmsg(GMS_NOTICE,
|
|
|
|
"SpriteReplace: [Set %d] Changing %d sprites, beginning with %d",
|
|
|
|
i, num_sprites, first_sprite
|
|
|
|
);
|
2004-11-12 18:47:19 +00:00
|
|
|
|
2005-08-15 11:39:13 +00:00
|
|
|
for (j = 0; j < num_sprites; j++) {
|
|
|
|
LoadNextSprite(first_sprite + j, _file_index); // XXX
|
2006-04-15 16:40:54 +00:00
|
|
|
_nfo_line++;
|
2004-11-12 18:47:19 +00:00
|
|
|
}
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-02 09:31:59 +00:00
|
|
|
/* Action 0x0B */
|
2004-08-09 17:04:08 +00:00
|
|
|
static void GRFError(byte *buf, int len)
|
|
|
|
{
|
|
|
|
/* <0B> <severity> <language-id> <message-id> [<message...> 00] [<data...>] 00 [<parnum>]
|
|
|
|
*
|
|
|
|
* B severity 00: notice, contine loading grf file
|
|
|
|
* 01: warning, continue loading grf file
|
|
|
|
* 02: error, but continue loading grf file, and attempt
|
|
|
|
* loading grf again when loading or starting next game
|
|
|
|
* 03: error, abort loading and prevent loading again in
|
|
|
|
* the future (only when restarting the patch)
|
|
|
|
* B language-id see action 4, use 1F for built-in error messages
|
|
|
|
* B message-id message to show, see below
|
|
|
|
* S message for custom messages (message-id FF), text of the message
|
|
|
|
* not present for built-in messages.
|
|
|
|
* V data additional data for built-in (or custom) messages
|
|
|
|
* B parnum see action 6, only used with built-in message 03 */
|
|
|
|
/* TODO: For now we just show the message, sometimes incomplete and never translated. */
|
|
|
|
|
|
|
|
static const char * const msgstr[4] = {
|
|
|
|
"Requires at least pseudo-TTDPatch version %s.",
|
|
|
|
"This file is for %s version of TTD.",
|
|
|
|
"Designed to be used with %s.",
|
|
|
|
"Invalid parameter %s.",
|
|
|
|
};
|
2004-11-12 15:36:49 +00:00
|
|
|
uint8 severity;
|
|
|
|
uint8 msgid;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-11-12 15:36:49 +00:00
|
|
|
check_length(len, 6, "GRFError");
|
|
|
|
severity = buf[1];
|
|
|
|
msgid = buf[3];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-11-17 02:01:12 +00:00
|
|
|
// Undocumented TTDPatch feature.
|
2006-04-19 07:50:16 +00:00
|
|
|
if ((severity & 0x80) == 0 && _cur_stage < 2) {
|
|
|
|
DEBUG(grf, 7) ("Skipping non-fatal GRFError in stage 1");
|
2004-11-17 02:01:12 +00:00
|
|
|
return;
|
2006-04-19 07:50:16 +00:00
|
|
|
}
|
2004-11-17 02:01:12 +00:00
|
|
|
severity &= 0x7F;
|
|
|
|
|
2004-11-12 18:43:12 +00:00
|
|
|
if (msgid == 0xFF) {
|
2004-11-12 15:36:49 +00:00
|
|
|
grfmsg(severity, "%s", buf+4);
|
|
|
|
} else {
|
|
|
|
grfmsg(severity, msgstr[msgid], buf+4);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-02 09:31:59 +00:00
|
|
|
/* Action 0x0C */
|
2004-08-09 17:04:08 +00:00
|
|
|
static void GRFComment(byte *buf, int len)
|
|
|
|
{
|
|
|
|
/* <0C> [<ignored...>]
|
|
|
|
*
|
|
|
|
* V ignored Anything following the 0C is ignored */
|
2006-04-15 21:27:59 +00:00
|
|
|
|
|
|
|
static char comment[256];
|
|
|
|
if (len == 1) return;
|
|
|
|
|
2006-04-16 20:24:10 +00:00
|
|
|
ttd_strlcpy(comment, (char*)(buf + 1), minu(sizeof(comment), len));
|
2006-04-15 21:27:59 +00:00
|
|
|
grfmsg(GMS_NOTICE, "GRFComment: %s", comment);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2004-11-12 15:15:56 +00:00
|
|
|
/* Action 0x0D */
|
2004-08-09 17:04:08 +00:00
|
|
|
static void ParamSet(byte *buf, int len)
|
|
|
|
{
|
|
|
|
/* <0D> <target> <operation> <source1> <source2> [<data>]
|
|
|
|
*
|
|
|
|
* B target parameter number where result is stored
|
|
|
|
* B operation operation to perform, see below
|
|
|
|
* B source1 first source operand
|
|
|
|
* B source2 second source operand
|
|
|
|
* D data data to use in the calculation, not necessary
|
|
|
|
* if both source1 and source2 refer to actual parameters
|
|
|
|
*
|
|
|
|
* Operations
|
|
|
|
* 00 Set parameter equal to source1
|
|
|
|
* 01 Addition, source1 + source2
|
|
|
|
* 02 Subtraction, source1 - source2
|
|
|
|
* 03 Unsigned multiplication, source1 * source2 (both unsigned)
|
|
|
|
* 04 Signed multiplication, source1 * source2 (both signed)
|
|
|
|
* 05 Unsigned bit shift, source1 by source2 (source2 taken to be a
|
|
|
|
* signed quantity; left shift if positive and right shift if
|
|
|
|
* negative, source1 is unsigned)
|
|
|
|
* 06 Signed bit shift, source1 by source2
|
|
|
|
* (source2 like in 05, and source1 as well)
|
|
|
|
*/
|
2004-11-12 18:57:46 +00:00
|
|
|
|
|
|
|
byte target;
|
|
|
|
byte oper;
|
2005-08-15 21:19:28 +00:00
|
|
|
uint32 src1;
|
|
|
|
uint32 src2;
|
|
|
|
uint32 data = 0;
|
|
|
|
uint32 res;
|
2004-11-12 18:57:46 +00:00
|
|
|
|
|
|
|
check_length(len, 5, "ParamSet");
|
2004-11-14 22:31:57 +00:00
|
|
|
buf++;
|
2004-11-12 18:57:46 +00:00
|
|
|
target = grf_load_byte(&buf);
|
|
|
|
oper = grf_load_byte(&buf);
|
|
|
|
src1 = grf_load_byte(&buf);
|
|
|
|
src2 = grf_load_byte(&buf);
|
|
|
|
|
2005-08-15 21:19:28 +00:00
|
|
|
if (len >= 8) data = grf_load_dword(&buf);
|
2004-11-14 13:59:11 +00:00
|
|
|
|
2004-11-12 18:57:46 +00:00
|
|
|
/* You can add 80 to the operation to make it apply only if the target
|
|
|
|
* is not defined yet. In this respect, a parameter is taken to be
|
|
|
|
* defined if any of the following applies:
|
|
|
|
* - it has been set to any value in the newgrf(w).cfg parameter list
|
|
|
|
* - it OR A PARAMETER WITH HIGHER NUMBER has been set to any value by
|
|
|
|
* an earlier action D */
|
|
|
|
if (oper & 0x80) {
|
2006-05-10 21:41:16 +00:00
|
|
|
if (target < 0x80 && target < _cur_grffile->param_end) {
|
|
|
|
DEBUG(grf, 7) ("Param %u already defined, skipping.", target);
|
2004-11-12 18:57:46 +00:00
|
|
|
return;
|
2006-05-10 21:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
oper &= 0x7F;
|
2004-11-12 18:57:46 +00:00
|
|
|
}
|
|
|
|
|
2006-05-10 21:55:44 +00:00
|
|
|
if (src2 == 0xFE) {
|
|
|
|
if (GB(data, 0, 8) == 0xFF) {
|
|
|
|
if (data == 0x0000FFFF) {
|
|
|
|
/* Patch variables */
|
2006-05-11 09:54:11 +00:00
|
|
|
grfmsg(GMS_WARN, "ParamSet: Reading Patch variables unsupported.");
|
2006-05-10 21:55:44 +00:00
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
/* GRF Resource Management */
|
|
|
|
grfmsg(GMS_WARN, "ParamSet: GRF Resource Management unsupported.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Read another GRF File's parameter */
|
|
|
|
const GRFFile *file = GetFileByGRFID(data);
|
|
|
|
if (file == NULL || src1 >= file->param_end) {
|
|
|
|
src1 = 0;
|
|
|
|
} else {
|
|
|
|
src1 = file->param[src1];
|
|
|
|
}
|
|
|
|
}
|
2004-11-12 18:57:46 +00:00
|
|
|
} else {
|
2006-05-10 21:55:44 +00:00
|
|
|
/* The source1 and source2 operands refer to the grf parameter number
|
|
|
|
* like in action 6 and 7. In addition, they can refer to the special
|
|
|
|
* variables available in action 7, or they can be FF to use the value
|
|
|
|
* of <data>. If referring to parameters that are undefined, a value
|
|
|
|
* of 0 is used instead. */
|
2006-05-11 09:54:11 +00:00
|
|
|
src1 = (src1 == 0xFF) ? data : GetParamVal(src1, NULL);
|
|
|
|
src2 = (src2 == 0xFF) ? data : GetParamVal(src2, NULL);
|
2004-11-12 18:57:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: You can access the parameters of another GRF file by using
|
|
|
|
* source2=FE, source1=the other GRF's parameter number and data=GRF
|
|
|
|
* ID. This is only valid with operation 00 (set). If the GRF ID
|
|
|
|
* cannot be found, a value of 0 is used for the parameter value
|
|
|
|
* instead. */
|
|
|
|
|
|
|
|
switch (oper) {
|
|
|
|
case 0x00:
|
2005-08-15 21:19:28 +00:00
|
|
|
res = src1;
|
2004-11-12 18:57:46 +00:00
|
|
|
break;
|
2005-08-15 21:19:28 +00:00
|
|
|
|
2004-11-12 18:57:46 +00:00
|
|
|
case 0x01:
|
2005-08-15 21:19:28 +00:00
|
|
|
res = src1 + src2;
|
2004-11-12 18:57:46 +00:00
|
|
|
break;
|
2005-08-15 21:19:28 +00:00
|
|
|
|
2004-11-12 18:57:46 +00:00
|
|
|
case 0x02:
|
2005-08-15 21:19:28 +00:00
|
|
|
res = src1 - src2;
|
2004-11-12 18:57:46 +00:00
|
|
|
break;
|
2005-08-15 21:19:28 +00:00
|
|
|
|
2004-11-12 18:57:46 +00:00
|
|
|
case 0x03:
|
2005-08-15 21:19:28 +00:00
|
|
|
res = src1 * src2;
|
2004-11-12 18:57:46 +00:00
|
|
|
break;
|
2005-08-15 21:19:28 +00:00
|
|
|
|
2004-11-12 18:57:46 +00:00
|
|
|
case 0x04:
|
2005-08-15 21:19:28 +00:00
|
|
|
res = (int32)src1 * (int32)src2;
|
2004-11-12 18:57:46 +00:00
|
|
|
break;
|
2005-08-15 21:19:28 +00:00
|
|
|
|
2004-11-12 18:57:46 +00:00
|
|
|
case 0x05:
|
2005-08-15 21:19:28 +00:00
|
|
|
if ((int32)src2 < 0)
|
|
|
|
res = src1 >> -(int32)src2;
|
2004-11-12 18:57:46 +00:00
|
|
|
else
|
2005-08-15 21:19:28 +00:00
|
|
|
res = src1 << src2;
|
2004-11-12 18:57:46 +00:00
|
|
|
break;
|
2005-08-15 21:19:28 +00:00
|
|
|
|
2004-11-12 18:57:46 +00:00
|
|
|
case 0x06:
|
2005-08-15 21:19:28 +00:00
|
|
|
if ((int32)src2 < 0)
|
|
|
|
res = (int32)src1 >> -(int32)src2;
|
2004-11-12 18:57:46 +00:00
|
|
|
else
|
2005-08-15 21:19:28 +00:00
|
|
|
res = (int32)src1 << src2;
|
2004-11-12 18:57:46 +00:00
|
|
|
break;
|
2005-08-15 21:19:28 +00:00
|
|
|
|
2005-09-21 19:07:58 +00:00
|
|
|
case 0x07: /* Bitwise AND */
|
|
|
|
res = src1 & src2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x08: /* Bitwise OR */
|
|
|
|
res = src1 | src2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x09: /* Unsigned division */
|
|
|
|
if (src2 == 0) {
|
|
|
|
res = src1;
|
|
|
|
} else {
|
|
|
|
res = src1 / src2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x0A: /* Signed divison */
|
|
|
|
if (src2 == 0) {
|
|
|
|
res = src1;
|
|
|
|
} else {
|
|
|
|
res = (int32)src1 / (int32)src2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x0B: /* Unsigned modulo */
|
|
|
|
if (src2 == 0) {
|
|
|
|
res = src1;
|
|
|
|
} else {
|
|
|
|
res = src1 % src2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x0C: /* Signed modulo */
|
|
|
|
if (src2 == 0) {
|
|
|
|
res = src1;
|
|
|
|
} else {
|
|
|
|
res = (int32)src1 % (int32)src2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2004-11-12 18:57:46 +00:00
|
|
|
default:
|
|
|
|
grfmsg(GMS_ERROR, "ParamSet: Unknown operation %d, skipping.", oper);
|
2005-08-15 21:19:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (target) {
|
|
|
|
case 0x8E: // Y-Offset for train sprites
|
|
|
|
_traininfo_vehicle_pitch = res;
|
|
|
|
break;
|
|
|
|
|
|
|
|
// TODO implement
|
|
|
|
case 0x8F: // Rail track type cost factors
|
|
|
|
case 0x93: // Tile refresh offset to left
|
|
|
|
case 0x94: // Tile refresh offset to right
|
|
|
|
case 0x95: // Tile refresh offset upwards
|
|
|
|
case 0x96: // Tile refresh offset downwards
|
|
|
|
case 0x97: // Snow line height
|
|
|
|
case 0x99: // Global ID offset
|
|
|
|
DEBUG(grf, 7) ("ParamSet: Skipping unimplemented target 0x%02X", target);
|
|
|
|
break;
|
|
|
|
|
2006-05-11 12:41:02 +00:00
|
|
|
case 0x9E: /* Miscellaneous GRF features */
|
|
|
|
_misc_grf_features = res;
|
2006-05-14 20:58:12 +00:00
|
|
|
/* Set train list engine width */
|
|
|
|
_traininfo_vehicle_width = HASBIT(res, 3) ? 32 : 29;
|
2006-05-11 12:41:02 +00:00
|
|
|
break;
|
|
|
|
|
2005-08-15 21:19:28 +00:00
|
|
|
default:
|
|
|
|
if (target < 0x80) {
|
|
|
|
_cur_grffile->param[target] = res;
|
|
|
|
if (target + 1U > _cur_grffile->param_end) _cur_grffile->param_end = target + 1;
|
|
|
|
} else {
|
|
|
|
DEBUG(grf, 7) ("ParamSet: Skipping unknown target 0x%02X", target);
|
|
|
|
}
|
|
|
|
break;
|
2004-11-12 18:57:46 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-02 09:31:59 +00:00
|
|
|
/* Action 0x0E */
|
2004-08-09 17:04:08 +00:00
|
|
|
static void GRFInhibit(byte *buf, int len)
|
|
|
|
{
|
|
|
|
/* <0E> <num> <grfids...>
|
|
|
|
*
|
|
|
|
* B num Number of GRFIDs that follow
|
|
|
|
* D grfids GRFIDs of the files to deactivate */
|
2004-11-12 22:39:00 +00:00
|
|
|
|
|
|
|
byte num;
|
|
|
|
int i;
|
2004-11-14 13:59:11 +00:00
|
|
|
|
2004-11-12 22:39:00 +00:00
|
|
|
check_length(len, 1, "GRFInhibit");
|
2004-11-14 22:25:21 +00:00
|
|
|
buf++, len--;
|
2004-11-12 22:39:00 +00:00
|
|
|
num = grf_load_byte(&buf); len--;
|
|
|
|
check_length(len, 4 * num, "GRFInhibit");
|
|
|
|
|
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
uint32 grfid = grf_load_dword(&buf);
|
2005-03-10 07:01:43 +00:00
|
|
|
GRFFile *file = GetFileByGRFID(grfid);
|
2004-11-12 22:39:00 +00:00
|
|
|
|
|
|
|
/* Unset activation flag */
|
|
|
|
if (file != NULL) {
|
|
|
|
grfmsg(GMS_NOTICE, "GRFInhibit: Deactivating file ``%s''", file->filename);
|
|
|
|
file->flags &= 0xFFFE;
|
|
|
|
}
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-02 09:31:59 +00:00
|
|
|
/* Action 0x10 */
|
2006-04-15 21:27:59 +00:00
|
|
|
static void DefineGotoLabel(byte *buf, int len)
|
|
|
|
{
|
|
|
|
/* <10> <label> [<comment>]
|
|
|
|
*
|
|
|
|
* B label The label to define
|
|
|
|
* V comment Optional comment - ignored */
|
|
|
|
|
|
|
|
GRFLabel *label;
|
|
|
|
|
2006-04-16 11:33:26 +00:00
|
|
|
check_length(len, 1, "DefineGotoLabel");
|
2006-04-15 21:27:59 +00:00
|
|
|
buf++; len--;
|
|
|
|
|
|
|
|
label = malloc(sizeof(*label));
|
|
|
|
label->label = grf_load_byte(&buf);
|
|
|
|
label->nfo_line = _nfo_line;
|
|
|
|
label->pos = FioGetPos();
|
|
|
|
label->next = NULL;
|
|
|
|
|
|
|
|
/* Set up a linked list of goto targets which we will search in an Action 0x7/0x9 */
|
|
|
|
if (_cur_grffile->label == NULL) {
|
|
|
|
_cur_grffile->label = label;
|
|
|
|
} else {
|
|
|
|
/* Attach the label to the end of the list */
|
|
|
|
GRFLabel *l;
|
|
|
|
for (l = _cur_grffile->label; l->next != NULL; l = l->next);
|
|
|
|
l->next = label;
|
|
|
|
}
|
|
|
|
|
2006-04-22 13:56:16 +00:00
|
|
|
grfmsg(GMS_NOTICE, "DefineGotoLabel: GOTO target with label 0x%02X", label->label);
|
2006-04-15 21:27:59 +00:00
|
|
|
}
|
2004-11-12 19:03:37 +00:00
|
|
|
|
|
|
|
static void InitializeGRFSpecial(void)
|
|
|
|
{
|
|
|
|
/* FIXME: We should rather reflect reality in _ttdpatch_flags[]. */
|
|
|
|
|
2005-11-12 09:30:52 +00:00
|
|
|
_ttdpatch_flags[0] = (_patches.always_small_airport ? (1 << 0x0C) : 0) /* keepsmallairport */
|
|
|
|
| (1 << 0x0E) /* largestations */
|
|
|
|
| (_patches.longbridges ? (1 << 0x0F) : 0) /* longbridges */
|
|
|
|
| (1 << 0x12) /* presignals */
|
|
|
|
| (1 << 0x13) /* extpresignals */
|
|
|
|
| (_patches.never_expire_vehicles ? (1 << 0x16) : 0) /* enginespersist */
|
|
|
|
| (1 << 0x1B); /* multihead */
|
|
|
|
_ttdpatch_flags[1] = (_patches.mammoth_trains ? (1 << 0x08) : 0) /* mammothtrains */
|
|
|
|
| (1 << 0x09) /* trainrefit */
|
2004-11-17 02:01:12 +00:00
|
|
|
| (1 << 0x14) /* bridgespeedlimits */
|
|
|
|
| (1 << 0x16) /* eternalgame */
|
|
|
|
| (1 << 0x17) /* newtrains */
|
|
|
|
| (1 << 0x18) /* newrvs */
|
|
|
|
| (1 << 0x19) /* newships */
|
|
|
|
| (1 << 0x1A) /* newplanes */
|
2006-03-29 16:30:26 +00:00
|
|
|
| (_patches.signal_side ? (1 << 0x1B) : 0) /* signalsontrafficside */
|
|
|
|
| (1 << 0x1C); /* electrifiedrailway */
|
2004-11-17 02:01:12 +00:00
|
|
|
|
2005-11-12 09:30:52 +00:00
|
|
|
_ttdpatch_flags[2] = (_patches.build_on_slopes ? (1 << 0x0D) : 0) /* buildonslopes */
|
2006-05-07 11:41:44 +00:00
|
|
|
| (1 << 0x12) /* newstations */
|
2005-11-12 09:30:52 +00:00
|
|
|
| (_patches.build_on_slopes ? (1 << 0x15) : 0) /* buildoncoasts */
|
2004-11-17 02:01:12 +00:00
|
|
|
| (1 << 0x16) /* canals */
|
2005-09-24 13:56:39 +00:00
|
|
|
| (1 << 0x17) /* newstartyear */
|
2005-11-12 09:30:52 +00:00
|
|
|
| (1 << 0x1A) /* newbridges */
|
|
|
|
| (_patches.wagon_speed_limits ? (1 << 0x1D) : 0); /* wagonspeedlimits */
|
|
|
|
_ttdpatch_flags[3] = (1 << 0x03) /* pathbasedsignalling */
|
|
|
|
| (1 << 0x0C) /* enhancemultiplayer */
|
|
|
|
| (1 << 0x0E) /* irregularstations */
|
|
|
|
| (1 << 0x10); /* autoreplace */
|
2004-11-12 19:03:37 +00:00
|
|
|
}
|
|
|
|
|
2005-11-12 00:19:34 +00:00
|
|
|
static void ResetCustomStations(void)
|
|
|
|
{
|
2006-05-03 21:07:44 +00:00
|
|
|
StationSpec *statspec;
|
2005-11-12 00:19:34 +00:00
|
|
|
GRFFile *file;
|
2005-11-12 08:51:46 +00:00
|
|
|
uint i;
|
2006-05-03 21:07:44 +00:00
|
|
|
uint t;
|
2005-11-12 00:19:34 +00:00
|
|
|
|
|
|
|
for (file = _first_grffile; file != NULL; file = file->next) {
|
2006-05-06 22:20:16 +00:00
|
|
|
if (file->stations == NULL) continue;
|
|
|
|
for (i = 0; i < MAX_STATIONS; i++) {
|
|
|
|
if (file->stations[i] == NULL) continue;
|
|
|
|
statspec = file->stations[i];
|
2006-05-03 21:07:44 +00:00
|
|
|
|
|
|
|
/* Release renderdata, if it wasn't copied from another custom station spec */
|
|
|
|
if (!statspec->copied_renderdata) {
|
|
|
|
for (t = 0; t < statspec->tiles; t++) {
|
|
|
|
free((void*)statspec->renderdata[t].seq);
|
|
|
|
}
|
|
|
|
free(statspec->renderdata);
|
|
|
|
}
|
2005-11-12 00:19:34 +00:00
|
|
|
|
2006-05-03 21:07:44 +00:00
|
|
|
// TODO: Release platforms and layouts
|
2006-05-06 22:20:16 +00:00
|
|
|
|
|
|
|
/* Release this station */
|
|
|
|
free(statspec);
|
2005-11-12 00:19:34 +00:00
|
|
|
}
|
2006-04-11 10:05:52 +00:00
|
|
|
|
|
|
|
/* Free and reset the station data */
|
|
|
|
free(file->stations);
|
|
|
|
file->stations = NULL;
|
2005-11-12 00:19:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-26 18:43:58 +00:00
|
|
|
/**
|
|
|
|
* Reset all NewGRF loaded data
|
|
|
|
* TODO
|
|
|
|
*/
|
|
|
|
static void ResetNewGRFData(void)
|
|
|
|
{
|
2006-02-18 14:41:24 +00:00
|
|
|
uint i;
|
2005-10-01 17:38:48 +00:00
|
|
|
|
2006-04-21 03:00:20 +00:00
|
|
|
CleanUpStrings();
|
|
|
|
|
2005-09-26 18:43:58 +00:00
|
|
|
// Copy/reset original engine info data
|
|
|
|
memcpy(&_engine_info, &orig_engine_info, sizeof(orig_engine_info));
|
|
|
|
memcpy(&_rail_vehicle_info, &orig_rail_vehicle_info, sizeof(orig_rail_vehicle_info));
|
|
|
|
memcpy(&_ship_vehicle_info, &orig_ship_vehicle_info, sizeof(orig_ship_vehicle_info));
|
|
|
|
memcpy(&_aircraft_vehicle_info, &orig_aircraft_vehicle_info, sizeof(orig_aircraft_vehicle_info));
|
|
|
|
memcpy(&_road_vehicle_info, &orig_road_vehicle_info, sizeof(orig_road_vehicle_info));
|
2005-10-01 17:38:48 +00:00
|
|
|
|
|
|
|
// Copy/reset original bridge info data
|
|
|
|
// First, free sprite table data
|
|
|
|
for (i = 0; i < MAX_BRIDGES; i++) {
|
|
|
|
if (_bridge[i].sprite_table != NULL) {
|
2006-02-18 14:41:24 +00:00
|
|
|
uint j;
|
|
|
|
|
|
|
|
for (j = 0; j < 7; j++) free(_bridge[i].sprite_table[j]);
|
2005-10-01 17:38:48 +00:00
|
|
|
free(_bridge[i].sprite_table);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
memcpy(&_bridge, &orig_bridge, sizeof(_bridge));
|
2005-10-04 21:42:00 +00:00
|
|
|
|
2005-11-06 13:42:26 +00:00
|
|
|
// Reset refit/cargo class data
|
|
|
|
memset(&cargo_allowed, 0, sizeof(cargo_allowed));
|
|
|
|
memset(&cargo_disallowed, 0, sizeof(cargo_disallowed));
|
|
|
|
|
2005-10-04 21:42:00 +00:00
|
|
|
// Unload sprite group data
|
|
|
|
UnloadWagonOverrides();
|
2006-04-30 18:41:16 +00:00
|
|
|
UnloadRotorOverrideSprites();
|
2005-10-04 21:42:00 +00:00
|
|
|
UnloadCustomEngineSprites();
|
2005-12-18 14:03:28 +00:00
|
|
|
UnloadCustomEngineNames();
|
2006-02-04 21:48:46 +00:00
|
|
|
ResetEngineListOrder();
|
2005-10-12 07:27:56 +00:00
|
|
|
|
|
|
|
// Reset price base data
|
|
|
|
ResetPriceBaseMultipliers();
|
2005-11-12 00:19:34 +00:00
|
|
|
|
|
|
|
// Reset station classes
|
|
|
|
ResetStationClasses();
|
|
|
|
ResetCustomStations();
|
2006-01-02 22:40:39 +00:00
|
|
|
|
|
|
|
// Add engine type to engine data. This is needed for the refit precalculation.
|
|
|
|
AddTypeToEngines();
|
2006-04-20 20:51:57 +00:00
|
|
|
|
2006-05-14 20:58:12 +00:00
|
|
|
/* Reset misc GRF features and train list display variables */
|
|
|
|
_misc_grf_features = 0;
|
|
|
|
_traininfo_vehicle_pitch = 0;
|
|
|
|
_traininfo_vehicle_width = 29;
|
|
|
|
|
2006-04-20 20:51:57 +00:00
|
|
|
InitializeSpriteGroupPool();
|
2005-09-26 18:43:58 +00:00
|
|
|
}
|
|
|
|
|
2006-04-15 21:27:59 +00:00
|
|
|
/** Reset all NewGRFData that was used only while processing data */
|
|
|
|
static void ClearTemporaryNewGRFData(void)
|
|
|
|
{
|
|
|
|
/* Clear the GOTO labels used for GRF processing */
|
|
|
|
GRFLabel *l;
|
|
|
|
for (l = _cur_grffile->label; l != NULL;) {
|
|
|
|
GRFLabel *l2 = l->next;
|
|
|
|
free(l);
|
|
|
|
l = l2;
|
|
|
|
}
|
|
|
|
_cur_grffile->label = NULL;
|
2006-04-20 20:51:57 +00:00
|
|
|
|
|
|
|
/* Clear the list of spritegroups */
|
|
|
|
free(_cur_grffile->spritegroups);
|
|
|
|
_cur_grffile->spritegroups = NULL;
|
|
|
|
_cur_grffile->spritegroups_count = 0;
|
2006-04-15 21:27:59 +00:00
|
|
|
}
|
|
|
|
|
2006-04-22 13:17:13 +00:00
|
|
|
static void InitNewGRFFile(const GRFConfig *config, int sprite_offset)
|
2004-11-12 23:26:02 +00:00
|
|
|
{
|
2005-03-10 07:01:43 +00:00
|
|
|
GRFFile *newfile;
|
2004-11-12 22:28:19 +00:00
|
|
|
|
2006-04-22 13:17:13 +00:00
|
|
|
newfile = GetFileByFilename(config->filename);
|
2004-11-22 22:52:01 +00:00
|
|
|
if (newfile != NULL) {
|
2004-11-22 22:51:19 +00:00
|
|
|
/* We already loaded it once. */
|
|
|
|
newfile->sprite_offset = sprite_offset;
|
|
|
|
_cur_grffile = newfile;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-03-10 07:01:43 +00:00
|
|
|
newfile = calloc(1, sizeof(*newfile));
|
2004-11-12 22:28:19 +00:00
|
|
|
|
2006-02-18 14:41:24 +00:00
|
|
|
if (newfile == NULL) error ("Out of memory");
|
2004-11-12 22:28:19 +00:00
|
|
|
|
2006-04-22 13:17:13 +00:00
|
|
|
newfile->filename = strdup(config->filename);
|
2004-11-12 22:28:19 +00:00
|
|
|
newfile->sprite_offset = sprite_offset;
|
|
|
|
|
2006-04-22 13:17:13 +00:00
|
|
|
/* Copy the initial parameter list */
|
|
|
|
assert(lengthof(newfile->param) == lengthof(config->param) && lengthof(config->param) == 0x80);
|
|
|
|
newfile->param_end = config->num_params;
|
|
|
|
memcpy(newfile->param, config->param, 0x80 * sizeof(newfile->param[0]));
|
|
|
|
|
2004-11-12 22:28:19 +00:00
|
|
|
if (_first_grffile == NULL) {
|
|
|
|
_cur_grffile = newfile;
|
|
|
|
_first_grffile = newfile;
|
|
|
|
} else {
|
|
|
|
_cur_grffile->next = newfile;
|
|
|
|
_cur_grffile = newfile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-06 13:42:26 +00:00
|
|
|
/**
|
|
|
|
* Precalculate refit masks from cargo classes for all vehicles.
|
|
|
|
*/
|
|
|
|
static void CalculateRefitMasks(void)
|
|
|
|
{
|
|
|
|
EngineID engine;
|
|
|
|
|
|
|
|
for (engine = 0; engine < TOTAL_NUM_ENGINES; engine++) {
|
|
|
|
uint32 mask = 0;
|
|
|
|
uint32 not_mask = 0;
|
|
|
|
uint32 xor_mask = _engine_info[engine].refit_mask;
|
|
|
|
byte i;
|
|
|
|
|
|
|
|
if (cargo_allowed[engine] != 0) {
|
|
|
|
// Build up the list of cargo types from the set cargo classes.
|
|
|
|
for (i = 0; i < lengthof(cargo_classes); i++) {
|
2006-02-18 14:41:24 +00:00
|
|
|
if (HASBIT(cargo_allowed[engine], i)) mask |= cargo_classes[i];
|
|
|
|
if (HASBIT(cargo_disallowed[engine], i)) not_mask |= cargo_classes[i];
|
2005-11-06 13:42:26 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Don't apply default refit mask to wagons or engines with no capacity
|
2006-02-18 14:41:24 +00:00
|
|
|
if (xor_mask == 0 && (
|
|
|
|
GetEngine(engine)->type != VEH_Train || (
|
|
|
|
RailVehInfo(engine)->capacity != 0 &&
|
|
|
|
!(RailVehInfo(engine)->flags & RVI_WAGON)
|
|
|
|
)
|
|
|
|
)) {
|
2005-11-06 13:42:26 +00:00
|
|
|
xor_mask = _default_refitmasks[GetEngine(engine)->type - VEH_Train];
|
2006-02-18 14:41:24 +00:00
|
|
|
}
|
2005-11-06 13:42:26 +00:00
|
|
|
}
|
|
|
|
_engine_info[engine].refit_mask = ((mask & ~not_mask) ^ xor_mask) & _landscape_global_cargo_mask[_opt.landscape];
|
|
|
|
}
|
|
|
|
}
|
2004-11-12 19:03:37 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
/* Here we perform initial decoding of some special sprites (as are they
|
|
|
|
* described at http://www.ttdpatch.net/src/newgrf.txt, but this is only a very
|
2004-11-12 23:26:02 +00:00
|
|
|
* partial implementation yet). */
|
2004-08-09 17:04:08 +00:00
|
|
|
/* XXX: We consider GRF files trusted. It would be trivial to exploit OTTD by
|
|
|
|
* a crafted invalid GRF file. We should tell that to the user somehow, or
|
|
|
|
* better make this more robust in the future. */
|
2006-02-02 07:15:46 +00:00
|
|
|
static void DecodeSpecialSprite(uint num, uint stage)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-08-15 11:39:13 +00:00
|
|
|
/* XXX: There is a difference between staged loading in TTDPatch and
|
|
|
|
* here. In TTDPatch, for some reason actions 1 and 2 are carried out
|
2006-04-15 21:27:59 +00:00
|
|
|
* during stage 1, whilst action 3 is carried out during stage 2 (to
|
2005-08-15 11:39:13 +00:00
|
|
|
* "resolve" cargo IDs... wtf). This is a little problem, because cargo
|
|
|
|
* IDs are valid only within a given set (action 1) block, and may be
|
|
|
|
* overwritten after action 3 associates them. But overwriting happens
|
|
|
|
* in an earlier stage than associating, so... We just process actions
|
2006-04-15 21:27:59 +00:00
|
|
|
* 1 and 2 in stage 2 now, let's hope that won't get us into problems.
|
2005-08-15 11:39:13 +00:00
|
|
|
* --pasky */
|
2006-04-15 21:27:59 +00:00
|
|
|
/* We need a pre-stage to set up GOTO labels of Action 0x10 because the grf
|
|
|
|
* is not in memory and scanning the file every time would be too expensive.
|
|
|
|
* In other stages we skip action 0x10 since it's already dealt with. */
|
|
|
|
static const uint32 action_mask[] = {0x10000, 0x0000FB40, 0x0000FFBF};
|
|
|
|
|
2005-08-15 11:39:13 +00:00
|
|
|
static const SpecialSpriteHandler handlers[] = {
|
|
|
|
/* 0x00 */ VehicleChangeInfo,
|
|
|
|
/* 0x01 */ NewSpriteSet,
|
|
|
|
/* 0x02 */ NewSpriteGroup,
|
|
|
|
/* 0x03 */ NewVehicle_SpriteGroupMapping,
|
|
|
|
/* 0x04 */ VehicleNewName,
|
|
|
|
/* 0x05 */ GraphicsNew,
|
|
|
|
/* 0x06 */ CfgApply,
|
|
|
|
/* 0x07 */ SkipIf,
|
|
|
|
/* 0x08 */ GRFInfo,
|
|
|
|
/* 0x09 */ SkipIf,
|
|
|
|
/* 0x0A */ SpriteReplace,
|
|
|
|
/* 0x0B */ GRFError,
|
|
|
|
/* 0x0C */ GRFComment,
|
|
|
|
/* 0x0D */ ParamSet,
|
|
|
|
/* 0x0E */ GRFInhibit,
|
|
|
|
/* 0x0F */ NULL, // TODO implement
|
2006-04-15 21:27:59 +00:00
|
|
|
/* 0x10 */ DefineGotoLabel,
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
2005-08-15 11:39:13 +00:00
|
|
|
|
|
|
|
byte* buf = malloc(num);
|
2004-08-09 17:04:08 +00:00
|
|
|
byte action;
|
|
|
|
|
2004-11-12 15:15:56 +00:00
|
|
|
if (buf == NULL) error("DecodeSpecialSprite: Could not allocate memory");
|
|
|
|
|
2005-08-15 11:39:13 +00:00
|
|
|
FioReadBlock(buf, num);
|
|
|
|
action = buf[0];
|
|
|
|
|
|
|
|
if (action >= lengthof(handlers)) {
|
|
|
|
DEBUG(grf, 7) ("Skipping unknown action 0x%02X", action);
|
2006-04-15 21:27:59 +00:00
|
|
|
} else if (!HASBIT(action_mask[stage], action)) {
|
2005-08-15 11:39:13 +00:00
|
|
|
DEBUG(grf, 7) ("Skipping action 0x%02X in stage %d", action, stage);
|
2005-11-15 09:47:25 +00:00
|
|
|
} else if (handlers[action] == NULL) {
|
2005-08-15 11:39:13 +00:00
|
|
|
DEBUG(grf, 7) ("Skipping unsupported Action 0x%02X", action);
|
2005-11-15 09:47:25 +00:00
|
|
|
} else {
|
|
|
|
DEBUG(grf, 7) ("Handling action 0x%02X in stage %d", action, stage);
|
|
|
|
handlers[action](buf, num);
|
2005-08-15 11:39:13 +00:00
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
}
|
2004-11-12 23:26:02 +00:00
|
|
|
|
|
|
|
|
2005-08-15 11:39:13 +00:00
|
|
|
static void LoadNewGRFFile(const char* filename, uint file_index, uint stage)
|
|
|
|
{
|
|
|
|
uint16 num;
|
|
|
|
|
|
|
|
/* A .grf file is activated only if it was active when the game was
|
|
|
|
* started. If a game is loaded, only its active .grfs will be
|
|
|
|
* reactivated, unless "loadallgraphics on" is used. A .grf file is
|
|
|
|
* considered active if its action 8 has been processed, i.e. its
|
|
|
|
* action 8 hasn't been skipped using an action 7.
|
|
|
|
*
|
|
|
|
* During activation, only actions 0, 1, 2, 3, 4, 5, 7, 8, 9, 0A and 0B are
|
|
|
|
* carried out. All others are ignored, because they only need to be
|
|
|
|
* processed once at initialization. */
|
|
|
|
if (stage != 0) {
|
|
|
|
_cur_grffile = GetFileByFilename(filename);
|
|
|
|
if (_cur_grffile == NULL) error("File ``%s'' lost in cache.\n", filename);
|
2006-04-15 21:27:59 +00:00
|
|
|
if (stage > 1 && !(_cur_grffile->flags & 0x0001)) return;
|
2005-08-15 11:39:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FioOpenFile(file_index, filename);
|
|
|
|
_file_index = file_index; // XXX
|
|
|
|
|
|
|
|
DEBUG(grf, 7) ("Reading NewGRF-file '%s'", filename);
|
|
|
|
|
|
|
|
/* Skip the first sprite; we don't care about how many sprites this
|
|
|
|
* does contain; newest TTDPatches and George's longvehicles don't
|
|
|
|
* neither, apparently. */
|
|
|
|
if (FioReadWord() == 4 && FioReadByte() == 0xFF) {
|
|
|
|
FioReadDword();
|
|
|
|
} else {
|
|
|
|
error("Custom .grf has invalid format.");
|
|
|
|
}
|
|
|
|
|
|
|
|
_skip_sprites = 0; // XXX
|
2006-04-15 16:40:54 +00:00
|
|
|
_nfo_line = 0;
|
2005-08-15 11:39:13 +00:00
|
|
|
|
|
|
|
while ((num = FioReadWord()) != 0) {
|
|
|
|
byte type = FioReadByte();
|
2006-04-15 16:40:54 +00:00
|
|
|
_nfo_line++;
|
2005-08-15 11:39:13 +00:00
|
|
|
|
|
|
|
if (type == 0xFF) {
|
|
|
|
if (_skip_sprites == 0) {
|
2006-02-02 07:15:46 +00:00
|
|
|
DecodeSpecialSprite(num, stage);
|
2005-08-15 11:39:13 +00:00
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
FioSkipBytes(num);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (_skip_sprites == 0) DEBUG(grf, 7) ("Skipping unexpected sprite");
|
|
|
|
|
|
|
|
FioSkipBytes(7);
|
|
|
|
num -= 8;
|
2004-11-12 23:26:02 +00:00
|
|
|
|
2005-08-15 11:39:13 +00:00
|
|
|
if (type & 2) {
|
|
|
|
FioSkipBytes(num);
|
|
|
|
} else {
|
|
|
|
while (num > 0) {
|
|
|
|
int8 i = FioReadByte();
|
|
|
|
if (i >= 0) {
|
|
|
|
num -= i;
|
|
|
|
FioSkipBytes(i);
|
2005-04-01 10:43:20 +00:00
|
|
|
} else {
|
2005-08-15 11:39:13 +00:00
|
|
|
i = -(i >> 3);
|
|
|
|
num -= i;
|
|
|
|
FioReadByte();
|
2005-04-01 10:43:20 +00:00
|
|
|
}
|
2005-08-15 11:39:13 +00:00
|
|
|
}
|
2005-04-01 10:43:20 +00:00
|
|
|
}
|
2004-11-12 23:26:02 +00:00
|
|
|
}
|
2005-08-15 11:39:13 +00:00
|
|
|
|
|
|
|
if (_skip_sprites > 0) _skip_sprites--;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-08-15 11:39:13 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-08-15 11:39:13 +00:00
|
|
|
|
|
|
|
void LoadNewGRF(uint load_index, uint file_index)
|
|
|
|
{
|
|
|
|
uint stage;
|
|
|
|
|
2006-01-30 14:50:55 +00:00
|
|
|
InitializeGRFSpecial();
|
2005-08-15 11:39:13 +00:00
|
|
|
|
2005-09-26 18:43:58 +00:00
|
|
|
ResetNewGRFData();
|
|
|
|
|
2005-08-15 11:39:13 +00:00
|
|
|
/* Load newgrf sprites
|
|
|
|
* in each loading stage, (try to) open each file specified in the config
|
|
|
|
* and load information from it. */
|
|
|
|
_custom_sprites_base = load_index;
|
2006-04-15 21:27:59 +00:00
|
|
|
for (stage = 0; stage <= 2; stage++) {
|
2005-09-09 06:39:47 +00:00
|
|
|
uint slot = file_index;
|
2006-04-22 13:17:13 +00:00
|
|
|
GRFConfig *c;
|
2005-08-15 11:39:13 +00:00
|
|
|
|
|
|
|
_cur_stage = stage;
|
|
|
|
_cur_spriteid = load_index;
|
2006-04-22 13:17:13 +00:00
|
|
|
for (c = _first_grfconfig; c != NULL; c = c->next) {
|
|
|
|
if (!FiosCheckFileExists(c->filename)) {
|
2005-08-15 11:39:13 +00:00
|
|
|
// TODO: usrerror()
|
2006-04-22 13:17:13 +00:00
|
|
|
error("NewGRF file missing: %s", c->filename);
|
2005-08-15 11:39:13 +00:00
|
|
|
}
|
2006-04-22 13:17:13 +00:00
|
|
|
|
|
|
|
if (stage == 0) InitNewGRFFile(c, _cur_spriteid);
|
|
|
|
LoadNewGRFFile(c->filename, slot++, stage);
|
2006-04-15 21:27:59 +00:00
|
|
|
if (stage == 2) ClearTemporaryNewGRFData();
|
2005-08-15 11:39:13 +00:00
|
|
|
DEBUG(spritecache, 2) ("Currently %i sprites are loaded", load_index);
|
|
|
|
}
|
|
|
|
}
|
2005-11-06 13:42:26 +00:00
|
|
|
|
|
|
|
// Pre-calculate all refit masks after loading GRF files
|
|
|
|
CalculateRefitMasks();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|