(svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.

this also fixes some window updates issues when autoreplacing
This commit is contained in:
bjarni 2005-01-23 22:01:51 +00:00
parent 3554e28ad8
commit cf862380fc
7 changed files with 103 additions and 45 deletions

View File

@ -269,6 +269,8 @@ int32 CmdBuildAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2)
InvalidateWindow(WC_COMPANY, v->owner); InvalidateWindow(WC_COMPANY, v->owner);
} }
InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Aircraft); //updates the replace Aircraft window
return value; return value;
} }
@ -322,6 +324,8 @@ int32 CmdSellAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2)
} }
InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Aircraft); // updates the replace Aircraft window
return -(int32)v->value; return -(int32)v->value;
} }

View File

@ -188,6 +188,8 @@ int32 CmdBuildRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2)
InvalidateWindow(WC_COMPANY, v->owner); InvalidateWindow(WC_COMPANY, v->owner);
} }
InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Road); // updates the replace Road window
return cost; return cost;
} }
@ -234,6 +236,7 @@ int32 CmdSellRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2)
DeleteWindowById(WC_VEHICLE_VIEW, v->index); DeleteWindowById(WC_VEHICLE_VIEW, v->index);
DeleteVehicle(v); DeleteVehicle(v);
} }
InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Road); // updates the replace Road window
return -(int32)v->value; return -(int32)v->value;
} }

View File

@ -877,6 +877,7 @@ int32 CmdBuildShip(int x, int y, uint32 flags, uint32 p1, uint32 p2)
RebuildVehicleLists(); RebuildVehicleLists();
InvalidateWindow(WC_COMPANY, v->owner); InvalidateWindow(WC_COMPANY, v->owner);
} }
InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Ship); // updates the replace Ship window
return value; return value;
} }
@ -903,6 +904,8 @@ int32 CmdSellShip(int x, int y, uint32 flags, uint32 p1, uint32 p2)
DeleteVehicle(v); DeleteVehicle(v);
} }
InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Ship); // updates the replace Ship window
return -(int32)v->value; return -(int32)v->value;
} }

View File

@ -486,6 +486,9 @@ int32 CmdBuildRailVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
} }
_cmd_build_rail_veh_var1 = _railveh_unk1[p1]; _cmd_build_rail_veh_var1 = _railveh_unk1[p1];
_cmd_build_rail_veh_score = _railveh_score[p1]; _cmd_build_rail_veh_score = _railveh_score[p1];
InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Train); // updates the replace Train window
return value; return value;
} }
@ -847,6 +850,7 @@ int32 CmdSellRailWagon(int x, int y, uint32 flags, uint32 p1, uint32 p2)
} }
if (last) cost -= last->value; if (last) cost -= last->value;
} }
InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Train); // updates the replace Train window
return cost; return cost;
} }
@ -2399,8 +2403,10 @@ static void HandleCrashedTrain(Vehicle *v)
ChangeTrainDirRandomly(v); ChangeTrainDirRandomly(v);
} }
if (state >= 4440 && !(v->tick_counter&0x1F)) if (state >= 4440 && !(v->tick_counter&0x1F)) {
DeleteLastWagon(v); DeleteLastWagon(v);
InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Train);
}
} }
static void HandleBrokenTrain(Vehicle *v) static void HandleBrokenTrain(Vehicle *v)

View File

@ -431,7 +431,8 @@ VARDEF byte _vehicle_design_names;
#define MAX_BRIDGES 13 #define MAX_BRIDGES 13
/* Autoreplace vehicle stuff*/ /* Autoreplace vehicle stuff*/
VARDEF byte _autoreplace_array[255]; VARDEF byte _autoreplace_array[256];
VARDEF uint16 _player_num_engines[256];
/* Debugging levels */ /* Debugging levels */
VARDEF int _debug_spritecache_level; VARDEF int _debug_spritecache_level;

View File

