grfspecial.c
author darkvater
Sun, 14 Nov 2004 13:45:38 +0000
changeset 397 fc532e982139
parent 396 f7dc2d2144b6
child 398 20f8a2faf809
permissions -rw-r--r--
(svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     1
#include "stdafx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#include <stdarg.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     4
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "ttd.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     6
#include "gfx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     7
#include "fileio.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     8
#include "engine.h"
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
     9
#include "station.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    10
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
/* TTDPatch extended GRF format codec
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
 * (c) Petr Baudis 2004 (GPL'd)
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
    13
 * Changes by Florian octo Forster are (c) by the OpenTTD development team.
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
    14
 *
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
 * Contains portions of documentation by TTDPatch team.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
 * Thanks especially to Josef Drexler for the documentation as well as a lot
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
 * of help at #tycoon. Also thanks to Michael Blunck for is GRF files which
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
 * served as subject to the initial testing of this codec. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    20
extern int _skip_sprites;
361
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
    21
extern int _replace_sprites_count[16];
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
    22
extern int _replace_sprites_offset[16];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
    24
struct GRFFile {
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
    25
	char *filename;
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
    26
	uint32 grfid;
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
    27
	uint16 flags;
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
    28
	uint16 sprite_offset;
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
    29
	struct GRFFile *next;
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
    30
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
    31
	/* A sprite group contains all sprites of a given vehicle (or multiple
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
    32
	 * vehicles) when carrying given cargo. It consists of several sprite
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
    33
	 * sets.  Group ids are refered as "cargo id"s by TTDPatch
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
    34
	 * documentation, contributing to the global confusion.
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
    35
	 *
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
    36
	 * A sprite set contains all sprites of a given vehicle carrying given
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
    37
	 * cargo at a given *stage* - that is usually its load stage. Ie. you
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
    38
	 * can have a spriteset for an empty wagon, wagon full of coal,
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
    39
	 * half-filled wagon etc.  Each spriteset contains eight sprites (one
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
    40
	 * per direction) or four sprites if the vehicle is symmetric. */
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
    41
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
    42
	int spriteset_start;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
    43
	int spriteset_numsets;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
    44
	int spriteset_numents;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
    45
	int spriteset_feature;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
    46
397
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
    47
	int spritegroups_count;
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
    48
	struct SpriteGroup *spritegroups;
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
    49
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
    50
	uint32 statinfo_classid[256];
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
    51
	byte statinfo_tiles[256];
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
    52
	DrawTileSprites statinfo_renderdata[256][8];
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
    53
};
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
    54
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
    55
static struct GRFFile *_cur_grffile, *_first_grffile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    56
static int _cur_spriteid;
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
    57
static int _cur_stage;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    58
362
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
    59
static int32 _paramlist[0x7f];
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
    60
static int _param_max;
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
    61
363
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
    62
/* 32 * 8 = 256 flags. Apparently TTDPatch uses this many.. */
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
    63
static uint32 _ttdpatch_flags[8];
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
    64
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
    65
373
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    66
enum grfspec_feature {
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    67
	GSF_TRAIN,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    68
	GSF_ROAD,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    69
	GSF_SHIP,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    70
	GSF_AIRCRAFT,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    71
	GSF_STATION,
391
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
    72
	GSF_BRIDGE,
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
    73
	GSF_TOWNHOUSE,
373
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    74
};
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    75
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    76
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    77
typedef void (*SpecialSpriteHandler)(byte *buf, int len);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    78
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
    79
