1
0
Fork 0

(svn r677) -newgrf: Fix some custom electric trains appearing in maglev depots (pasky).

release/0.4.5
darkvater 2004-11-19 19:13:32 +00:00
parent d51daeab1a
commit 249438be88
3 changed files with 50 additions and 57 deletions

20
ai.c
View File

@ -113,25 +113,19 @@ static void AiStateVehLoop(Player *p)
p->ai.state_counter = 0; p->ai.state_counter = 0;
} }
// XXX
static const byte _rail_locos_count[3] = {
27, 3, 5
};
extern const byte _rail_engines_start[3];
static int AiChooseTrainToBuild(byte railtype, int32 money, byte flag) static int AiChooseTrainToBuild(byte railtype, int32 money, byte flag)
{ {
int best_veh_index = -1; int best_veh_index = -1;
byte best_veh_score = 0; byte best_veh_score = 0;
int32 r; int32 r;
int i;
int i = _rail_engines_start[railtype]; for (i = 0; i < NUM_TRAIN_ENGINES; i++) {
int end = i + _rail_locos_count[railtype]; RailVehicleInfo *rvi = &rail_vehinfo(i);
Engine *e = &_engines[i]; Engine *e = DEREF_ENGINE(i);
do {
assert(!(_rail_vehicle_info[i].flags & RVI_WAGON));
if (!HASBIT(e->player_avail, _current_player) || e->reliability < 0x8A3D) if (e->railtype != railtype || rvi->flags & RVI_WAGON
|| !HASBIT(e->player_avail, _current_player) || e->reliability < 0x8A3D)
continue; continue;
r = DoCommandByTile(0, i, 0, 0, CMD_BUILD_RAIL_VEHICLE); r = DoCommandByTile(0, i, 0, 0, CMD_BUILD_RAIL_VEHICLE);
@ -142,7 +136,7 @@ static int AiChooseTrainToBuild(byte railtype, int32 money, byte flag)
best_veh_score = _cmd_build_rail_veh_score; best_veh_score = _cmd_build_rail_veh_score;
best_veh_index = i; best_veh_index = i;
} }
} while (++e, ++i != end); }
return best_veh_index; return best_veh_index;
} }

View File

@ -15,14 +15,16 @@ void DrawShipEngineInfo(int engine, int x, int y, int maxw);
StringID GetEngineCategoryName(byte engine) StringID GetEngineCategoryName(byte engine)
{ {
if (engine < NUM_NORMAL_RAIL_ENGINES) if (engine < NUM_TRAIN_ENGINES) {
return STR_8102_RAILROAD_LOCOMOTIVE; switch (_engines[engine].railtype) {
case 0:
if (engine < NUM_NORMAL_RAIL_ENGINES + NUM_MONORAIL_ENGINES) return STR_8102_RAILROAD_LOCOMOTIVE;
return STR_8106_MONORAIL_LOCOMOTIVE; case 1:
return STR_8106_MONORAIL_LOCOMOTIVE;
if (engine < NUM_TRAIN_ENGINES) case 2:
return STR_8107_MAGLEV_LOCOMOTIVE; return STR_8107_MAGLEV_LOCOMOTIVE;
}
}
if (engine < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES) if (engine < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES)
return STR_8103_ROAD_VEHICLE; return STR_8103_ROAD_VEHICLE;

View File

@ -14,23 +14,6 @@
int _traininfo_vehicle_pitch = 0; int _traininfo_vehicle_pitch = 0;
static Engine * const _rail_engines[3] = {
&_engines[0],
&_engines[NUM_NORMAL_RAIL_ENGINES],
&_engines[NUM_MONORAIL_ENGINES + NUM_NORMAL_RAIL_ENGINES],
};
const byte _rail_engines_count[3] = {
NUM_NORMAL_RAIL_ENGINES,
NUM_MONORAIL_ENGINES,
NUM_MAGLEV_ENGINES,
};
const byte _rail_engines_start[3] = {
0,
NUM_NORMAL_RAIL_ENGINES,
NUM_MONORAIL_ENGINES + NUM_NORMAL_RAIL_ENGINES,
};
static void CcBuildWagon(bool success, uint tile, uint32 p1, uint32 p2) static void CcBuildWagon(bool success, uint tile, uint32 p1, uint32 p2)
{ {
@ -85,12 +68,15 @@ static void NewRailVehicleWndProc(Window *w, WindowEvent *e)
{ {
int count = 0; int count = 0;
int num = _rail_engines_count[WP(w,buildtrain_d).railtype]; byte railtype = WP(w,buildtrain_d).railtype;
Engine *e = _rail_engines[WP(w,buildtrain_d).railtype]; int i;
do {
if (HASBIT(e->player_avail, _local_player)) for (i = 0; i < NUM_TRAIN_ENGINES; i++) {
Engine *e = &_engines[i];
if (e->railtype == railtype
&& HASBIT(e->player_avail, _local_player))
count++; count++;
} while (++e,--num); }
SetVScrollCount(w, count); SetVScrollCount(w, count);
} }
@ -98,26 +84,37 @@ static void NewRailVehicleWndProc(Window *w, WindowEvent *e)
DrawWindowWidgets(w); DrawWindowWidgets(w);
{ {
int num = _rail_engines_count[WP(w,buildtrain_d).railtype]; byte railtype = WP(w,buildtrain_d).railtype;
Engine *e = _rail_engines[WP(w,buildtrain_d).railtype];
int sel = WP(w,buildtrain_d).sel_index; int sel = WP(w,buildtrain_d).sel_index;
int pos = w->vscroll.pos; int pos = w->vscroll.pos;
int x = 1; int x = 1;
int y = 15; int y = 15;
int engine_id = _rail_engines_start[WP(w,buildtrain_d).railtype];
int selected_id = -1; int selected_id = -1;
int i;
do { /* Ensure that custom engines which substituted wagons
if (HASBIT(e->player_avail, _local_player)) { * are sorted correctly. */
if (sel==0) selected_id = engine_id; #define engine_drawing_loop(cmp_) \
if (IS_INT_INSIDE(--pos, -8, 0)) { for (i = 0; i < NUM_TRAIN_ENGINES; i++) { \
DrawString(x+59, y+2, GetCustomEngineName(engine_id), sel==0 ? 0xC : 0x10); Engine *e = DEREF_ENGINE(i); \
DrawTrainEngine(x+29, y+6+_traininfo_vehicle_pitch, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player))); RailVehicleInfo *rvi = &rail_vehinfo(i); \
y += 14; \
} if (e->railtype != railtype || (rvi->flags & RVI_WAGON) cmp_ 0 \
sel--; || !HASBIT(e->player_avail, _local_player)) \
} continue; \
} while (++engine_id, ++e,--num); \
if (sel == 0) selected_id = i; \
if (IS_INT_INSIDE(--pos, -8, 0)) { \
DrawString(x+59, y+2, GetCustomEngineName(i), sel == 0 ? 0xC : 0x10); \
DrawTrainEngine(x+29, y+6+_traininfo_vehicle_pitch, i, \
SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player))); \
y += 14; \
} \
sel--; \
}
engine_drawing_loop(!=); // True engines
engine_drawing_loop(==); // Feeble wagons
WP(w,buildtrain_d).sel_engine = selected_id; WP(w,buildtrain_d).sel_engine = selected_id;