@ -1449,6 +1449,7 @@ int32 CmdReplaceVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
byte capacity = rvi->capacity; byte capacity = rvi->capacity;
Vehicle *first = GetFirstVehicleInChain(v); Vehicle *first = GetFirstVehicleInChain(v);
//if (v->owner == _local_player) InvalidateWindowClasses(WC_TRAINS_LIST);
/* rvi->image_index is the new sprite for the engine. Adding +1 makes the engine head the other way /* rvi->image_index is the new sprite for the engine. Adding +1 makes the engine head the other way
if it is a multiheaded engine (rear engine) if it is a multiheaded engine (rear engine)
(rvi->flags & RVI_MULTIHEAD && sprite - rvi2->image_index) is true if the engine is heading the other way, otherwise 0*/ (rvi->flags & RVI_MULTIHEAD && sprite - rvi2->image_index) is true if the engine is heading the other way, otherwise 0*/
@ -1507,7 +1508,7 @@ int32 CmdReplaceVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
veh->u.rail.first_engine = new_engine_type; veh->u.rail.first_engine = new_engine_type;
} while ( (veh=veh->next) != NULL ); } while ( (veh=veh->next) != NULL );
} }
InvalidateWindowClasses(WC_TRAINS_LIST);
break; break;
} }
case VEH_Road: case VEH_Road:
@ -1518,6 +1519,7 @@ int32 CmdReplaceVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
v->cargo_type = rvi->cargo_type; v->cargo_type = rvi->cargo_type;
v->cargo_cap = rvi->capacity; v->cargo_cap = rvi->capacity;
v->max_speed = rvi->max_speed; v->max_speed = rvi->max_speed;
InvalidateWindowClasses(WC_ROADVEH_LIST);
break; break;
} }
case VEH_Ship: case VEH_Ship:
@ -1533,6 +1535,7 @@ int32 CmdReplaceVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
// since we do not stop it for autorefitting // since we do not stop it for autorefitting
if (v->cargo_type != cargo_type) if (v->cargo_type != cargo_type)
CmdRefitShip(v->x_pos, v->y_pos, DC_EXEC, v->index , cargo_type + 0x0100 ); CmdRefitShip(v->x_pos, v->y_pos, DC_EXEC, v->index , cargo_type + 0x0100 );
InvalidateWindowClasses(WC_SHIPS_LIST);
break; break;
} }
case VEH_Aircraft: case VEH_Aircraft:
@ -1553,6 +1556,7 @@ int32 CmdReplaceVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
// since we do not stop it for autorefitting // since we do not stop it for autorefitting
CmdRefitAircraft(v->x_pos, v->y_pos, DC_EXEC, v->index , cargo_type + 0x0100 ); CmdRefitAircraft(v->x_pos, v->y_pos, DC_EXEC, v->index , cargo_type + 0x0100 );
} }
InvalidateWindowClasses(WC_AIRCRAFT_LIST);
break; break;
} }
default: return CMD_ERROR; default: return CMD_ERROR;
@ -1565,6 +1569,8 @@ int32 CmdReplaceVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
v->cargo_count = v->cargo_cap; v->cargo_count = v->cargo_cap;
} }
} }
InvalidateWindow(WC_REPLACE_VEHICLE, v->type);
ResortVehicleLists();
} }
//needs to be down here because refitting will change SET_EXPENSES_TYPE if called //needs to be down here because refitting will change SET_EXPENSES_TYPE if called
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);

View File

