engine.c
changeset 2708 48714bad9499
parent 2639 eeaefdabfdfd
child 2763 a4d065e3261b
equal deleted inserted replaced
2707:06fc91550280 2708:48714bad9499
    15 #include "vehicle.h"
    15 #include "vehicle.h"
    16 #include "news.h"
    16 #include "news.h"
    17 #include "saveload.h"
    17 #include "saveload.h"
    18 #include "sprite.h"
    18 #include "sprite.h"
    19 #include "variables.h"
    19 #include "variables.h"
       
    20 #include "train.h"
    20 
    21 
    21 enum {
    22 enum {
    22 	ENGINE_AVAILABLE = 1,
    23 	ENGINE_AVAILABLE = 1,
    23 	ENGINE_INTRODUCING = 2,
    24 	ENGINE_INTRODUCING = 2,
    24 	ENGINE_PREVIEWING = 4,
    25 	ENGINE_PREVIEWING = 4,
   361 			}
   362 			}
   362 		}
   363 		}
   363 	}
   364 	}
   364 }
   365 }
   365 
   366 
       
   367 static int MapOldSubType(const Vehicle *v)
       
   368 {
       
   369 	if (v->type != VEH_Train) return v->subtype;
       
   370 	if (IsTrainEngine(v)) return 0;
       
   371 	if (IsFreeWagon(v)) return 4;
       
   372 	return 2;
       
   373 }
       
   374 
   366 typedef SpriteGroup *(*resolve_callback)(const SpriteGroup *spritegroup,
   375 typedef SpriteGroup *(*resolve_callback)(const SpriteGroup *spritegroup,
   367 	const Vehicle *veh, uint16 callback_info, void *resolve_func); /* XXX data pointer used as function pointer */
   376 	const Vehicle *veh, uint16 callback_info, void *resolve_func); /* XXX data pointer used as function pointer */
   368 
   377 
   369 static const SpriteGroup* ResolveVehicleSpriteGroup(const SpriteGroup *spritegroup,
   378 static const SpriteGroup* ResolveVehicleSpriteGroup(const SpriteGroup *spritegroup,
   370 	const Vehicle *veh, uint16 callback_info, resolve_callback resolve_func)
   379 	const Vehicle *veh, uint16 callback_info, resolve_callback resolve_func)
   440 					// TTDPatch runs on little-endian arch;
   449 					// TTDPatch runs on little-endian arch;
   441 					// Variable is 0x80 + offset in TTD's vehicle structure
   450 					// Variable is 0x80 + offset in TTD's vehicle structure
   442 					switch (dsg->variable - 0x80) {
   451 					switch (dsg->variable - 0x80) {
   443 #define veh_prop(id_, value_) case (id_): value = (value_); break
   452 #define veh_prop(id_, value_) case (id_): value = (value_); break
   444 						veh_prop(0x00, veh->type);
   453 						veh_prop(0x00, veh->type);
   445 						veh_prop(0x01, veh->subtype);
   454 						veh_prop(0x01, MapOldSubType(veh));
   446 						veh_prop(0x04, veh->index);
   455 						veh_prop(0x04, veh->index);
   447 						veh_prop(0x05, veh->index & 0xFF);
   456 						veh_prop(0x05, veh->index & 0xFF);
   448 						/* XXX? Is THIS right? */
   457 						/* XXX? Is THIS right? */
   449 						veh_prop(0x0A, PackOrder(&veh->current_order));
   458 						veh_prop(0x0A, PackOrder(&veh->current_order));
   450 						veh_prop(0x0B, PackOrder(&veh->current_order) & 0xff);
   459 						veh_prop(0x0B, PackOrder(&veh->current_order) & 0xff);