static const int _vehcounts[4] = {
373
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    80
	/* GSF_TRAIN */    NUM_TRAIN_ENGINES,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    81
	/* GSF_ROAD */     NUM_ROAD_ENGINES,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    82
	/* GSF_SHIP */     NUM_SHIP_ENGINES,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    83
	/* GSF_AIRCRAFT */ NUM_AIRCRAFT_ENGINES
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
    84
};
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
    85
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    86
static const int _vehshifts[4] = {
373
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    87
	/* GSF_TRAIN */    0,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    88
	/* GSF_ROAD */     ROAD_ENGINES_INDEX,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    89
	/* GSF_SHIP */     SHIP_ENGINES_INDEX,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    90
	/* GSF_AIRCRAFT */ AIRCRAFT_ENGINES_INDEX,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    91
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    93
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
    94
/* Debugging messages policy:
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
    95
 *
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
    96
 * These should be the severities used for direct DEBUG() calls
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
    97
 * (there is room for exceptions, but you have to have a good cause):
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
    98
 *
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
    99
 * 0..2 - dedicated to grfmsg()
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
   100
 * 3
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
   101
 * 4
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
   102
 * 5
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
   103
 * 6 - action handler entry reporting - one per action
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
   104
 * 7 - basic action progress reporting - in loops, only single one allowed
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
   105
 * 8 - more detailed progress reporting - less important stuff, in deep loops etc
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
   106
 * 9 - extremely detailed progress reporting - detailed reports inside of deep loops and so
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
   107
 */
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
   108
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
   109
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
enum grfmsg_severity {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
	GMS_NOTICE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   112
	GMS_WARN,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
	GMS_ERROR,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   114
	GMS_FATAL,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   116
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   117
static void CDECL grfmsg(enum grfmsg_severity severity, const char *str, ...)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   118
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   119
	static const char * const severitystr[4] = { "Notice", "Warning", "Error", "Fatal" };
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   120
	int export_severity = 0;
65
f9f866bc609c (svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents: 51
diff changeset
   121
	char buf[1024];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   122
	va_list va;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   123
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   124
	va_start(va, str);
65
f9f866bc609c (svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents: 51
diff changeset
   125
	vsprintf(buf, str, va);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   126
	va_end(va);
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   127
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   128
	export_severity = 2 - (severity == GMS_FATAL ? 2 : severity);
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   129
	DEBUG(grf, export_severity) ("[%s][%s] %s", _cur_grffile->filename, severitystr[severity], buf);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   130
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   132
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   133
#define check_length(real, wanted, where) \
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   134
do { \
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   135
	if (real < wanted) { \
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   136
		grfmsg(GMS_ERROR, "%s: Invalid special sprite length %d (expected %d)!", where, real, wanted); \
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   137
		return; \
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   138
	} \
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   139
} while (0)
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   140
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   141
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
   142
static byte INLINE grf_load_byte(byte **buf)
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
   143
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   144
	return *(*buf)++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   146
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
static uint16 grf_load_word(byte **buf)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   148
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
	uint16 val;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   150
	byte *p = *buf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   151
	val = p[0];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
	val |= p[1] << 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
	*buf = p + 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
	return val;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
static uint16 grf_load_dword(byte **buf)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
	uint32 val;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   160
	byte *p = *buf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
	val = p[0];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
	val |= p[1] << 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
	val |= p[2] << 16;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
	val |= p[3] << 24;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
	*buf = p + 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
	return val;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   169
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   170
static struct GRFFile *GetFileByGRFID(uint32 grfid)
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   171
{
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   172
	struct GRFFile *file;
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   173
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   174
	file = _first_grffile;
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   175
	while ((file != NULL) && (file->grfid != grfid))
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   176
		file = file->next;
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   177
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   178
	return file;
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   179
}
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   180
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
   181
static struct GRFFile *GetFileByFilename(const char *filename)
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   182
{
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   183
	struct GRFFile *file;
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   184
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   185
	file = _first_grffile;
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   186
	while ((file != NULL) && strcmp(file->filename, filename))
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
   187
		file = file->next;
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   188
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   189
	return file;
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   190
}
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   191
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   192
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   193
typedef bool (*VCI_Handler)(uint engine, int numinfo, int prop, byte **buf, int len);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   195
#define FOR_EACH_ENGINE for (i = 0; i < numinfo; i++)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   196
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   197
static void dewagonize(int condition, int engine)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
	EngineInfo *ei = &_engine_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
	RailVehicleInfo *rvi = &_rail_vehicle_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   202
	if (condition != 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   203
		ei->unk2 &= ~0x80;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
		rvi->flags &= ~2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   205
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
		ei->unk2 |= 0x80;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   207
		rvi->flags |= 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   211
static bool RailVehicleChangeInfo(uint engine, int numinfo, int prop, byte **bufp, int len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
	EngineInfo *ei = &_engine_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
	RailVehicleInfo *rvi = &_rail_vehicle_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
	byte *buf = *bufp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
	int i;
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   217
	bool ret = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   219
	switch (prop) {
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   220
		case 0x05: {	/* Track type */
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   221
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
				uint8 tracktype = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   223
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
				ei[i].railtype_climates &= 0xf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   225
				ei[i].railtype_climates |= tracktype << 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   227
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   228
		case 0x08: {	/* AI passenger service */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   229
			/* TODO */
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   230
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
				grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   233
			ret = true;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   234
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   235
		case 0x09: {	/* Speed */
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   236
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   237
				uint16 speed = grf_load_word(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   238
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
				rvi[i].max_speed = speed;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
				dewagonize(speed, engine + i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   242
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   243
		case 0x0B: {	/* Power */
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   244
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
				uint16 power = grf_load_word(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
				rvi[i].power = power;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   248
				dewagonize(power, engine + i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   249
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   250
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   251
		case 0x0D: {	/* Running cost factor */
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   252
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   253
				uint8 runcostfact = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
				rvi[i].running_cost_base = runcostfact;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
				dewagonize(runcostfact, engine + i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   258
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   259
		case 0x0E: {	/* Running cost base */
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   260
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
				uint32 base = grf_load_dword(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
				switch (base) {
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   264
				case 0x4C30:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
					rvi[i].engclass = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
					break;
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   267
				case 0x4C36:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
					rvi[i].engclass = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
					break;
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   270
				case 0x4C3C:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
					rvi[i].engclass = 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
					break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   273
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
				dewagonize(base, engine + i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   276
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   277
		case 0x12: {	/* Sprite ID */
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   278
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
				uint8 spriteid = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   281
				if (spriteid == 0xFD && rvi[i].image_index != 0xFD)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
					_engine_original_sprites[engine + i] = rvi[i].image_index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
				rvi[i].image_index = spriteid;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   284
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   285
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   286
		case 0x13: {	/* Dual-headed */
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   287
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
				uint8 dual = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   290
				if (dual != 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   291
					rvi[i].flags |= 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
				} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
					rvi[i].flags &= ~1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   296
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   297
		case 0x14: {	/* Cargo capacity */
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   298
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
				uint8 capacity = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
				rvi[i].capacity = capacity;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   303
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   304
		case 0x15: {	/* Cargo type */
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   305
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
				uint8 ctype = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
				rvi[i].cargo_type = ctype;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   310
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   311
		case 0x16: {	/* Weight */
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   312
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
				uint8 weight = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
				rvi[i].weight = weight;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   316
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   317
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   318
		case 0x17: {	/* Cost factor */
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   319
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   320
				uint8 cfactor = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   321
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
				rvi[i].base_cost = cfactor;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   323
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   324
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   325
		case 0x18: {	/* AI rank */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
			/* TODO: _railveh_score should be merged to _rail_vehicle_info. */
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   327
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
				grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   330
			ret = true;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   331
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   332
		case 0x19: { /* Engine traction type */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
			/* TODO: What do the individual numbers mean?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   334
			 * XXX: And in what base are they, in fact? --pasky */
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   335
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   336
				uint8 traction = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   337
				int engclass;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   339
				if (traction <= 0x07)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   340
					engclass = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   341
				else if (traction <= 0x27)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
					engclass = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   343
				else if (traction <= 0x31)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   344
					engclass = 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   345
				else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   346
					break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   347
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   348
				rvi[i].engclass = engclass;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   349
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   350
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   351
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   352
		/* TODO */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   353
		/* Fall-through for unimplemented four bytes long properties. */
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   354
		case 0x1D:	/* Refit cargo */
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   355
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
				grf_load_word(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   357
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   358
		/* Fall-through for unimplemented two bytes long properties. */
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   359
		case 0x1B:	/* Powered wagons power bonus */
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   360
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
				grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
		/* Fall-through for unimplemented one byte long properties. */
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   364
		case 0x1A:	/* Sort order */
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   365
		case 0x1C:	/* Refit cost */
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   366
		case 0x1E:	/* Callback */
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   367
		case 0x1F:	/* Tractive effort */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
		case 0x21:	/* Shorter tenders */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
		case 0x22:	/* Visual */
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   370
		case 0x23: {/* Powered wagons weight bonus */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   371
			/* TODO */
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   372
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
				grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   374
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   375
			ret = true;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   376
		}	break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
		default:
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   378
			ret = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
	*bufp = buf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
	return ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   383
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   384
static bool RoadVehicleChangeInfo(uint engine, int numinfo, int prop, byte **bufp, int len)
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   385
{
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   386
	RoadVehicleInfo *rvi = &_road_vehicle_info[engine];
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   387
	byte *buf = *bufp;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   388
	int i;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   389
	bool ret = false;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   390
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   391
	switch (prop) {
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   392
		case 0x08: {	/* Speed */
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   393
			FOR_EACH_ENGINE {
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   394
				uint8 speed = grf_load_byte(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   395
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   396
				rvi[i].max_speed = speed; // ?? units
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   397
			}
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   398
		}	break;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   399
		case 0x09: {	/* Running cost factor */
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   400
			FOR_EACH_ENGINE {
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   401
				uint8 runcost = grf_load_byte(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   402
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   403
				rvi[i].running_cost = runcost;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   404
			}
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   405
		}	break;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   406
		case 0x0A:	/* Running cost base */
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   407
			/* TODO: I have no idea. --pasky */
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   408
			FOR_EACH_ENGINE {
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   409
				grf_load_byte(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   410
			}
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   411
			ret = true;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   412
			break;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   413
		case 0x0E: {	/* Sprite ID */
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   414
			FOR_EACH_ENGINE {
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   415
				uint8 spriteid = grf_load_byte(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   416
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   417
				if (spriteid == 0xFF)
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   418
					spriteid = 0xFD; // cars have different custom id in the GRF file
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   419
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   420
				// This is currently not used but there's no reason
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   421
				// in not having it here for the future.
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   422
				if (spriteid == 0xFD && rvi[i].image_index != 0xFD)
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   423
					_engine_original_sprites[ROAD_ENGINES_INDEX + engine + i] = rvi[i].image_index;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   424
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   425
				rvi[i].image_index = spriteid;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   426
			}
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   427
		}	break;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   428
		case 0x0F: {	/* Cargo capacity */
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   429
			FOR_EACH_ENGINE {
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   430
				uint16 capacity = grf_load_word(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   431
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   432
				rvi[i].capacity = capacity;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   433
			}
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   434
		}	break;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   435
		case 0x10: { /* Cargo type */
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   436
			FOR_EACH_ENGINE {
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   437
				uint8 cargo = grf_load_byte(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   438
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   439
				rvi[i].cargo_type = cargo;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   440
			}
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   441
		}	break;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   442
		case 0x11: {	/* Cost factor */
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   443
			FOR_EACH_ENGINE {
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   444
				uint8 cost_factor = grf_load_byte(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   445
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   446
				rvi[i].base_cost = cost_factor; // ?? is it base_cost?
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   447
			}
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   448
		}	break;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   449
		case 0x12: {	/* SFX */
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   450
			FOR_EACH_ENGINE {
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   451
				uint8 sfx = grf_load_byte(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   452
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   453
				rvi[i].sfx = sfx;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   454
			}
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   455
		}	break;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   456
		case 0x13:      /* Power in 10hp */
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   457
		case 0x14:      /* Weight in 1/4 tons */
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   458
		case 0x15:      /* Speed in mph*0.8 */
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   459
			/* TODO: Support for road vehicles realistic power
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   460
			 * computations (called rvpower in TTDPatch) is just
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   461
			 * missing in OTTD yet. --pasky */
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   462
			FOR_EACH_ENGINE {
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   463
				grf_load_byte(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   464
			}
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   465
			ret = true;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   466
			break;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   467
		case 0x16: {	/* Cargos available for refitting */
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   468
			FOR_EACH_ENGINE {
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   469
				uint32 refit_mask = grf_load_dword(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   470
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   471
				_engine_refit_masks[ROAD_ENGINES_INDEX + engine + i] = refit_mask;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   472
			}
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   473
		}	break;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   474
		case 0x17:      /* Callback */
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   475
		case 0x18:      /* Tractive effort */
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   476
			/* TODO */
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   477
			FOR_EACH_ENGINE {
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   478
				grf_load_byte(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   479
			}
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   480
			ret = true;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   481
			break;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   482
		default:
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   483
			ret = true;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   484
	}
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   485
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   486
	*bufp = buf;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   487
	return ret;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   488
}
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   489
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   490
static bool ShipVehicleChangeInfo(uint engine, int numinfo, int prop, byte **bufp, int len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   491
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   492
	ShipVehicleInfo *svi = &_ship_vehicle_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   493
	byte *buf = *bufp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   494
	int i;
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   495
	bool ret = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   496
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   497
	//printf("e %x prop %x?\n", engine, prop);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   498
	switch (prop) {
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   499
		case 0x08: {	/* Sprite ID */
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   500
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   501
				uint8 spriteid = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   502
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   503
				if (spriteid == 0xFF)
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   504
					spriteid = 0xFD; // ships have different custom id in the GRF file
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   505
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   506
				// This is currently not used but there's no reason
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   507
				// in not having it here for the future.
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   508
				if (spriteid == 0xFD && svi[i].image_index != 0xFD)
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   509
					_engine_original_sprites[SHIP_ENGINES_INDEX + engine + i] = svi[i].image_index;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   510
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   511
				svi[i].image_index = spriteid;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   512
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   513
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   514
		case 0x09: {	/* Refittable */
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   515
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   516
				uint8 refittable = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   517
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   518
				svi[i].refittable = refittable;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   520
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   521
		case 0x0A: {	/* Cost factor */
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   522
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   523
				uint8 cost_factor = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   524
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   525
				svi[i].base_cost = cost_factor; // ?? is it base_cost?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   526
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   527
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   528
		case 0x0B: {	/* Speed */
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   529
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   530
				uint8 speed = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   531
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   532
				svi[i].max_speed = speed; // ?? units
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   533
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   534
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   535
		case 0x0C: { /* Cargo type */
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   536
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   537
				uint8 cargo = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   538
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   539
				// XXX: Need to consult this with patchman yet.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   540
#if 0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   541
				// Documentation claims this is already the
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   542
				// per-landscape cargo type id, but newships.grf
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   543
				// assume otherwise.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   544
				cargo = local_cargo_id_ctype[cargo];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   545
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   546
				svi[i].cargo_type = cargo;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   547
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   548
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   549
		case 0x0D: {	/* Cargo capacity */
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   550
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   551
				uint16 capacity = grf_load_word(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   552
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   553
				svi[i].capacity = capacity;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   554
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   555
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   556
		case 0x0F: {	/* Running cost factor */
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   557
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   558
				uint8 runcost = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   559
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   560
				svi[i].running_cost = runcost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   561
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   562
		} break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   563
		case 0x10: {	/* SFX */
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   564
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   565
				uint8 sfx = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   566
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   567
				svi[i].sfx = sfx;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   568
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   569
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   570
		case 0x11: {	/* Cargos available for refitting */
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   571
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   572
				uint32 refit_mask = grf_load_dword(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   573
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   574
				_engine_refit_masks[SHIP_ENGINES_INDEX + engine + i] = refit_mask;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   575
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   576
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   577
		case 0x12: { /* Callback TODO */
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   578
			ret = true;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   579
		}	break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   580
		default:
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   581
			ret = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   582
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   583
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   584
	*bufp = buf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   585
	return ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   586
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   587
381
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   588
static bool AircraftVehicleChangeInfo(uint engine, int numinfo, int prop, byte **bufp, int len)
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   589
{
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   590
	AircraftVehicleInfo *avi = &_aircraft_vehicle_info[engine];
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   591
	byte *buf = *bufp;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   592
	int i;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   593
	bool ret = false;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   594
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   595
	//printf("e %x prop %x?\n", engine, prop);
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   596
	switch (prop) {
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   597
		case 0x08: {	/* Sprite ID */
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   598
			FOR_EACH_ENGINE {
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   599
				uint8 spriteid = grf_load_byte(&buf);
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   600
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   601
				if (spriteid == 0xFF)
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   602
					spriteid = 0xFD; // ships have different custom id in the GRF file
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   603
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   604
				// This is currently not used but there's no reason
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   605
				// in not having it here for the future.
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   606
				if (spriteid == 0xFD && avi[i].image_index != 0xFD)
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   607
					_engine_original_sprites[AIRCRAFT_ENGINES_INDEX + engine + i] = avi[i].image_index;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   608
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   609
				avi[i].image_index = spriteid;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   610
			}
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   611
		}	break;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   612
		case 0x09: {	/* Helicopter */
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   613
			FOR_EACH_ENGINE {
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   614
				uint8 heli = grf_load_byte(&buf);
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   615
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   616
				avi[i].subtype = (heli == 0) ? 0 : 1;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   617
			}
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   618
		}	break;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   619
		case 0x0A: {	/* Large */
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   620
			FOR_EACH_ENGINE {
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   621
				uint8 large = grf_load_byte(&buf);
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   622
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   623
				avi[i].subtype = (large == 1) ? 3 : 1;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   624
			}
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   625
		}	break;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   626
		case 0x0B: {	/* Cost factor */
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   627
			FOR_EACH_ENGINE {
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   628
				uint8 cost_factor = grf_load_byte(&buf);
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   629
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   630
				avi[i].base_cost = cost_factor; // ?? is it base_cost?
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   631
			}
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   632
		}	break;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   633
		case 0x0C: {	/* Speed */
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   634
			FOR_EACH_ENGINE {
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   635
				uint8 speed = grf_load_byte(&buf);
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   636
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   637
				avi[i].max_speed = speed; // ?? units
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   638
			}
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   639
		}	break;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   640
		case 0x0D: {	/* Acceleration */
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   641
			FOR_EACH_ENGINE {
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   642
				uint8 accel = grf_load_byte(&buf);
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   643
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   644
				avi[i].acceleration = accel;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   645
			}
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   646
		} break;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   647
		case 0x0E: {	/* Running cost factor */
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   648
			FOR_EACH_ENGINE {
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   649
				uint8 runcost = grf_load_byte(&buf);
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   650
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   651
				avi[i].running_cost = runcost;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   652
			}
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   653
		} break;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   654
		case 0x0F: {	/* Passenger capacity */
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   655
			FOR_EACH_ENGINE {
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   656
				uint16 capacity = grf_load_word(&buf);
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   657
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   658
				avi[i].passanger_capacity = capacity;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   659
			}
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   660
		}	break;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   661
		case 0x11: {	/* Mail capacity */
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   662
			FOR_EACH_ENGINE {
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   663
				uint8 capacity = grf_load_byte(&buf);
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   664
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   665
				avi[i].mail_capacity = capacity;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   666
			}
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   667
		}	break;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   668
		case 0x12: {	/* SFX */
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   669
			FOR_EACH_ENGINE {
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   670
				uint8 sfx = grf_load_byte(&buf);
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   671
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   672
				avi[i].sfx = sfx;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   673
			}
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   674
		}	break;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   675
		case 0x13: {	/* Cargos available for refitting */
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   676
			FOR_EACH_ENGINE {
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   677
				uint32 refit_mask = grf_load_dword(&buf);
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   678
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   679
				_engine_refit_masks[AIRCRAFT_ENGINES_INDEX + engine + i] = refit_mask;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   680
			}
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   681
		}	break;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   682
		case 0x14: { /* Callback TODO */
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   683
			ret = true;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   684
		}	break;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   685
		default:
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   686
			ret = true;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   687
	}
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   688
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   689
	*bufp = buf;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   690
	return ret;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   691
}
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   692
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   693
static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int len)
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   694
{
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   695
	byte *buf = *bufp;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   696
	int i;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   697
	int ret = 0;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   698
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   699
	/* This is one single huge TODO. It doesn't handle anything more than
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   700
	 * just waypoints for now. */
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   701
391
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
   702
	/* TODO: Differentiate between railtypes. This is missing in the new
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
   703
	 * GRF file specification yet, though, so I need to agree on this with
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
   704
	 * patchman yet. We just assume all the station stuff is for railtype 0
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
   705
	 * (railroad) for now. --pasky */
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
   706
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   707
	//printf("sci %d %d [0x%02x]\n", stid, numinfo, prop);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   708
	switch (prop) {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   709
		case 0x08:
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   710
		{	/* Class ID */
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   711
			FOR_EACH_ENGINE {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   712
				/* classid, for a change, is always little-endian */
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   713
				_cur_grffile->statinfo_classid[stid+i] = *(buf++) << 24;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   714
				_cur_grffile->statinfo_classid[stid+i] |= *(buf++) << 16;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   715
				_cur_grffile->statinfo_classid[stid+i] |= *(buf++) << 8;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   716
				_cur_grffile->statinfo_classid[stid+i] |= *(buf++);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   717
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   718
			break;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   719
		}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   720
		case 0x09:
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   721
		{	/* Define sprite layout */
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   722
			FOR_EACH_ENGINE {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   723
				int t;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   724
				_cur_grffile->statinfo_tiles[stid+i] = grf_load_byte(&buf);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   725
				for (t = 0; t < _cur_grffile->statinfo_tiles[stid+i]; t++) {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   726
					DrawTileSprites *dts = &_cur_grffile->statinfo_renderdata[stid+i][t];
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   727
					int seq_count = 0;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   728
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   729
					if (t >= 8) {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   730
						grfmsg(GMS_WARN, "StationChangeInfo: Sprite %d>=8, skipping.", t);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   731
						grf_load_dword(&buf); // at least something
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   732
						continue;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   733
					}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   734
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   735
					dts->ground_sprite = grf_load_dword(&buf);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   736
					if (!dts->ground_sprite) {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   737
						static const DrawTileSeqStruct empty = {0x80};
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   738
						dts->seq = &empty;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   739
						continue;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   740
					}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   741
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   742
					dts->seq = NULL;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   743
					while (buf < *bufp + len) {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   744
						DrawTileSeqStruct *dtss;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   745
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   746
						// no relative bounding box support
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   747
						dts->seq = realloc((void*)dts->seq, ++seq_count * sizeof(DrawTileSeqStruct));
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   748
						dtss = (DrawTileSeqStruct*) &dts->seq[seq_count - 1];
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   749
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   750
						dtss->delta_x = grf_load_byte(&buf);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   751
						if ((byte) dtss->delta_x == 0x80) break;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   752
						dtss->delta_y = grf_load_byte(&buf);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   753
						dtss->delta_z = grf_load_byte(&buf);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   754
						dtss->width = grf_load_byte(&buf);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   755
						dtss->height = grf_load_byte(&buf);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   756
						dtss->unk = grf_load_byte(&buf);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   757
						dtss->image = grf_load_dword(&buf) - 0x42d;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   758
					}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   759
				}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   760
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   761
			break;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   762
		}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   763
		case 0x0a:
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   764
		{	/* Copy sprite layout */
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   765
			FOR_EACH_ENGINE {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   766
				byte src = grf_load_byte(&buf);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   767
				int t;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   768
				_cur_grffile->statinfo_tiles[stid+i] = _cur_grffile->statinfo_tiles[src];
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   769
				for (t = 0; t < _cur_grffile->statinfo_tiles[stid+i]; t++) {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   770
					DrawTileSprites *dts = &_cur_grffile->statinfo_renderdata[stid+i][t];
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   771
					DrawTileSprites *sdts = &_cur_grffile->statinfo_renderdata[src][t];
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   772
					DrawTileSeqStruct const *sdtss = sdts->seq;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   773
					int seq_count = 0;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   774
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   775
					dts->ground_sprite = sdts->ground_sprite;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   776
					if (!dts->ground_sprite) {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   777
						static const DrawTileSeqStruct empty = {0x80};
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   778
						dts->seq = &empty;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   779
						continue;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   780
					}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   781
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   782
					dts->seq = NULL;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   783
					while (1) {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   784
						DrawTileSeqStruct *dtss;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   785
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   786
						// no relative bounding box support
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   787
						dts->seq = realloc((void*)dts->seq, ++seq_count * sizeof(DrawTileSeqStruct));
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   788
						dtss = (DrawTileSeqStruct*) &dts->seq[seq_count - 1];
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   789
						*dtss = *sdtss;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   790
						if ((byte) dtss->delta_x == 0x80) break;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   791
						sdtss++;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   792
					}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   793
				}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   794
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   795
			break;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   796
		}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   797
		case 0x0b:
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   798
		{	/* Callback */
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   799
			/* TODO */
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   800
			FOR_EACH_ENGINE {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   801
				grf_load_byte(&buf);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   802
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   803
			ret = 1;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   804
			break;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   805
		}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   806
		case 0x0c:
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   807
		{	/* Platforms number */
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   808
			/* TODO */
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   809
			FOR_EACH_ENGINE {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   810
				grf_load_byte(&buf);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   811
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   812
			ret = 1;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   813
			break;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   814
		}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   815
		case 0x0d:
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   816
		{	/* Platforms length */
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   817
			/* TODO */
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   818
			FOR_EACH_ENGINE {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   819
				grf_load_byte(&buf);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   820
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   821
			ret = 1;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   822
			break;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   823
		}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   824
		case 0x0e:
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   825
		{	/* Define custom layout */
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   826
			/* TODO */
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   827
			FOR_EACH_ENGINE {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   828
				while (buf < *bufp + len) {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   829
					byte length = grf_load_byte(&buf);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   830
					byte number = grf_load_byte(&buf);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   831
					int k = length * number;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   832
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   833
					if (!length && !number) break;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   834
					while (k--) grf_load_byte(&buf);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   835
				}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   836
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   837
			ret = 1;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   838
			break;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   839
		}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   840
		case 0x0f:
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   841
		{	/* Copy custom layout */
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   842
			/* TODO */
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   843
			FOR_EACH_ENGINE {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   844
				grf_load_byte(&buf);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   845
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   846
			ret = 1;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   847
			break;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   848
		}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   849
		case 0x10:
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   850
		{	/* Little/lots cargo threshold */
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   851
			/* TODO */
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   852
			FOR_EACH_ENGINE {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   853
				grf_load_word(&buf);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   854
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   855
			ret = 1;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   856
			break;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   857
		}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   858
		default:
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   859
			ret = 1;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   860
			break;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   861
	}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   862
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   863
	*bufp = buf;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   864
	return ret;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   865
}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   866
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   867
#undef shift_buf
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   868
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   869
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
   870
/* Action 0x00 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   871
static void VehicleChangeInfo(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   872
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   873
	byte *bufend = buf + len;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   874
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   875
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   876
	/* <00> <feature> <num-props> <num-info> <id> (<property <new-info>)...
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   877
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   878
	 * B feature       0, 1, 2 or 3 for trains, road vehicles, ships or planes
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   879
	 *                 4 for defining new train station sets
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   880
	 * B num-props     how many properties to change per vehicle/station
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   881
	 * B num-info      how many vehicles/stations to change
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   882
	 * B id            ID of first vehicle/station to change, if num-info is
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   883
	 *                 greater than one, this one and the following
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   884
	 *                 vehicles/stations will be changed
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   885
	 * B property      what property to change, depends on the feature
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   886
	 * V new-info      new bytes of info (variable size; depends on properties) */
391
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
   887
	/* TODO: Bridges, town houses. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   888
391
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
   889
	static const VCI_Handler handler[7] = {
373
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
   890
		/* GSF_TRAIN */    RailVehicleChangeInfo,
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   891
		/* GSF_ROAD */     RoadVehicleChangeInfo,
373
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
   892
		/* GSF_SHIP */     ShipVehicleChangeInfo,
381
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   893
		/* GSF_AIRCRAFT */ AircraftVehicleChangeInfo,
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   894
		/* GSF_STATION */  StationChangeInfo,
391
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
   895
		/* GSF_BRIDGE */   NULL,
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
   896
		/* GSF_TOWNHOUSE */NULL,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   897
	};
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   898
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   899
	uint8 feature;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   900
	uint8 numprops;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   901
	uint8 numinfo;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   902
	byte engine;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   903
	EngineInfo *ei;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   904
396
f7dc2d2144b6 (svn r588) -newgrf: Silent ignore those stupid one-byte zero special sprites (dbsetw.grf is crawling with them) (pasky).
darkvater
parents: 391
diff changeset
   905
	if (len == 1) {
f7dc2d2144b6 (svn r588) -newgrf: Silent ignore those stupid one-byte zero special sprites (dbsetw.grf is crawling with them) (pasky).
darkvater
parents: 391
diff changeset
   906
		DEBUG(grf, 8) ("Silently ignoring one-byte special sprite 0x00.");
f7dc2d2144b6 (svn r588) -newgrf: Silent ignore those stupid one-byte zero special sprites (dbsetw.grf is crawling with them) (pasky).
darkvater
parents: 391
diff changeset
   907
		return;
f7dc2d2144b6 (svn r588) -newgrf: Silent ignore those stupid one-byte zero special sprites (dbsetw.grf is crawling with them) (pasky).
darkvater
parents: 391
diff changeset
   908
	}
f7dc2d2144b6 (svn r588) -newgrf: Silent ignore those stupid one-byte zero special sprites (dbsetw.grf is crawling with them) (pasky).
darkvater
parents: 391
diff changeset
   909
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   910
	check_length(len, 6, "VehicleChangeInfo");
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   911
	feature = buf[1];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   912
	numprops = buf[2];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   913
	numinfo = buf[3];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   914
	engine = buf[4];
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 74
diff changeset
   915
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   916
	DEBUG(grf, 6) ("VehicleChangeInfo: Feature %d, %d properties, to apply to %d+%d",
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   917
	               feature, numprops, engine, numinfo);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   918
391
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
   919
	if (feature > GSF_STATION) {
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
   920
		grfmsg(GMS_WARN, "VehicleChangeInfo: Unsupported feature %d, skipping.", feature);
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
   921
		return;
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
   922
	}
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
   923
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   924
	if (feature != GSF_STATION)
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   925
		ei = &_engine_info[engine + _vehshifts[feature]];
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   926
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   927
	buf += 5;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   928
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   929
	while (numprops-- && buf < bufend) {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   930
		uint8 prop = grf_load_byte(&buf);
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   931
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   932
		if (feature == 4)
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   933
			// stations don't share those common properties
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   934
			goto run_handler;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   935
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   936
		switch (prop) {
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   937
		case 0x00: { /* Introduction date */
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   938
			FOR_EACH_ENGINE {
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   939
				uint16 date = grf_load_word(&buf);
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   940
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   941
				ei[i].base_intro = date;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   942
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   943
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   944
		case 0x02: { /* Decay speed */
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   945
			FOR_EACH_ENGINE {
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   946
				uint8 decay = grf_load_byte(&buf);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   947
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   948
				ei[i].unk2 &= 0x80;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   949
				ei[i].unk2 |= decay & 0x7f;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   950
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   951
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   952
		case 0x03: { /* Vehicle life */
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   953
			FOR_EACH_ENGINE {
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   954
				uint8 life = grf_load_byte(&buf);
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   955
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   956
				ei[i].lifelength = life;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   957
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   958
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   959
		case 0x04: { /* Model life */
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   960
			FOR_EACH_ENGINE {
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   961
				uint8 life = grf_load_byte(&buf);
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   962
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   963
				ei[i].base_life = life;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   964
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   965
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   966
		case 0x06: { /* Climates available */
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   967
			FOR_EACH_ENGINE {
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   968
				uint8 climates = grf_load_byte(&buf);
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   969
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   970
				ei[i].railtype_climates &= 0xf0;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   971
				ei[i].railtype_climates |= climates;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   972
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   973
		}	break;
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   974
		case 0x07: { /* Loading speed */
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   975
			/* TODO */
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   976
			/* Hyronymus explained me what does
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   977
			 * this mean and insists on having a
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   978
			 * credit ;-). --pasky */
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   979
			/* TODO: This needs to be supported by
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   980
			 * LoadUnloadVehicle() first. */
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   981
			FOR_EACH_ENGINE {
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   982
				grf_load_byte(&buf);
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   983
			}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   984
			goto ignoring;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   985
		}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   986
		default: {
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   987
run_handler:
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   988
			if (handler[feature](engine, numinfo, prop, &buf, bufend - buf)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   989
ignoring:
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   990
				grfmsg(GMS_NOTICE, "VehicleChangeInfo: Ignoring property %x (not implemented).", prop);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   991
			}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   992
			break;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   993
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   994
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   995
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   996
#undef shift_buf
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   997
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   998
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   999
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1000
/* Action 0x01 */
369
ab2266938fa8 (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  1001
static void NewSpriteSet(byte *buf, int len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1002
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1003
	/* <01> <feature> <num-sets> <num-ent>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1004
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1005
	 * B feature       feature to define sprites for
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1006
	 *                 0, 1, 2, 3: veh-type, 4: train stations
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1007
	 * B num-sets      number of sprite sets
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1008
	 * B num-ent       how many entries per sprite set
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1009
	 *                 For vehicles, this is the number of different
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1010
	 *                         vehicle directions in each sprite set
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1011
	 *                         Set num-dirs=8, unless your sprites are symmetric.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1012
	 *                         In that case, use num-dirs=4.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1013
	 *                 For stations, must be 12 (hex) for the eighteen
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1014
	 *                         different sprites that make up a station */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1015
	/* TODO: No stations support. */
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1016
	uint8 feature;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1017
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1018
	check_length(len, 4, "NewSpriteSet");
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1019
	feature = buf[1];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1020
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1021
	_cur_grffile->spriteset_start = _cur_spriteid + 1;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1022
	_cur_grffile->spriteset_feature = feature;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1023
	_cur_grffile->spriteset_numsets = buf[2];
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1024
	_cur_grffile->spriteset_numents = buf[3];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1025
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1026
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1027
/* Action 0x02 */
369
ab2266938fa8 (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  1028
static void NewSpriteGroup(byte *buf, int len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1029
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1030
	byte *bufend = buf + len;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1031
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1032
	/* <02> <feature> <set-id> <type/num-entries> <feature-specific-data...>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1033
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1034
	 * B feature       see action 1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1035
	 * B set-id        ID of this particular definition
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1036
	 * B type/num-entries
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1037
	 *                 if 80 or greater, this is a randomized or variational
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1038
	 *                 list definition, see below
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1039
	 *                 otherwise it specifies a number of entries, the exact
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1040
	 *                 meaning depends on the feature
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1041
	 * V feature-specific-data (huge mess, don't even look it up --pasky) */
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1042
	/* TODO: No 0x80-types (ugh). */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1043
	/* TODO: Also, empty sprites aren't handled for now. Need to investigate
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1044
	 * the "opacity" rules for these, that is which sprite to fall back to
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1045
	 * when. --pasky */
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1046
	uint8 feature;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1047
	uint8 setid;
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1048
	/* XXX: For stations, these two are "little cargo" and "lotsa cargo" sets. */
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1049
	uint8 numloaded;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1050
	uint8 numloading;
369
ab2266938fa8 (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  1051
	struct SpriteGroup *group;
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1052
	byte *loaded_ptr;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1053
	byte *loading_ptr;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1054
	int i;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 74
diff changeset
  1055
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1056
	check_length(len, 5, "NewSpriteGroup");
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1057
	feature = buf[1];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1058
	setid = buf[2];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1059
	numloaded = buf[3];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1060
	numloading = buf[4];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1061
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1062
	if (numloaded == 0x81) {
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1063
		/* XXX: This just goes for the default superset for now,
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1064
		 * straight and safe. --pasky */
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1065
		uint8 var = buf[4];
397
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1066
		uint8 shiftnum = buf[5];
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1067
		uint8 andmask = buf[6];
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1068
		uint8 nvar = buf[7];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1069
		//uint32 val;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1070
		uint16 def;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1071
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1072
		grfmsg(GMS_WARN, "NewSpriteGroup(0x81): Unsupported variable %x. Using default cid.", var);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1073
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1074
		//val = (0xff << shiftnum) & andmask;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1075
397
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1076
		if (setid >= _cur_grffile->spritegroups_count) {
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1077
			_cur_grffile->spritegroups_count = setid + 1;
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1078
			_cur_grffile->spritegroups = realloc(_cur_grffile->spritegroups, _cur_grffile->spritegroups_count * sizeof(struct SpriteGroup));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1079
		}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1080
		buf += 8 + nvar * 4;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1081
		def = grf_load_word(&buf);
397
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1082
		_cur_grffile->spritegroups[setid] = _cur_grffile->spritegroups[def];
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1083
		return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1084
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1085
	} else if (numloaded & 0x80) {
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1086
		grfmsg(GMS_WARN, "NewSpriteGroup(0x%x): Unsupported special group.", numloaded);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1087
		return;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1088
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1089
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1090
	if (!_cur_grffile->spriteset_start) {
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1091
		grfmsg(GMS_ERROR, "NewSpriteGroup: No sprite set to work on! Skipping.");
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1092
		return;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1093
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1094
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1095
	if (_cur_grffile->spriteset_feature != feature) {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1096
		grfmsg(GMS_ERROR, "NewSpriteGroup: Group feature %x doesn't match set feature %x! Playing it risky and trying to use it anyway.", feature, _cur_grffile->spriteset_feature);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1097
		// return; // XXX: we can't because of MB's newstats.grf --pasky
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1098
	}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1099
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1100
	check_length(bufend - buf, 5, "NewSpriteGroup");
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1101
	buf += 5;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1102
	check_length(bufend - buf, 2 * numloaded, "NewSpriteGroup");
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1103
	loaded_ptr = buf;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1104
	loading_ptr = buf + 2 * numloaded;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1105
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1106
	if (numloaded > 16) {
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1107
		grfmsg(GMS_WARN, "NewSpriteGroup: More than 16 sprites in group %x, skipping the rest.", setid);
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1108
		numloaded = 16;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1109
	}
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1110
	if (numloading > 16) {
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1111
		grfmsg(GMS_WARN, "NewSpriteGroup: More than 16 sprites in group %x, skipping the rest.", setid);
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1112
		numloading = 16;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1113
	}
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1114
397
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1115
	if (setid >= _cur_grffile->spritegroups_count) {
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1116
		_cur_grffile->spritegroups_count = setid + 1;
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1117
		_cur_grffile->spritegroups = realloc(_cur_grffile->spritegroups, _cur_grffile->spritegroups_count * sizeof(struct SpriteGroup));
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1118
	}
397
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1119
	group = &_cur_grffile->spritegroups[setid];
369
ab2266938fa8 (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  1120
	memset(group, 0, sizeof(struct SpriteGroup));
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1121
	group->sprites_per_set = _cur_grffile->spriteset_numents;
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1122
	group->loaded_count  = numloaded;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1123
	group->loading_count = numloading;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1124
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1125
	DEBUG(grf, 6) ("NewSpriteGroup: New SpriteGroup 0x%02hhx, %u views, %u loaded, %u loading, sprites %u - %u",
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1126
			setid, group->sprites_per_set, group->loaded_count, group->loading_count,
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1127
			_cur_grffile->spriteset_start - _cur_grffile->sprite_offset,
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1128
			_cur_grffile->spriteset_start + (_cur_grffile->spriteset_numents * (numloaded + numloading)) - _cur_grffile->sprite_offset);
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1129
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1130
	for (i = 0; i < numloaded; i++) {
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1131
		uint16 spriteset_id = grf_load_word(&loaded_ptr);
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1132
		group->loaded[i] = _cur_grffile->spriteset_start + spriteset_id * _cur_grffile->spriteset_numents;
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1133
		DEBUG(grf, 8) ("NewSpriteGroup: + group->loaded[%i]  = %u (subset %u)", i, group->loaded[i], spriteset_id);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1134
	}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1135
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1136
	for (i = 0; i < numloading; i++) {
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1137
		uint16 spriteset_id = grf_load_word(&loading_ptr);
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1138
		group->loading[i] = _cur_grffile->spriteset_start + spriteset_id * _cur_grffile->spriteset_numents;
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1139
		DEBUG(grf, 8) ("NewSpriteGroup: + group->loading[%i] = %u (subset %u)", i, group->loading[i], spriteset_id);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1140
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1141
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1142
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1143
/* Action 0x03 */
369
ab2266938fa8 (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  1144
static void NewVehicle_SpriteGroupMapping(byte *buf, int len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1145
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1146
	/* <03> <feature> <n-id> <ids>... <num-cid> [<cargo-type> <cid>]... <def-cid>
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1147
	 * id-list	:= [<id>] [id-list]
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1148
	 * cargo-list	:= <cargo-type> <cid> [cargo-list]
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1149
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1150
	 * B feature       see action 0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1151
	 * B n-id          bits 0-6: how many IDs this definition applies to
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1152
	 *                 bit 7: if set, this is a wagon override definition (see below)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1153
	 * B ids           the IDs for which this definition applies
369
ab2266938fa8 (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  1154
	 * B num-cid       number of cargo IDs (sprite group IDs) in this definition
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1155
	 *                 can be zero, in that case the def-cid is used always
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1156
	 * B cargo-type    type of this cargo type (e.g. mail=2, wood=7, see below)
369
ab2266938fa8 (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  1157
	 * W cid           cargo ID (sprite group ID) for this type of cargo
ab2266938fa8 (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  1158
	 * W def-cid       default cargo ID (sprite group ID) */
391
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1159
	/* TODO: Bridges, town houses. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1160
	/* TODO: Multiple cargo support could be useful even for trains/cars -
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1161
	 * cargo id 0xff is used for showing images in the build train list. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1162
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1163
	static byte *last_engines;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1164
	static int last_engines_count;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1165
	uint8 feature;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1166
	uint8 idcount;
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1167
	bool wagover;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1168
	uint8 cidcount;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1169
	int c, i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1170
369
ab2266938fa8 (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  1171
	check_length(len, 7, "VehicleMapSpriteGroup");
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1172
	feature = buf[1];
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  1173
	idcount = buf[2] & 0x7F;
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1174
	wagover = (buf[2] & 0x80) == 0x80;
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1175
	check_length(len, 3 + idcount, "VehicleMapSpriteGroup");
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1176
	cidcount = buf[3 + idcount];
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1177
	check_length(len, 4 + idcount + cidcount * 3, "VehicleMapSpriteGroup");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1178
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1179
	DEBUG(grf, 6) ("VehicleMapSpriteGroup: Feature %d, %d ids, %d cids, wagon override %d.",
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1180
			feature, idcount, cidcount, wagover);
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1181
391
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1182
	if (feature > GSF_STATION) {
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1183
		grfmsg(GMS_WARN, "VehicleMapSpriteGroup: Unsupported feature %d, skipping.", feature);
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1184
		return;
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1185
	}
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1186
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1187
373
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
  1188
	if (feature == GSF_STATION) {
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1189
		// We do things differently for stations.
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1190
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1191
		/* XXX: Currently we don't support cargo-specific images, so
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1192
		 * we go straight to the defaults. */
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1193
		byte *bp = buf + 4 + idcount + cidcount * 3;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1194
		uint16 groupid = grf_load_word(&bp);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1195
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1196
		for (i = 0; i < idcount; i++) {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1197
			uint8 stid = buf[3 + i];
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1198
			int j;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1199
397
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1200
			if (groupid >= _cur_grffile->spritegroups_count) {
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1201
				grfmsg(GMS_WARN, "VehicleMapSpriteGroup: Spriteset %x out of range %x, skipping.",
397
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1202
				       groupid, _cur_grffile->spritegroups_count);
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1203
				return;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1204
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1205
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1206
			// relocate sprite indexes based on spriteset locations
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1207
			for (j = 0; j < _cur_grffile->statinfo_tiles[stid]; j++) {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1208
				DrawTileSeqStruct *seq;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1209
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1210
				foreach_draw_tile_seq(seq, (DrawTileSeqStruct*) _cur_grffile->statinfo_renderdata[stid][j].seq) {
397
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1211
					seq->image += _cur_grffile->spritegroups[groupid].loading[0];
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1212
				}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1213
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1214
			/* FIXME: This means several GRF files defining new stations
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1215
			 * will override each other, but the stid should be GRF-specific
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1216
			 * instead! --pasky */
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1217
			SetCustomStation(_cur_grffile->statinfo_classid[stid], stid, _cur_grffile->statinfo_renderdata[stid], _cur_grffile->statinfo_tiles[stid]);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1218
			_cur_grffile->statinfo_classid[stid] = 0;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1219
		}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1220
		return;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1221
	}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1222
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1223
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1224
	/* If ``n-id'' (or ``idcount'') is zero, this is a ``feature
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1225
	 * callback''. I have no idea how this works, so we will ignore it for
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1226
	 * now.  --octo */
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1227
	if (idcount == 0) {
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1228
		grfmsg(GMS_NOTICE, "NewMapping: Feature callbacks not implemented yet.");
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1229
		return;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1230
	}
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1231
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1232
	// FIXME: Tropicset contains things like:
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1233
	// 03 00 01 19 01 00 00 00 00 - this is missing one 00 at the end,
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1234
	// what should we exactly do with that? --pasky
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1235
397
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1236
	if (!_cur_grffile->spriteset_start || !_cur_grffile->spritegroups) {
369
ab2266938fa8 (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  1237
		grfmsg(GMS_WARN, "VehicleMapSpriteGroup: No sprite set to work on! Skipping.");
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1238
		return;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1239
	}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1240
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1241
	if (!wagover && last_engines_count != idcount) {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1242
		last_engines = realloc(last_engines, idcount);
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1243
		last_engines_count = idcount;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1244
	}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1245
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1246
	if (wagover) {
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1247
		if (last_engines_count == 0) {
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1248
			grfmsg(GMS_ERROR, "VehicleMapSpriteGroup: WagonOverride: No engine to do override with.");
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1249
			return;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1250
		}
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1251
		DEBUG(grf, 6) ("VehicleMapSpriteGroup: WagonOverride: %u engines, %u wagons.",
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1252
				last_engines_count, idcount);
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1253
	}
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1254
	
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1255
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1256
	for (i = 0; i < idcount; i++) {
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1257
		uint8 engine_id = buf[3 + i];
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1258
		uint8 engine = engine_id + _vehshifts[feature];
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1259
		byte *bp = &buf[4 + idcount];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1260
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1261
		if (engine_id > _vehcounts[feature]) {
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1262
			grfmsg(GMS_ERROR, "Id %u for feature %x is out of bounds.",
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1263
					engine_id, feature);
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1264
			return;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1265
		}
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1266
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1267
		DEBUG(grf, 7) ("VehicleMapSpriteGroup: [%d] Engine %d...", i, engine);
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1268
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1269
		for (c = 0; c < cidcount; c++) {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1270
			uint8 ctype = grf_load_byte(&bp);
369
ab2266938fa8 (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  1271
			uint16 groupid = grf_load_word(&bp);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1272
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1273
			DEBUG(grf, 8) ("VehicleMapSpriteGroup: * [%d] Cargo type %x, group id %x", c, ctype, groupid);
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1274
397
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1275
			if (groupid >= _cur_grffile->spritegroups_count) {
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1276
				grfmsg(GMS_WARN, "VehicleMapSpriteGroup: Spriteset %x out of range %x, skipping.", groupid, _cur_grffile->spritegroups_count);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1277
				return;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1278
			}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1279
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  1280
			if (ctype == 0xFF)
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1281
				ctype = CID_PURCHASE;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1282
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1283
			if (wagover) {
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1284
				// TODO: No multiple cargo types per vehicle yet. --pasky
397
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1285
				SetWagonOverrideSprites(engine, &_cur_grffile->spritegroups[groupid], last_engines, last_engines_count);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1286
			} else {
397
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1287
				SetCustomEngineSprites(engine, ctype, &_cur_grffile->spritegroups[groupid]);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1288
				last_engines[i] = engine;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1289
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1290
		}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1291
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1292
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1293
	{
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1294
		byte *bp = buf + 4 + idcount + cidcount * 3;
369
ab2266938fa8 (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  1295
		uint16 groupid = grf_load_word(&bp);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1296
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1297
		DEBUG(grf, 8) ("-- Default group id %x", groupid);
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1298
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1299
		for (i = 0; i < idcount; i++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1300
			uint8 engine = buf[3 + i] + _vehshifts[feature];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1301
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1302
			// Don't tell me you don't love duplicated code!
397
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1303
			if (groupid >= _cur_grffile->spritegroups_count) {
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1304
				grfmsg(GMS_WARN, "VehicleMapSpriteGroup: Spriteset %x out of range %x, skipping.", groupid, _cur_grffile->spritegroups_count);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1305
				return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1306
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1307
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1308
			if (wagover) {
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1309
				// TODO: No multiple cargo types per vehicle yet. --pasky
397
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1310
				SetWagonOverrideSprites(engine, &_cur_grffile->spritegroups[groupid], last_engines, last_engines_count);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1311
			} else {
397
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1312
				SetCustomEngineSprites(engine, CID_DEFAULT, &_cur_grffile->spritegroups[groupid]);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1313
				last_engines[i] = engine;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1314
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1315
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1316
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1317
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1318
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1319
/* Action 0x04 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1320
static void VehicleNewName(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1321
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1322
	/* <04> <veh-type> <language-id> <num-veh> <offset> <data...>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1323
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1324
	 * B veh-type      see action 0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1325
	 * B language-id   language ID with bit 7 cleared (see below)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1326
	 * B num-veh       number of vehicles which are getting a new name
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1327
	 * B offset        number of the first vehicle that gets a new name
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1328
	 * S data          new texts, each of them zero-terminated, after
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1329
	 *                 which the next name begins. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1330
	/* TODO: No support for changing non-vehicle text. Perhaps we shouldn't
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1331
	 * implement it at all, but it could be useful for some "modpacks"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1332
	 * (completely new scenarios changing all graphics and logically also
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1333
	 * factory names etc). We should then also support all languages (by
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1334
	 * name), not only the original four ones. --pasky */
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1335
	/* TODO: Support for custom station class/type names. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1336
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1337
	uint8 feature;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1338
	uint8 lang;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1339
	uint8 id;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1340
	uint8 endid;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1341
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1342
	check_length(len, 6, "VehicleNewName");
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1343
	feature = buf[1];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1344
	lang = buf[2];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1345
	id = buf[4] + _vehshifts[feature];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1346
	endid = id + buf[3];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1347
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1348
	DEBUG(grf, 6) ("VehicleNewName: About to rename engines %d..%d (feature %d) in language 0x%x.",
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1349
	               id, endid, feature, lang);
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1350
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1351
	if (lang & 0x80) {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1352
		grfmsg(GMS_WARN, "VehicleNewName: No support for changing in-game texts. Skipping.");
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1353
		return;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1354
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1355
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1356
	if (!(lang & 3)) {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1357
		/* XXX: If non-English name, silently skip it. */
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1358
		DEBUG(grf, 7) ("VehicleNewName: Skipping non-English name.");
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1359
		return;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1360
	}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1361
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1362
	buf += 5, len -= 5;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1363
	for (; id < endid && len > 0; id++) {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1364
		int ofs = strlen(buf) + 1;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1365
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1366
		if (ofs < 128) {
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1367
			DEBUG(grf, 8) ("VehicleNewName: %d <- %s", id, buf);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1368
			SetCustomEngineName(id, buf);
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1369
		} else {
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1370
			DEBUG(grf, 7) ("VehicleNewName: Too long a name (%d)", ofs);
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1371
		}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1372
		buf += ofs, len -= ofs;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1373
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1374
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1375
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1376
/* Action 0x05 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1377
static void GraphicsNew(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1378
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1379
	/* <05> <graphics-type> <num-sprites> <other data...>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1380
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1381
	 * B graphics-type What set of graphics the sprites define.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1382
	 * B num-sprites   How many sprites are in this set?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1383
	 * V other data    Graphics type specific data.  Currently unused. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1384
	/* TODO */
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1385
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1386
	uint8 type;
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1387
	uint8 num;
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1388
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1389
	check_length(len, 2, "GraphicsNew");
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1390
	type = buf[0];
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1391
	num = buf[1];
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1392
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1393
	grfmsg(GMS_NOTICE, "GraphicsNew: Custom graphics (type %x) sprite block of length %d (unimplemented, ignoring).\n",
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1394
	       type, num);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1395
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1396
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1397
/* Action 0x06 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1398
static void CfgApply(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1399
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1400
	/* <06> <param-num> <param-size> <offset> ... <FF>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1401
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1402
	 * B param-num     Number of parameter to substitute (First = "zero")
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1403
	 *                 Ignored if that parameter was not specified in newgrf.cfg
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1404
	 * B param-size    How many bytes to replace.  If larger than 4, the
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1405
	 *                 bytes of the following parameter are used.  In that
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1406
	 *                 case, nothing is applied unless *all* parameters
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1407
	 *                 were specified.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1408
	 * B offset        Offset into data from beginning of next sprite
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1409
	 *                 to place where parameter is to be stored. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1410
	/* TODO */
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1411
	grfmsg(GMS_NOTICE, "CfgApply: Ignoring (not implemented).\n");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1412
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1413
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1414
/* Action 0x07 */
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1415
/* Action 0x09 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1416
static void SkipIf(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1417
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1418
	/* <07/09> <param-num> <param-size> <condition-type> <value> <num-sprites>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1419
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1420
	 * B param-num
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1421
	 * B param-size
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1422
	 * B condition-type
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1423
	 * V value
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1424
	 * B num-sprites */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1425
	/* TODO: More params. More condition types. */
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1426
	uint8 param;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1427
	uint8 paramsize;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1428
	uint8 condtype;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1429
	uint8 numsprites;
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  1430
	int param_val = 0, cond_val = 0;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  1431
	bool result;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1432
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1433
	check_length(len, 6, "SkipIf");
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1434
	param = buf[1];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1435
	paramsize = buf[2];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1436
	condtype = buf[3];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1437
359
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1438
	if (condtype < 2) {
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1439
		/* Always 1 for bit tests, the given value should
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1440
		 * be ignored. */
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1441
		paramsize = 1;
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1442
	}
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1443
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1444
	buf += 4;
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1445
	if (paramsize == 4)
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1446
		cond_val = grf_load_dword(&buf);
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1447
	else if (paramsize == 2)
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1448
		cond_val = grf_load_word(&buf);
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1449
	else if (paramsize == 1)
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1450
		cond_val = grf_load_byte(&buf);
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1451
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1452
	switch (param) {
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1453
		case 0x83:
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1454
			param_val = _opt.landscape;
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1455
			break;
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1456
		case 0x84:
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1457
			param_val = _cur_stage;
359
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1458
			break;
363
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
  1459
		case 0x85:
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
  1460
			param_val = _ttdpatch_flags[cond_val / 0x20];
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
  1461
			cond_val %= 0x20;
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
  1462
			break;
359
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1463
		case 0x86:
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1464
			param_val = _opt.road_side << 4;
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1465
			break;
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  1466
		case 0x88: {
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  1467
			struct GRFFile *file;
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  1468
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  1469
			file = GetFileByGRFID(cond_val);
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  1470
			param_val = (file != NULL);
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  1471
		}	break;
359
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1472
		default:
362
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1473
			if (param >= 0x80) {
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1474
				/* In-game variable. */
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1475
				grfmsg(GMS_WARN, "Unsupported in-game variable %x. Ignoring test.", param);
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1476
			} else {
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1477
				/* Parameter. */
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1478
				param_val = _paramlist[param];
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1479
			}
359
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1480
			return;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1481
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1482
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1483
	switch (condtype) {
359
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1484
		case 0: result = (param_val & (1 << cond_val));
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1485
			break;
359
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1486
		case 1: result = !(param_val & (1 << cond_val));
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1487
			break;
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1488
		/* TODO: For the following, make it to work with paramsize>1. */
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1489
		case 2: result = (param_val == cond_val);
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1490
			break;
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1491
		case 3: result = (param_val != cond_val);
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1492
			break;
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1493
		case 4: result = (param_val < cond_val);
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1494
			break;
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1495
		case 5: result = (param_val > cond_val);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1496
			break;
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  1497
		case 6: result = param_val; /* GRFID is active (only for param-num=88) */
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  1498
			break;
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  1499
		case 7: result = !param_val; /* GRFID is not active (only for param-num=88) */
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  1500
			break;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1501
		default:
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1502
			grfmsg(GMS_WARN, "Unsupported test %d. Ignoring.", condtype);
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1503
			return;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1504
	}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1505
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1506
	if (result == 0) {
359
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1507
		grfmsg(GMS_NOTICE, "Not skipping sprites, test was false.");
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1508
		return;
359
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1509
	}
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1510
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1511
	numsprites = grf_load_byte(&buf);
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  1512
	grfmsg(GMS_NOTICE, "Skipping %d sprites, test was true.", numsprites);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1513
	_skip_sprites = numsprites;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1514
	if (_skip_sprites == 0) {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1515
		/* Zero means there are no sprites to skip, so
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1516
		 * we use -1 to indicate that all further
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1517
		 * sprites should be skipped. */
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1518
		_skip_sprites = -1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1519
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1520
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1521
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1522
static void GRFInfo(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1523
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1524
	/* <08> <version> <grf-id> <name> <info>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1525
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1526
	 * B version       newgrf version, currently 06
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1527
	 * 4*B grf-id      globally unique ID of this .grf file
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1528
	 * S name          name of this .grf set
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1529
	 * S info          string describing the set, and e.g. author and copyright */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1530
	/* TODO: Check version. (We should have own versioning done somehow.) */
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1531
	uint8 version;
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  1532
	uint32 grfid;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1533
	char *name;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1534
	char *info;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1535
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1536
	check_length(len, 9, "GRFInfo");
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1537
	version = buf[1];
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  1538
	/* this is de facto big endian - grf_load_dword() unsuitable */
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1539
	grfid = buf[2] << 24 | buf[3] << 16 | buf[4] << 8 | buf[5];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1540
	name = buf + 6;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1541
	info = name + strlen(name) + 1;
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  1542
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  1543
	_cur_grffile->grfid = grfid;
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  1544
	_cur_grffile->flags |= 0x0001; /* set active flag */
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  1545
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1546
	DEBUG(grf, 1) ("[%s] Loaded GRFv%d set %08lx - %s:\n%s\n",
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  1547
	               _cur_grffile->filename, version, grfid, name, info);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1548
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1549
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1550
static void SpriteReplace(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1551
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1552
	/* <0A> <num-sets> <set1> [<set2> ...]
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1553
	 * <set>: <num-sprites> <first-sprite>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1554
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1555
	 * B num-sets      How many sets of sprites to replace.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1556
	 * Each set:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1557
	 * B num-sprites   How many sprites are in this set
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1558
	 * W first-sprite  First sprite number to replace */
361
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  1559
	uint8 num_sets;
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  1560
	int i;
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  1561
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  1562
	buf++; /* skip action byte */
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  1563
	num_sets = grf_load_byte(&buf);
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  1564
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  1565
	if (num_sets > 16) {
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  1566
		grfmsg(GMS_ERROR, "SpriteReplace: Too many sets (%d), taking only the first 16!", num_sets);
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  1567
	}
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  1568
	
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  1569
	for (i = 0; i < 16; i++) {
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  1570
		if (i < num_sets) {
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  1571
			uint8 num_sprites = grf_load_byte(&buf);
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  1572
			uint16 first_sprite = grf_load_word(&buf);
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  1573
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  1574
			_replace_sprites_count[i] = num_sprites;
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  1575
			_replace_sprites_offset[i] = first_sprite;
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  1576
			grfmsg(GMS_NOTICE, "SpriteReplace: [Set %d] Changing %d sprites, beginning with %d",
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  1577
					i, num_sprites, first_sprite);
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  1578
		} else {
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  1579
			_replace_sprites_count[i] = 0;
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  1580
			_replace_sprites_offset[i] = 0;
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  1581
		}
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  1582
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1583
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1584
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1585
static void GRFError(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1586
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1587
	/* <0B> <severity> <language-id> <message-id> [<message...> 00] [<data...>] 00 [<parnum>]
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1588
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1589
	 * B severity      00: notice, contine loading grf file
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1590
	 *                 01: warning, continue loading grf file
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1591
	 *                 02: error, but continue loading grf file, and attempt
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1592
	 *                     loading grf again when loading or starting next game
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1593
	 *                 03: error, abort loading and prevent loading again in
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1594
	 *                     the future (only when restarting the patch)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1595
	 * B language-id   see action 4, use 1F for built-in error messages
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1596
	 * B message-id    message to show, see below
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1597
	 * S message       for custom messages (message-id FF), text of the message
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1598
	 *                 not present for built-in messages.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1599
	 * V data          additional data for built-in (or custom) messages
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1600
	 * B parnum        see action 6, only used with built-in message 03 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1601
	/* TODO: For now we just show the message, sometimes incomplete and never translated. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1602
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1603
	static const char * const msgstr[4] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1604
		"Requires at least pseudo-TTDPatch version %s.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1605
		"This file is for %s version of TTD.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1606
		"Designed to be used with %s.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1607
		"Invalid parameter %s.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1608
	};
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1609
	uint8 severity;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1610
	uint8 msgid;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1611
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1612
	check_length(len, 6, "GRFError");
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1613
	severity = buf[1];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1614
	msgid = buf[3];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1615
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  1616
	if (msgid == 0xFF) {
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1617
		grfmsg(severity, "%s", buf+4);
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1618
	} else {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1619
		grfmsg(severity, msgstr[msgid], buf+4);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1620
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1621
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1622
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1623
static void GRFComment(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1624
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1625
	/* <0C> [<ignored...>]
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1626
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1627
	 * V ignored       Anything following the 0C is ignored */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1628
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1629
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1630
/* Action 0x0D */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1631
static void ParamSet(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1632
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1633
	/* <0D> <target> <operation> <source1> <source2> [<data>]
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1634
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1635
	 * B target        parameter number where result is stored
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1636
	 * B operation     operation to perform, see below
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1637
	 * B source1       first source operand
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1638
	 * B source2       second source operand
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1639
	 * D data          data to use in the calculation, not necessary
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1640
	 *                 if both source1 and source2 refer to actual parameters
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1641
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1642
	 * Operations
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1643
	 * 00      Set parameter equal to source1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1644
	 * 01      Addition, source1 + source2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1645
	 * 02      Subtraction, source1 - source2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1646
	 * 03      Unsigned multiplication, source1 * source2 (both unsigned)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1647
	 * 04      Signed multiplication, source1 * source2 (both signed)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1648
	 * 05      Unsigned bit shift, source1 by source2 (source2 taken to be a
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1649
	 *         signed quantity; left shift if positive and right shift if
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1650
	 *         negative, source1 is unsigned)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1651
	 * 06      Signed bit shift, source1 by source2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1652
	 *         (source2 like in 05, and source1 as well)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1653
	 */
362
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1654
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1655
	byte target;
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1656
	byte oper;
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1657
	uint16 src1;
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1658
	uint16 src2;
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1659
	uint16 data = 0;
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1660
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1661
	check_length(len, 5, "ParamSet");
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1662
	target = grf_load_byte(&buf);
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1663
	oper = grf_load_byte(&buf);
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1664
	src1 = grf_load_byte(&buf);
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1665
	src2 = grf_load_byte(&buf);
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1666
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1667
	if (len >= 8)
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1668
		data = grf_load_dword(&buf);
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1669
	
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1670
	/* You can add 80 to the operation to make it apply only if the target
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1671
	 * is not defined yet.  In this respect, a parameter is taken to be
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1672
	 * defined if any of the following applies:
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1673
	 * - it has been set to any value in the newgrf(w).cfg parameter list
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1674
	 * - it OR A PARAMETER WITH HIGHER NUMBER has been set to any value by
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1675
	 *   an earlier action D */
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1676
	if (oper & 0x80) {
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1677
		if (_param_max < target)
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1678
			oper &= 0x7F;
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1679
		else
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1680
			return;
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1681
	}
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1682
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1683
	/* The source1 and source2 operands refer to the grf parameter number
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1684
	 * like in action 6 and 7.  In addition, they can refer to the special
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1685
	 * variables available in action 7, or they can be FF to use the value
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1686
	 * of <data>.  If referring to parameters that are undefined, a value
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1687
	 * of 0 is used instead.  */
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1688
	if (src1 == 0xFF) {
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1689
		src1 = data;
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1690
	} else {
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1691
		src1 = _param_max >= src1 ? _paramlist[src1] : 0;
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1692
	}
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1693
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1694
	if (src2 == 0xFF) {
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1695
		src2 = data;
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1696
	} else {
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1697
		src2 = _param_max >= src2 ? _paramlist[src2] : 0;
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1698
	}
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1699
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1700
	/* TODO: You can access the parameters of another GRF file by using
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1701
	 * source2=FE, source1=the other GRF's parameter number and data=GRF
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1702
	 * ID.  This is only valid with operation 00 (set).  If the GRF ID
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1703
	 * cannot be found, a value of 0 is used for the parameter value
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1704
	 * instead. */
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1705
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1706
	/* TODO: The target operand can also refer to the special variables
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1707
	 * from action 7, but at the moment the only variable that is valid to
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1708
	 * write is 8E. */
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1709
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1710
	if (_param_max < target)
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1711
		_param_max = target;
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1712
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1713
	/* FIXME: No checking for overflows. */
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1714
	switch (oper) {
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1715
		case 0x00:
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1716
			_paramlist[target] = src1;
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1717
			break;
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1718
		case 0x01:
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1719
			_paramlist[target] = src1 + src2;
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1720
			break;
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1721
		case 0x02:
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1722
			_paramlist[target] = src1 - src2;
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1723
			break;
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1724
		case 0x03:
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1725
			_paramlist[target] = ((uint32) src1) * ((uint32) src2);
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1726
			break;
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1727
		case 0x04:
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1728
			_paramlist[target] = ((int32) src1) * ((int32) src2);
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1729
			break;
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1730
		case 0x05:
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1731
			if (src2 & 0x8000) /* src2 is "negative" */
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1732
				_paramlist[target] = src1 >> -((int16) src2);
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1733
			else
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1734
				_paramlist[target] = src1 << src2;
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1735
			break;
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1736
		case 0x06:
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1737
			if (src2 & 0x8000) /* src2 is "negative" */
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1738
				_paramlist[target] = ((int16) src1) >> -((int16) src2);
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1739
			else
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1740
				_paramlist[target] = ((int16) src1) << src2;
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1741
			break;
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1742
		default:
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1743
			grfmsg(GMS_ERROR, "ParamSet: Unknown operation %d, skipping.", oper);
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  1744
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1745
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1746
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1747
static void GRFInhibit(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1748
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1749
	/* <0E> <num> <grfids...>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1750
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1751
	 * B num           Number of GRFIDs that follow
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1752
	 * D grfids        GRFIDs of the files to deactivate */
367
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  1753
	/* XXX: Should we handle forward deactivations? */
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  1754
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  1755
	byte num;
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  1756
	int i;
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  1757
	
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  1758
	check_length(len, 1, "GRFInhibit");
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  1759
	num = grf_load_byte(&buf); len--;
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  1760
	check_length(len, 4 * num, "GRFInhibit");
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  1761
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  1762
	for (i = 0; i < num; i++) {
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  1763
		uint32 grfid = grf_load_dword(&buf);
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  1764
		struct GRFFile *file = GetFileByGRFID(grfid);
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  1765
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  1766
		/* Unset activation flag */
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  1767
		if (file != NULL) {
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  1768
			grfmsg(GMS_NOTICE, "GRFInhibit: Deactivating file ``%s''", file->filename);
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  1769
			file->flags &= 0xFFFE;
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  1770
		}
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  1771
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1772
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1773
363
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
  1774
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
  1775
static void InitializeGRFSpecial(void)
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
  1776
{
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
  1777
	/* FIXME: We should rather reflect reality in _ttdpatch_flags[]. */
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
  1778
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
  1779
	_ttdpatch_flags[1] = (1 << 0x08)	/* mammothtrains */
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
  1780
		| (1 << 0x0B)			/* subsidiaries */
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
  1781
		| (1 << 0x14)			/* bridgespeedlimits */
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
  1782
		| (1 << 0x16)			/* eternalgame */
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
  1783
		| (1 << 0x17)			/* newtrains */
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
  1784
		| (1 << 0x18)			/* newrvs */
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
  1785
		| (1 << 0x19)			/* newships */
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
  1786
		| (1 << 0x1A);		/* newplanes */
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
  1787
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
  1788
	_ttdpatch_flags[2] = (1 << 0x0D)	/* signalsontrafficside */
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
  1789
		| (1 << 0x16)			/* canals */
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
  1790
		| (1 << 0x17);		/* newstartyear */
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
  1791
}
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
  1792
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1793
void InitNewGRFFile(const char *filename, int sprite_offset)
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1794
{
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  1795
	struct GRFFile *newfile;
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  1796
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1797
	newfile = calloc(1, sizeof(struct GRFFile));
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  1798
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  1799
	if (newfile == NULL)
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  1800
		error ("Out of memory");
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  1801
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  1802
	newfile->filename = strdup(filename);
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  1803
	newfile->sprite_offset = sprite_offset;
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  1804
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  1805
	if (_first_grffile == NULL) {
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  1806
		_cur_grffile = newfile;
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  1807
		_first_grffile = newfile;
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  1808
	} else {
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  1809
		_cur_grffile->next = newfile;
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  1810
		_cur_grffile = newfile;
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  1811
	}
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  1812
}
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  1813
363
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
  1814
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1815
/* Here we perform initial decoding of some special sprites (as are they
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1816
 * described at http://www.ttdpatch.net/src/newgrf.txt, but this is only a very
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1817
 * partial implementation yet). */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1818
/* XXX: We consider GRF files trusted. It would be trivial to exploit OTTD by
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1819
 * a crafted invalid GRF file. We should tell that to the user somehow, or
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1820
 * better make this more robust in the future. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1821
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1822
void DecodeSpecialSprite(const char *filename, int num, int spriteid, int stage)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1823
{
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  1824
#define NUM_ACTIONS 0xF
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1825
	static const SpecialSpriteHandler handlers[NUM_ACTIONS] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1826
		/* 0x0 */ VehicleChangeInfo,
369
ab2266938fa8 (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  1827
		/* 0x1 */ NewSpriteSet,
ab2266938fa8 (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  1828
		/* 0x2 */ NewSpriteGroup,
ab2266938fa8 (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  1829
		/* 0x3 */ NewVehicle_SpriteGroupMapping,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1830
		/* 0x4 */ VehicleNewName,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1831
		/* 0x5 */ GraphicsNew,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1832
		/* 0x6 */ CfgApply,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1833
		/* 0x7 */ SkipIf,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1834
		/* 0x8 */ GRFInfo,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1835
		/* 0x9 */ SkipIf,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1836
		/* 0xa */ SpriteReplace,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1837
		/* 0xb */ GRFError,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1838
		/* 0xc */ GRFComment,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1839
		/* 0xd */ ParamSet,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1840
		/* 0xe */ GRFInhibit,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1841
	};
363
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
  1842
	static int initialized;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1843
	byte action;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1844
	byte *buf = malloc(num);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1845
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1846
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1847
	if (buf == NULL) error("DecodeSpecialSprite: Could not allocate memory");
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1848
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1849
	if (initialized == 0) {
363
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
  1850
		InitializeGRFSpecial();
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
  1851
		initialized = 1;
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
  1852
	}
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
  1853
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1854
	_cur_stage = stage;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1855
	_cur_spriteid = spriteid;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1856
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1857
	for (i = 0; i != num; i++)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1858
		buf[i] = FioReadByte();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1859
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1860
	action = buf[0];
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1861
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1862
	/* XXX: There is a difference between staged loading in TTDPatch and
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1863
	 * here.  In TTDPatch, for some reason actions 1 and 2 are carried out
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1864
	 * during stage 0, whilst action 3 is carried out during stage 1 (to
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1865
	 * "resolve" cargo IDs... wtf). This is a little problem, because cargo
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1866
	 * IDs are valid only within a given set (action 1) block, and may be
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1867
	 * overwritten after action 3 associates them. But overwriting happens
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1868
	 * in an earlier stage than associating, so...  We just process actions
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1869
	 * 1 and 2 in stage 1 now, let's hope that won't get us into problems.
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1870
	 * --pasky */
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1871
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1872
	if (stage == 0) {
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1873
		/* During initialization, actions 0, 1, 2, 3, 4, 5 and 7 are ignored. */
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1874
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1875
		if ((action == 0x00) || (action == 0x01) || (action == 0x02) || (action == 0x03)
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1876
		    || (action == 0x04) || (action == 0x05) || (action == 0x07)) {
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1877
			DEBUG (grf, 7) ("DecodeSpecialSprite: Action: %x, Stage 0, Skipped", action);
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1878
			/* Do nothing. */
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1879
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1880
		} else if (action < NUM_ACTIONS) {
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1881
			DEBUG (grf, 7) ("DecodeSpecialSprite: Action: %x, Stage 0", action);
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1882
 			handlers[action](buf, num);
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1883
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1884
		} else {
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1885
			grfmsg(GMS_WARN, "Unknown special sprite action %x, skipping.", action);
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1886
		}
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1887
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1888
	} else if (stage == 1) {
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1889
		/* A .grf file is activated only if it was active when the game was
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1890
		 * started.  If a game is loaded, only its active .grfs will be
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1891
		 * reactivated, unless "loadallgraphics on" is used.  A .grf file is
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1892
		 * considered active if its action 8 has been processed, i.e. its
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1893
		 * action 8 hasn't been skipped using an action 7.
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1894
		 *
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1895
		 * During activation, only actions 0, 1, 2, 3, 4, 5, 7, 8, 9 and 0A are
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1896
		 * carried out.  All others are ignored, because they only need to be
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1897
		 * processed once at initialization.  */
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1898
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1899
		if ((_cur_grffile == NULL) || strcmp(_cur_grffile->filename, filename))
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1900
			_cur_grffile = GetFileByFilename(filename);
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1901
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1902
		if (_cur_grffile == NULL)
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1903
			error("File ``%s'' lost in cache.\n", filename);
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1904
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1905
		if (!(_cur_grffile->flags & 0x0001)) {
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1906
			DEBUG (grf, 7) ("DecodeSpecialSprite: Action: %x, Stage 1, Not activated", action);
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1907
			/* Do nothing. */
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1908
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1909
		} else if ((action == 0x00) || (action == 0x01) || (action == 0x02) || (action == 0x03)
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1910
			   || (action == 0x04) || (action == 0x05) || (action == 0x07) || (action == 0x08)
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1911
			   || (action == 0x09) || (action == 0x0A)) {
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1912
			DEBUG (grf, 7) ("DecodeSpecialSprite: Action: %x, Stage 1", action);
367
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  1913
			handlers[action](buf, num);
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1914
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1915
		} else if (action < NUM_ACTIONS) {
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1916
			DEBUG (grf, 7) ("DecodeSpecialSprite: Action: %x, Stage 1, Skipped", action);
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1917
			/* Do nothing. */
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1918
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1919
		} else {
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1920
			grfmsg(GMS_WARN, "Unknown special sprite action %x, skipping.", action);
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1921
		}
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1922
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1923
	} else {
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1924
		error("Invalid stage %d", stage);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1925
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1926
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1927
	free(buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1928
#undef NUM_ACTIONS
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1929
}