@ -324,6 +324,8 @@ static void train_engine_drawing_loop(int *x, int *y, int *pos, int *sel, int *s
const RailVehicleInfo *rvi = RailVehInfo(i); const RailVehicleInfo *rvi = RailVehInfo(i);
const EngineInfo *info = &_engine_info[i]; const EngineInfo *info = &_engine_info[i];
if ( _player_num_engines[i] == 0 && show_outdated ) continue;
if ( rvi->power == 0 && !(show_cars) ) // disables display of cars (works since they do not have power) if ( rvi->power == 0 && !(show_cars) ) // disables display of cars (works since they do not have power)
continue; continue;
@ -346,6 +348,10 @@ static void train_engine_drawing_loop(int *x, int *y, int *pos, int *sel, int *s
colour); colour);
DrawTrainEngine(*x + 29, *y + 6, i, DrawTrainEngine(*x + 29, *y + 6, i,
SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player))); SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)));
if ( show_outdated ) {
SetDParam(0, _player_num_engines[i]);
DrawStringRightAligned(213, *y+5, STR_TINY_BLACK, 0);
}
*y += 14; *y += 14;
} }
--*sel; --*sel;
@ -376,8 +382,10 @@ static void SetupScrollStuffForReplaceWindow(Window *w)
if (ENGINE_AVAILABLE && RailVehInfo(engine_id)->power && e->railtype == railtype ) { if (ENGINE_AVAILABLE && RailVehInfo(engine_id)->power && e->railtype == railtype ) {
count++; count++;
if ( _player_num_engines[engine_id] ) {
if (sel[0]==0) selected_id[0] = engine_id; if (sel[0]==0) selected_id[0] = engine_id;
sel[0]--; sel[0]--;
}
if (HASBIT(e->player_avail, _local_player)) { if (HASBIT(e->player_avail, _local_player)) {
if (sel[1]==0) selected_id[1] = engine_id; if (sel[1]==0) selected_id[1] = engine_id;
count2++; count2++;
@ -396,7 +404,7 @@ static void SetupScrollStuffForReplaceWindow(Window *w)
do { do {
info = &_engine_info[engine_id]; info = &_engine_info[engine_id];
if (ENGINE_AVAILABLE) { if (_player_num_engines[engine_id] ) {
if (sel[0]==0) selected_id[0] = engine_id; if (sel[0]==0) selected_id[0] = engine_id;
count++; count++;
sel[0]--; sel[0]--;
@ -429,7 +437,7 @@ static void SetupScrollStuffForReplaceWindow(Window *w)
do { do {
info = &_engine_info[engine_id]; info = &_engine_info[engine_id];
if (ENGINE_AVAILABLE) { if (_player_num_engines[engine_id] ) {
if ( sel[0] == 0 ) selected_id[0] = engine_id; if ( sel[0] == 0 ) selected_id[0] = engine_id;
count++; count++;
sel[0]--; sel[0]--;
@ -465,7 +473,7 @@ static void SetupScrollStuffForReplaceWindow(Window *w)
do { do {
info = &_engine_info[engine_id]; info = &_engine_info[engine_id];
if (ENGINE_AVAILABLE) { if (_player_num_engines[engine_id]) {
count++; count++;
if (sel[0]==0) selected_id[0] = engine_id; if (sel[0]==0) selected_id[0] = engine_id;
sel[0]--; sel[0]--;
@ -543,12 +551,16 @@ static void DrawEngineArrayInReplaceWindow(Window *w, int x, int y, int x2, int
do { do {
info = &_engine_info[engine_id]; info = &_engine_info[engine_id];
if (ENGINE_AVAILABLE) { if (_player_num_engines[engine_id]) {
if (IS_INT_INSIDE(--pos, -w->vscroll.cap, 0)) { if (IS_INT_INSIDE(--pos, -w->vscroll.cap, 0)) {
DrawString(x+59, y+2, GetCustomEngineName(engine_id), sel[0]==0 ? 0xC : 0x10); DrawString(x+59, y+2, GetCustomEngineName(engine_id), sel[0]==0 ? 0xC : 0x10);
DrawRoadVehEngine(x+29, y+6, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player))); DrawRoadVehEngine(x+29, y+6, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)));
SetDParam(0, _player_num_engines[engine_id]);
DrawStringRightAligned(213, y+5, STR_TINY_BLACK, 0);
y += 14; y += 14;
} }
sel[0]--;
}
if ( RoadVehInfo(engine_id)->cargo_type == cargo && HASBIT(e->player_avail, _local_player) ) { if ( RoadVehInfo(engine_id)->cargo_type == cargo && HASBIT(e->player_avail, _local_player) ) {
if (IS_INT_INSIDE(--pos2, -w->vscroll.cap, 0) && RoadVehInfo(engine_id)->cargo_type == cargo) { if (IS_INT_INSIDE(--pos2, -w->vscroll.cap, 0) && RoadVehInfo(engine_id)->cargo_type == cargo) {
@ -558,8 +570,6 @@ static void DrawEngineArrayInReplaceWindow(Window *w, int x, int y, int x2, int
} }
sel[1]--; sel[1]--;
} }
sel[0]--;
}
} while (++engine_id, ++e,--num); } while (++engine_id, ++e,--num);
} }
break; break;
@ -578,12 +588,16 @@ static void DrawEngineArrayInReplaceWindow(Window *w, int x, int y, int x2, int
do { do {
info = &_engine_info[engine_id]; info = &_engine_info[engine_id];
if (ENGINE_AVAILABLE) { if (_player_num_engines[engine_id]) {
if (IS_INT_INSIDE(--pos, -w->vscroll.cap, 0)) { if (IS_INT_INSIDE(--pos, -w->vscroll.cap, 0)) {
DrawString(x+75, y+7, GetCustomEngineName(engine_id), sel[0]==0 ? 0xC : 0x10); DrawString(x+75, y+7, GetCustomEngineName(engine_id), sel[0]==0 ? 0xC : 0x10);
DrawShipEngine(x+35, y+10, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player))); DrawShipEngine(x+35, y+10, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)));
SetDParam(0, _player_num_engines[engine_id]);
DrawStringRightAligned(213, y+15, STR_TINY_BLACK, 0);
y += 24; y += 24;
} }
sel[0]--;
}
if ( selected_id[0] != -1 ) { if ( selected_id[0] != -1 ) {
if (HASBIT(e->player_avail, _local_player) && ( cargo == ShipVehInfo(engine_id)->cargo_type || refittable & ShipVehInfo(engine_id)->refittable)) { if (HASBIT(e->player_avail, _local_player) && ( cargo == ShipVehInfo(engine_id)->cargo_type || refittable & ShipVehInfo(engine_id)->refittable)) {
if (IS_INT_INSIDE(--pos2, -w->vscroll.cap, 0)) { if (IS_INT_INSIDE(--pos2, -w->vscroll.cap, 0)) {
@ -594,8 +608,6 @@ static void DrawEngineArrayInReplaceWindow(Window *w, int x, int y, int x2, int
sel[1]--; sel[1]--;
} }
} }
sel[0]--;
}
} while (++engine_id, ++e,--num); } while (++engine_id, ++e,--num);
} }
break; break;
@ -611,13 +623,17 @@ static void DrawEngineArrayInReplaceWindow(Window *w, int x, int y, int x2, int
do { do {
info = &_engine_info[engine_id]; info = &_engine_info[engine_id];
if (ENGINE_AVAILABLE) { if (_player_num_engines[engine_id]) {
if (sel[0]==0) selected_id[0] = engine_id; if (sel[0]==0) selected_id[0] = engine_id;
if (IS_INT_INSIDE(--pos, -w->vscroll.cap, 0)) { if (IS_INT_INSIDE(--pos, -w->vscroll.cap, 0)) {
DrawString(x+62, y+7, GetCustomEngineName(engine_id), sel[0]==0 ? 0xC : 0x10); DrawString(x+62, y+7, GetCustomEngineName(engine_id), sel[0]==0 ? 0xC : 0x10);
DrawAircraftEngine(x+29, y+10, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player))); DrawAircraftEngine(x+29, y+10, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)));
SetDParam(0, _player_num_engines[engine_id]);
DrawStringRightAligned(213, y+15, STR_TINY_BLACK, 0);
y += 24; y += 24;
} }
sel[0]--;
}
if ( ((subtype && AircraftVehInfo(engine_id)->subtype) || (!(subtype) && !AircraftVehInfo(engine_id)->subtype)) if ( ((subtype && AircraftVehInfo(engine_id)->subtype) || (!(subtype) && !AircraftVehInfo(engine_id)->subtype))
&& HASBIT(e->player_avail, _local_player) ) { && HASBIT(e->player_avail, _local_player) ) {
if (sel[1]==0) selected_id[1] = engine_id; if (sel[1]==0) selected_id[1] = engine_id;
@ -628,8 +644,6 @@ static void DrawEngineArrayInReplaceWindow(Window *w, int x, int y, int x2, int
} }
sel[1]--; sel[1]--;
} }
sel[0]--;
}
} while (++engine_id, ++e,--num); } while (++engine_id, ++e,--num);
} }
break; break;
@ -658,6 +672,27 @@ static void ReplaceVehicleWndProc(Window *w, WindowEvent *e)
sel[0] = WP(w,replaceveh_d).sel_index[0]; sel[0] = WP(w,replaceveh_d).sel_index[0];
sel[1] = WP(w,replaceveh_d).sel_index[1]; sel[1] = WP(w,replaceveh_d).sel_index[1];
{
uint i;
const Vehicle *vehicle;
for (i = 0; i < lengthof(_player_num_engines); i++) {
_player_num_engines[i] = 0;
}
FOR_ALL_VEHICLES(vehicle) {
if ( vehicle->owner == _local_player ) {
if (vehicle->type == VEH_Aircraft && vehicle->subtype > 2) continue;
// do not count the vehicles, that contains only 0 in all var
if (vehicle->engine_type == 0 && vehicle->spritenum == 0 ) continue;
if (vehicle->type != DEREF_ENGINE(vehicle->engine_type)->type) continue;
_player_num_engines[vehicle->engine_type]++;
}
}
}
SetupScrollStuffForReplaceWindow(w); SetupScrollStuffForReplaceWindow(w);
selected_id[0] = WP(w,replaceveh_d).sel_engine[0]; selected_id[0] = WP(w,replaceveh_d).sel_engine[0];