diff options
author | rubidium <rubidium@openttd.org> | 2007-08-30 13:03:56 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2007-08-30 13:03:56 +0000 |
commit | cb7eaff3534c1d18c9c8bc06be04ceb437d97765 (patch) | |
tree | 141633b357757cb790c904dc033f8479d58ba5e5 | |
parent | ac5fde61fb03059daee4b505dcaad84f21b93857 (diff) | |
download | openttd-cb7eaff3534c1d18c9c8bc06be04ceb437d97765.tar.xz |
(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
-rw-r--r-- | src/ai/default/default.cpp | 6 | ||||
-rw-r--r-- | src/aircraft_cmd.cpp | 32 | ||||
-rw-r--r-- | src/aircraft_gui.cpp | 4 | ||||
-rw-r--r-- | src/articulated_vehicles.cpp | 8 | ||||
-rw-r--r-- | src/autoreplace_cmd.cpp | 12 | ||||
-rw-r--r-- | src/depot_gui.cpp | 4 | ||||
-rw-r--r-- | src/disaster_cmd.cpp | 4 | ||||
-rw-r--r-- | src/economy.cpp | 8 | ||||
-rw-r--r-- | src/group_cmd.cpp | 4 | ||||
-rw-r--r-- | src/newgrf_engine.cpp | 24 | ||||
-rw-r--r-- | src/rail_cmd.cpp | 4 | ||||
-rw-r--r-- | src/road_cmd.cpp | 2 | ||||
-rw-r--r-- | src/roadveh.h | 2 | ||||
-rw-r--r-- | src/roadveh_cmd.cpp | 26 | ||||
-rw-r--r-- | src/roadveh_gui.cpp | 8 | ||||
-rw-r--r-- | src/train.h | 6 | ||||
-rw-r--r-- | src/train_cmd.cpp | 80 | ||||
-rw-r--r-- | src/train_gui.cpp | 10 | ||||
-rw-r--r-- | src/vehicle.cpp | 26 | ||||
-rw-r--r-- | src/vehicle.h | 25 | ||||
-rw-r--r-- | src/vehicle_gui.cpp | 16 |
21 files changed, 164 insertions, 147 deletions
diff --git a/src/ai/default/default.cpp b/src/ai/default/default.cpp index b28e2a2b8..87306b6bc 100644 --- a/src/ai/default/default.cpp +++ b/src/ai/default/default.cpp @@ -261,8 +261,8 @@ static EngineID AiChooseTrainToReplaceWith(const Player* p, const Vehicle* v) const Vehicle* u = v; int num = 0; - while (++num, u->next != NULL) { - u = u->next; + while (++num, u->Next() != NULL) { + u = u->Next(); } // XXX: check if a wagon @@ -2496,7 +2496,7 @@ handle_nocash: // Sell a vehicle if the train is double headed. v = GetVehicle(loco_id); - if (v->next != NULL) { + if (v->Next() != NULL) { i = p->ai.wagon_list[p->ai.num_wagons * 2 - 2]; p->ai.wagon_list[p->ai.num_wagons * 2 - 2] = INVALID_VEHICLE; DoCommand(tile, i, 0, DC_EXEC, CMD_SELL_RAIL_WAGON); diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index 672d52176..24c2a6110 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -171,7 +171,7 @@ SpriteID GetRotorImage(const Vehicle *v) { assert(v->subtype == AIR_HELICOPTER); - const Vehicle *w = v->next->next; + const Vehicle *w = v->Next()->Next(); if (is_custom_sprite(v->spritenum)) { SpriteID spritenum = GetCustomRotorSprite(v, false); if (spritenum != 0) return spritenum; @@ -678,7 +678,7 @@ CommandCost CmdRefitAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) if (flags & DC_EXEC) { v->cargo_cap = pass; - Vehicle *u = v->next; + Vehicle *u = v->Next(); uint mail = IsCargoInClass(new_cid, CC_PASSENGERS) ? avi->mail_capacity : 0; u->cargo_cap = mail; v->cargo.Truncate(v->cargo_type == new_cid ? pass : 0); @@ -771,13 +771,13 @@ static void AgeAircraftCargo(Vehicle *v) do { v->cargo.AgeCargo(); - v = v->next; + v = v->Next(); } while (v != NULL); } static void HelicopterTickHandler(Vehicle *v) { - Vehicle *u = v->next->next; + Vehicle *u = v->Next()->Next(); if (u->vehstatus & VS_HIDDEN) return; @@ -829,13 +829,13 @@ static void SetAircraftPosition(Vehicle *v, int x, int y, int z) v->z_pos = z; v->cur_image = v->GetImage(v->direction); - if (v->subtype == AIR_HELICOPTER) v->next->next->cur_image = GetRotorImage(v); + if (v->subtype == AIR_HELICOPTER) v->Next()->Next()->cur_image = GetRotorImage(v); BeginVehicleMove(v); VehiclePositionChanged(v); EndVehicleMove(v); - Vehicle *u = v->next; + Vehicle *u = v->Next(); int safe_x = clamp(x, 0, MapMaxX() * TILE_SIZE); int safe_y = clamp(y - 1, 0, MapMaxY() * TILE_SIZE); @@ -850,7 +850,7 @@ static void SetAircraftPosition(Vehicle *v, int x, int y, int z) VehiclePositionChanged(u); EndVehicleMove(u); - u = u->next; + u = u->Next(); if (u != NULL) { u->x_pos = x; u->y_pos = y; @@ -870,9 +870,9 @@ void HandleAircraftEnterHangar(Vehicle *v) v->subspeed = 0; v->progress = 0; - Vehicle *u = v->next; + Vehicle *u = v->Next(); u->vehstatus |= VS_HIDDEN; - u = u->next; + u = u->Next(); if (u != NULL) { u->vehstatus |= VS_HIDDEN; u->cur_speed = 0; @@ -1057,7 +1057,7 @@ static bool AircraftController(Vehicle *v) /* Helicopter raise */ if (amd->flag & AMED_HELI_RAISE) { - Vehicle *u = v->next->next; + Vehicle *u = v->Next()->Next(); /* Make sure the rotors don't rotate too fast */ if (u->cur_speed > 32) { @@ -1101,7 +1101,7 @@ static bool AircraftController(Vehicle *v) int z = GetSlopeZ(x, y) + 1 + afc->delta_z; if (z == v->z_pos) { - Vehicle *u = v->next->next; + Vehicle *u = v->Next()->Next(); /* Increase speed of rotors. When speed is 80, we've landed. */ if (u->cur_speed >= 80) return true; @@ -1411,7 +1411,7 @@ static void ProcessAircraftOrder(Vehicle *v) void Aircraft::MarkDirty() { this->cur_image = this->GetImage(this->direction); - if (this->subtype == AIR_HELICOPTER) this->next->next->cur_image = GetRotorImage(this); + if (this->subtype == AIR_HELICOPTER) this->Next()->Next()->cur_image = GetRotorImage(this); MarkAllViewportsDirty(this->left_coord, this->top_coord, this->right_coord + 1, this->bottom_coord + 1); } @@ -1429,7 +1429,7 @@ static void CrashAirplane(Vehicle *v) SetDParam(0, amt); v->cargo.Truncate(0); - v->next->cargo.Truncate(0); + v->Next()->cargo.Truncate(0); const Station *st = GetStation(v->u.air.targetairport); StringID newsitem; if (st->airport_tile == 0) { @@ -1527,11 +1527,11 @@ static void AircraftLeaveHangar(Vehicle *v) v->direction = DIR_SE; v->vehstatus &= ~VS_HIDDEN; { - Vehicle *u = v->next; + Vehicle *u = v->Next(); u->vehstatus &= ~VS_HIDDEN; /* Rotor blades */ - u = u->next; + u = u->Next(); if (u != NULL) { u->vehstatus &= ~VS_HIDDEN; u->cur_speed = 80; @@ -2155,7 +2155,7 @@ void UpdateOldAircraft() v_oldstyle->tile = 0; // aircraft in air is tile=0 /* correct speed of helicopter-rotors */ - if (v_oldstyle->subtype == AIR_HELICOPTER) v_oldstyle->next->next->cur_speed = 32; + if (v_oldstyle->subtype == AIR_HELICOPTER) v_oldstyle->Next()->Next()->cur_speed = 32; /* set new position x,y,z */ SetAircraftPosition(v_oldstyle, gp.x, gp.y, GetAircraftFlyingAltitude(v_oldstyle)); diff --git a/src/aircraft_gui.cpp b/src/aircraft_gui.cpp index 28813eb12..b161c84a7 100644 --- a/src/aircraft_gui.cpp +++ b/src/aircraft_gui.cpp @@ -133,7 +133,7 @@ static void AircraftDetailsWndProc(Window *w, WindowEvent *e) SetDParam(0, v->cargo_type); SetDParam(1, v->cargo_cap); - u = v->next; + u = v->Next(); SetDParam(2, u->cargo_type); SetDParam(3, u->cargo_cap); DrawString(60, y, (u->cargo_cap != 0) ? STR_A019_CAPACITY : STR_A01A_CAPACITY, 0); @@ -151,7 +151,7 @@ static void AircraftDetailsWndProc(Window *w, WindowEvent *e) y += 10; } - } while ( (v=v->next) != NULL); + } while ((v = v->Next()) != NULL); } } break; diff --git a/src/articulated_vehicles.cpp b/src/articulated_vehicles.cpp index 2fad99769..6fdfb1339 100644 --- a/src/articulated_vehicles.cpp +++ b/src/articulated_vehicles.cpp @@ -41,11 +41,11 @@ void AddArticulatedParts(Vehicle **vl, VehicleType type) /* Attempt to use pre-allocated vehicles until they run out. This can happen * if the callback returns different values depending on the cargo type. */ - u->next = vl[i]; - if (u->next == NULL) u->next = new InvalidVehicle(); - if (u->next == NULL) return; + u->SetNext(vl[i]); + if (u->Next() == NULL) u->SetNext(new InvalidVehicle()); + if (u->Next() == NULL) return; - u = u->next; + u = u->Next(); EngineID engine_type = GetFirstEngineOfType(type) + GB(callback, 0, 7); bool flip_image = HASBIT(callback, 7); diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp index 0b9552d62..606a60126 100644 --- a/src/autoreplace_cmd.cpp +++ b/src/autoreplace_cmd.cpp @@ -42,9 +42,9 @@ static void MoveVehicleCargo(Vehicle *dest, Vehicle *source) dest->day_counter = source->day_counter; dest->tick_counter = source->tick_counter; - } while (source->cargo.Count() > 0 && (dest = dest->next) != NULL); + } while (source->cargo.Count() > 0 && (dest = dest->Next()) != NULL); dest = v; - } while ((source = source->next) != NULL); + } while ((source = source->Next()) != NULL); /* * The of the train will be incorrect at this moment. This is due @@ -110,7 +110,7 @@ static CargoID GetNewCargoTypeForReplace(Vehicle *v, EngineID engine_type) /* Now we found a cargo type being carried on the train and we will see if it is possible to carry to this one */ if (v->cargo_type == new_cargo_type) return CT_NO_REFIT; if (CanRefitTo(engine_type, v->cargo_type)) return v->cargo_type; - } while ((v = v->next) != NULL); + } while ((v = v->Next()) != NULL); return CT_NO_REFIT; // We failed to find a cargo type on the old vehicle and we will not refit the new one } @@ -189,7 +189,7 @@ static CommandCost ReplaceVehicle(Vehicle **w, byte flags, Money total_cost) } } - if (new_v->type == VEH_TRAIN && HASBIT(old_v->u.rail.flags, VRF_REVERSE_DIRECTION) && !IsMultiheaded(new_v) && !(new_v->next != NULL && IsArticulatedPart(new_v->next))) { + if (new_v->type == VEH_TRAIN && HASBIT(old_v->u.rail.flags, VRF_REVERSE_DIRECTION) && !IsMultiheaded(new_v) && !(new_v->Next() != NULL && IsArticulatedPart(new_v->Next()))) { // we are autorenewing to a single engine, so we will turn it as the old one was turned as well SETBIT(new_v->u.rail.flags, VRF_REVERSE_DIRECTION); } @@ -247,12 +247,12 @@ static CommandCost ReplaceVehicle(Vehicle **w, byte flags, Money total_cost) } } else { // flags & DC_EXEC not set CommandCost tmp_move; - if (old_v->type == VEH_TRAIN && IsFrontEngine(old_v) && old_v->next != NULL) { + if (old_v->type == VEH_TRAIN && IsFrontEngine(old_v) && old_v->Next() != NULL) { /* Verify that the wagons can be placed on the engine in question. * This is done by building an engine, test if the wagons can be added and then sell the test engine. */ DoCommand(old_v->tile, new_engine_type, 3, DC_EXEC, GetCmdBuildVeh(old_v)); Vehicle *temp = GetVehicle(_new_vehicle_id); - tmp_move = DoCommand(0, (temp->index << 16) | old_v->next->index, 1, 0, CMD_MOVE_RAIL_VEHICLE); + tmp_move = DoCommand(0, (temp->index << 16) | old_v->Next()->index, 1, 0, CMD_MOVE_RAIL_VEHICLE); DoCommand(0, temp->index, 0, DC_EXEC, GetCmdSellVeh(old_v)); } diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index 7f47d54d0..0ca889b78 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -279,7 +279,7 @@ static void DrawDepotWindow(Window *w) /*Draw the train counter */ i = 0; u = v; - do i++; while ( (u=u->next) != NULL); // Determine length of train + do i++; while ((u = u->Next()) != NULL); // Determine length of train SetDParam(0, i); // Set the counter DrawStringRightAligned(w->widget[DEPOT_WIDGET_MATRIX].right - 1, y + 4, STR_TINY_BLACK, 0); // Draw the counter } @@ -356,7 +356,7 @@ static int GetVehicleFromDepotWndPt(const Window *w, int x, int y, Vehicle **veh x += skip; /* find the vehicle in this row that was clicked */ - while (v != NULL && (x -= v->u.rail.cached_veh_length) >= 0) v = v->next; + while (v != NULL && (x -= v->u.rail.cached_veh_length) >= 0) v = v->Next(); /* if an articulated part was selected, find its parent */ while (v != NULL && IsArticulatedPart(v)) v = GetPrevVehicleInChain(v); diff --git a/src/disaster_cmd.cpp b/src/disaster_cmd.cpp index c274513a7..a88a1bfe8 100644 --- a/src/disaster_cmd.cpp +++ b/src/disaster_cmd.cpp @@ -158,7 +158,7 @@ static void SetDisasterVehiclePos(Vehicle *v, int x, int y, byte z) VehiclePositionChanged(v); EndVehicleMove(v); - if ((u = v->next) != NULL) { + if ((u = v->Next()) != NULL) { int safe_x = clamp(x, 0, MapMaxX() * TILE_SIZE); int safe_y = clamp(y - 1, 0, MapMaxY() * TILE_SIZE); BeginVehicleMove(u); @@ -173,7 +173,7 @@ static void SetDisasterVehiclePos(Vehicle *v, int x, int y, byte z) VehiclePositionChanged(u); EndVehicleMove(u); - if ((u = u->next) != NULL) { + if ((u = u->Next()) != NULL) { BeginVehicleMove(u); u->x_pos = x; u->y_pos = y; diff --git a/src/economy.cpp b/src/economy.cpp index 2a42a13c7..f120feb55 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -1412,7 +1412,7 @@ void VehiclePayment(Vehicle *front_v) /* Start unloading in at the first possible moment */ front_v->load_unload_time_rem = 1; - for (Vehicle *v = front_v; v != NULL; v = v->next) { + for (Vehicle *v = front_v; v != NULL; v = v->Next()) { /* No cargo to unload */ if (v->cargo_cap == 0 || v->cargo.Empty()) continue; @@ -1499,7 +1499,7 @@ static void LoadUnloadVehicle(Vehicle *v, int *cargo_left) if (--v->load_unload_time_rem != 0) { if (_patches.improved_load && HASBIT(v->current_order.flags, OFB_FULL_LOAD)) { /* 'Reserve' this cargo for this vehicle, because we were first. */ - for (; v != NULL; v = v->next) { + for (; v != NULL; v = v->Next()) { if (v->cargo_cap != 0) cargo_left[v->cargo_type] -= v->cargo_cap - v->cargo.Count(); } } @@ -1529,7 +1529,7 @@ static void LoadUnloadVehicle(Vehicle *v, int *cargo_left) StationID last_visited = v->last_station_visited; Station *st = GetStation(last_visited); - for (; v != NULL; v = v->next) { + for (; v != NULL; v = v->Next()) { if (v->cargo_cap == 0) continue; byte load_amount = EngInfo(v->engine_type)->load_amount; @@ -1651,7 +1651,7 @@ static void LoadUnloadVehicle(Vehicle *v, int *cargo_left) * enough to fill the previous wagons) */ if (_patches.improved_load && HASBIT(u->current_order.flags, OFB_FULL_LOAD)) { /* Update left cargo */ - for (v = u; v != NULL; v = v->next) { + for (v = u; v != NULL; v = v->Next()) { if (v->cargo_cap != 0) cargo_left[v->cargo_type] -= v->cargo_cap - v->cargo.Count(); } } diff --git a/src/group_cmd.cpp b/src/group_cmd.cpp index 3ac42e2fd..f27473640 100644 --- a/src/group_cmd.cpp +++ b/src/group_cmd.cpp @@ -371,7 +371,7 @@ void SetTrainGroupID(Vehicle *v, GroupID new_g) assert(v->IsValid() && v->type == VEH_TRAIN && IsFrontEngine(v)); - for (Vehicle *u = v; u != NULL; u = u->next) { + for (Vehicle *u = v; u != NULL; u = u->Next()) { if (IsEngineCountable(u)) UpdateNumEngineGroup(u->engine_type, u->group_id, new_g); u->group_id = new_g; @@ -394,7 +394,7 @@ void UpdateTrainGroupID(Vehicle *v) assert(v->IsValid() && v->type == VEH_TRAIN && (IsFrontEngine(v) || IsFreeWagon(v))); GroupID new_g = IsFrontEngine(v) ? v->group_id : (GroupID)DEFAULT_GROUP; - for (Vehicle *u = v; u != NULL; u = u->next) { + for (Vehicle *u = v; u != NULL; u = u->Next()) { if (IsEngineCountable(u)) UpdateNumEngineGroup(u->engine_type, u->group_id, new_g); u->group_id = new_g; diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp index e51ed4f3f..4f1ef3a05 100644 --- a/src/newgrf_engine.cpp +++ b/src/newgrf_engine.cpp @@ -516,14 +516,14 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by byte chain_before = 0; byte chain_after = 0; - for (u = GetFirstVehicleInChain(v); u != v; u = u->next) { + for (u = GetFirstVehicleInChain(v); u != v; u = u->Next()) { chain_before++; if (variable == 0x41 && u->engine_type != v->engine_type) chain_before = 0; } - while (u->next != NULL && (variable == 0x40 || u->next->engine_type == v->engine_type)) { + while (u->Next() != NULL && (variable == 0x40 || u->Next()->engine_type == v->engine_type)) { chain_after++; - u = u->next; + u = u->Next(); } return chain_before | chain_after << 8 | (chain_before + chain_after + (variable == 0x41)) << 16; @@ -544,7 +544,7 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by memset(common_cargos, 0, sizeof(common_cargos)); memset(common_subtypes, 0, sizeof(common_subtypes)); - for (u = v; u != NULL; u = u->next) { + for (u = v; u != NULL; u = u->Next()) { /* Skip empty engines */ if (u->cargo_cap == 0) continue; @@ -579,7 +579,7 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by if (v->type != VEH_AIRCRAFT) return UINT_MAX; { - const Vehicle *w = v->next; + const Vehicle *w = v->Next(); uint16 altitude = v->z_pos - w->z_pos; // Aircraft height - shadow height byte airporttype; @@ -611,7 +611,7 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by if (v->type != VEH_TRAIN) return 0; const Vehicle *u_p = GetPrevVehicleInChain(v); - const Vehicle *u_n = v->next; + const Vehicle *u_n = v->Next(); DirDiff f = (u_p == NULL) ? DIRDIFF_SAME : DirDifference(u_p->direction, v->direction); DirDiff b = (u_n == NULL) ? DIRDIFF_SAME : DirDifference(v->direction, u_n->direction); DirDiff t = ChangeDirDiff(f, b); @@ -644,7 +644,7 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by { uint count = 0; - for (; v != NULL; v = v->next) { + for (; v != NULL; v = v->Next()) { if (v->engine_type == parameter) count++; } return count; @@ -735,7 +735,7 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by case 0x57: return GB(ClampToI32(v->profit_last_year), 8, 24); case 0x58: return GB(ClampToI32(v->profit_last_year), 16, 16); case 0x59: return GB(ClampToI32(v->profit_last_year), 24, 8); - case 0x5A: return v->next == NULL ? INVALID_VEHICLE : v->next->index; + case 0x5A: return v->Next() == NULL ? INVALID_VEHICLE : v->Next()->index; case 0x5C: return ClampToI32(v->value); case 0x5D: return GB(ClampToI32(v->value), 8, 24); case 0x5E: return GB(ClampToI32(v->value), 16, 16); @@ -914,7 +914,7 @@ SpriteID GetRotorOverrideSprite(EngineID engine, const Vehicle *v, bool info_vie if (v == NULL) return group->g.result.sprite; - return group->g.result.sprite + (info_view ? 0 : (v->next->next->u.air.state % group->g.result.num_sprites)); + return group->g.result.sprite + (info_view ? 0 : (v->Next()->Next()->u.air.state % group->g.result.num_sprites)); } @@ -1040,7 +1040,7 @@ static void DoTriggerVehicle(Vehicle *v, VehicleTrigger trigger, byte base_rando /* We now trigger the next vehicle in chain recursively. * The random bits portions may be different for each * vehicle in chain. */ - if (v->next != NULL) DoTriggerVehicle(v->next, trigger, 0, true); + if (v->Next() != NULL) DoTriggerVehicle(v->Next(), trigger, 0, true); break; case VEHICLE_TRIGGER_EMPTY: @@ -1048,14 +1048,14 @@ static void DoTriggerVehicle(Vehicle *v, VehicleTrigger trigger, byte base_rando * recursively. The random bits portions must be same * for each vehicle in chain, so we give them all * first chained vehicle's portion of random bits. */ - if (v->next != NULL) DoTriggerVehicle(v->next, trigger, first ? new_random_bits : base_random_bits, false); + if (v->Next() != NULL) DoTriggerVehicle(v->Next(), trigger, first ? new_random_bits : base_random_bits, false); break; case VEHICLE_TRIGGER_ANY_NEW_CARGO: /* Now pass the trigger recursively to the next vehicle * in chain. */ assert(!first); - if (v->next != NULL) DoTriggerVehicle(v->next, VEHICLE_TRIGGER_ANY_NEW_CARGO, base_random_bits, false); + if (v->Next() != NULL) DoTriggerVehicle(v->Next(), VEHICLE_TRIGGER_ANY_NEW_CARGO, base_random_bits, false); break; } } diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index f88090ad2..29c44d194 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -2156,7 +2156,7 @@ static uint32 VehicleEnter_Track(Vehicle *v, TileIndex tile, int x, int y) v->u.rail.track = TRACK_BIT_DEPOT, v->vehstatus |= VS_HIDDEN; /* hide it */ v->direction = ReverseDir(v->direction); - if (v->next == NULL) VehicleEnterDepot(v); + if (v->Next() == NULL) VehicleEnterDepot(v); v->tile = tile; InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); @@ -2165,7 +2165,7 @@ static uint32 VehicleEnter_Track(Vehicle *v, TileIndex tile, int x, int y) } else if (fract_coord_leave == fract_coord) { if (DiagDirToDir(dir) == v->direction) { /* leave the depot? */ - if ((v = v->next) != NULL) { + if ((v = v->Next()) != NULL) { v->vehstatus &= ~VS_HIDDEN; v->u.rail.track = (DiagDirToAxis(dir) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y); } diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp index d0a65fea4..00e488629 100644 --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -1342,7 +1342,7 @@ static uint32 VehicleEnter_Road(Vehicle *v, TileIndex tile, int x, int y) v->u.road.state = RVSB_IN_DEPOT; v->vehstatus |= VS_HIDDEN; v->direction = ReverseDir(v->direction); - if (v->next == NULL) VehicleEnterDepot(v); + if (v->Next() == NULL) VehicleEnterDepot(v); v->tile = tile; InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); diff --git a/src/roadveh.h b/src/roadveh.h index 5c62fcee0..1c545ea43 100644 --- a/src/roadveh.h +++ b/src/roadveh.h @@ -41,7 +41,7 @@ static inline void SetRoadVehArticPart(Vehicle *v) static inline bool RoadVehHasArticPart(const Vehicle *v) { assert(v->type == VEH_ROAD); - return v->next != NULL && IsRoadVehArticPart(v->next); + return v->Next() != NULL && IsRoadVehArticPart(v->Next()); } diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index d24de2980..53155c8a1 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -140,7 +140,7 @@ void RoadVehUpdateCache(Vehicle *v) assert(v->type == VEH_ROAD); assert(IsRoadVehFront(v)); - for (Vehicle *u = v; u != NULL; u = u->next) { + for (Vehicle *u = v; u != NULL; u = u->Next()) { /* Update the v->first cache. */ if (u->first == NULL) u->first = v; @@ -338,7 +338,7 @@ static bool CheckRoadVehInDepotStopped(const Vehicle *v) if (!IsTileDepotType(tile, TRANSPORT_ROAD)) return false; if (IsRoadVehFront(v) && !(v->vehstatus & VS_STOPPED)) return false; - for (; v != NULL; v = v->next) { + for (; v != NULL; v = v->Next()) { if (v->u.road.state != RVSB_IN_DEPOT || v->tile != tile) return false; } return true; @@ -556,7 +556,7 @@ CommandCost CmdTurnRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) void RoadVehicle::MarkDirty() { - for (Vehicle *v = this; v != NULL; v = v->next) { + for (Vehicle *v = this; v != NULL; v = v->Next()) { v->cur_image = v->GetImage(v->direction); MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1); } @@ -599,8 +599,8 @@ static void ClearCrashedStation(Vehicle *v) static void DeleteLastRoadVeh(Vehicle *v) { Vehicle *u = v; - for (; v->next != NULL; v = v->next) u = v; - u->next = NULL; + for (; v->Next() != NULL; v = v->Next()) u = v; + u->SetNext(NULL); DeleteWindowById(WC_VEHICLE_VIEW, v->index); @@ -646,7 +646,7 @@ static void RoadVehSetRandomDirection(Vehicle *v) v->UpdateDeltaXY(v->direction); v->cur_image = v->GetImage(v->direction); SetRoadVehPosition(v, v->x_pos, v->y_pos); - } while ((v = v->next) != NULL); + } while ((v = v->Next()) != NULL); } static void RoadVehIsCrashed(Vehicle *v) @@ -679,7 +679,7 @@ static void RoadVehCrash(Vehicle *v) v->u.road.crashed_ctr++; - for (Vehicle *u = v; u != NULL; u = u->next) { + for (Vehicle *u = v; u != NULL; u = u->Next()) { if (IsCargoInClass(u->cargo_type, CC_PASSENGERS)) pass += u->cargo.Count(); u->vehstatus |= VS_CRASHED; @@ -706,7 +706,7 @@ static void RoadVehCrash(Vehicle *v) static void RoadVehCheckTrainCrash(Vehicle *v) { - for (Vehicle *u = v; u != NULL; u = u->next) { + for (Vehicle *u = v; u != NULL; u = u->Next()) { if (u->u.road.state == RVSB_WORMHOLE) continue; TileIndex tile = u->tile; @@ -1333,7 +1333,7 @@ static const byte _road_veh_data_1[] = { static bool RoadVehLeaveDepot(Vehicle *v, bool first) { /* Don't leave if not all the wagons are in the depot. */ - for (const Vehicle *u = v; u != NULL; u = u->next) { + for (const Vehicle *u = v; u != NULL; u = u->Next()) { if (u->u.road.state != RVSB_IN_DEPOT || u->tile != v->tile) return false; } @@ -1627,11 +1627,11 @@ again: /* This vehicle is not in a wormhole and it hasn't entered a new tile. If * it's on a depot tile, check if it's time to activate the next vehicle in * the chain yet. */ - if (v->next != NULL && + if (v->Next() != NULL && IsTileType(v->tile, MP_ROAD) && GetRoadTileType(v->tile) == ROAD_TILE_DEPOT) { if (v->u.road.frame == v->u.road.cached_veh_length + RVC_DEPOT_START_FRAME) { - RoadVehLeaveDepot(v->next, false); + RoadVehLeaveDepot(v->Next(), false); } } @@ -1822,7 +1822,7 @@ static void RoadVehController(Vehicle *v) /* Check if vehicle needs to proceed, return if it doesn't */ if (!RoadVehAccelerate(v)) return; - for (Vehicle *prev = NULL; v != NULL; prev = v, v = v->next) { + for (Vehicle *prev = NULL; v != NULL; prev = v, v = v->Next()) { if (!IndividualRoadVehicleController(v, prev)) break; } } @@ -2029,7 +2029,7 @@ CommandCost CmdRefitRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) SET_EXPENSES_TYPE(EXPENSES_ROADVEH_RUN); - for (; v != NULL; v = v->next) { + for (; v != NULL; v = v->Next()) { /* XXX: We refit all the attached wagons en-masse if they can be * refitted. This is how TTDPatch does it. TODO: Have some nice * [Refit] button near each wagon. */ diff --git a/src/roadveh_gui.cpp b/src/roadveh_gui.cpp index f67d81e02..331053605 100644 --- a/src/roadveh_gui.cpp +++ b/src/roadveh_gui.cpp @@ -46,7 +46,7 @@ void DrawRoadVehImage(const Vehicle *v, int x, int y, int count, VehicleID selec } dx += length; - v = v->next; + v = v->Next(); } while (v != NULL && dx < max_length); } @@ -65,7 +65,7 @@ static void RoadVehDetailsWndProc(Window *w, WindowEvent *e) /* Add space for the cargo amount for each part. */ do { height_extension += 11; - } while ((v = v->next) != NULL); + } while ((v = v->Next()) != NULL); ResizeWindow(w, 0, height_extension); } break; @@ -128,7 +128,7 @@ static void RoadVehDetailsWndProc(Window *w, WindowEvent *e) memset(max_cargo, 0, sizeof(max_cargo)); - for (const Vehicle *u = v; u != NULL; u = u->next) { + for (const Vehicle *u = v; u != NULL; u = u->Next()) { max_cargo[u->cargo_type] += u->cargo_cap; } @@ -153,7 +153,7 @@ static void RoadVehDetailsWndProc(Window *w, WindowEvent *e) SetDParamStr(0, capacity); DrawStringTruncated(34, 67 + y_offset, STR_JUST_STRING, 0, w->width - 34); - for (const Vehicle *u = v; u != NULL; u = u->next) { + for (const Vehicle *u = v; u != NULL; u = u->Next()) { str = STR_8812_EMPTY; if (!u->cargo.Empty()) { SetDParam(0, u->cargo_type); diff --git a/src/train.h b/src/train.h index 1983b99ff..55ef18663 100644 --- a/src/train.h +++ b/src/train.h @@ -200,7 +200,7 @@ static inline void ClearMultiheaded(Vehicle *v) static inline bool EngineHasArticPart(const Vehicle *v) { assert(v->type == VEH_TRAIN); - return (v->next != NULL && IsArticulatedPart(v->next)); + return (v->Next() != NULL && IsArticulatedPart(v->Next())); } /** @@ -211,7 +211,7 @@ static inline bool EngineHasArticPart(const Vehicle *v) static inline Vehicle *GetNextArticPart(const Vehicle *v) { assert(EngineHasArticPart(v)); - return v->next; + return v->Next(); } /** Get the last part of a multi-part engine. @@ -235,7 +235,7 @@ static inline Vehicle *GetNextVehicle(const Vehicle *v) while (EngineHasArticPart(v)) v = GetNextArticPart(v); /* v now contains the last artic part in the engine */ - return v->next; + return v->Next(); } void ConvertOldMultiheadToNew(); diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index f1c428ff5..2733a7c92 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -70,7 +70,7 @@ void TrainPowerChanged(Vehicle* v) uint32 total_power = 0; uint32 max_te = 0; - for (const Vehicle *u = v; u != NULL; u = u->next) { + for (const Vehicle *u = v; u != NULL; u = u->Next()) { /* Power is not added for articulated parts */ if (IsArticulatedPart(u)) continue; @@ -112,7 +112,7 @@ static void TrainCargoChanged(Vehicle* v) { uint32 weight = 0; - for (Vehicle *u = v; u != NULL; u = u->next) { + for (Vehicle *u = v; u != NULL; u = u->Next()) { uint32 vweight = GetCargo(u->cargo_type)->weight * u->cargo.Count() * FreightWagonMult(u->cargo_type) / 16; /* Vehicle weight is not added for articulated parts. */ @@ -158,7 +158,7 @@ void TrainConsistChanged(Vehicle* v) v->u.rail.cached_total_length = 0; v->u.rail.compatible_railtypes = 0; - for (Vehicle *u = v; u != NULL; u = u->next) { + for (Vehicle *u = v; u != NULL; u = u->Next()) { const RailVehicleInfo *rvi_u = RailVehInfo(u->engine_type); /* Update the v->first cache. This is faster than having to brute force it later. */ @@ -235,7 +235,7 @@ void TrainConsistChanged(Vehicle* v) veh_len = GetVehicleCallback(CBID_VEHICLE_LENGTH, 0, 0, u->engine_type, u); } if (veh_len == CALLBACK_FAILED) veh_len = rvi_u->shorten_factor; - veh_len = clamp(veh_len, 0, u->next == NULL ? 7 : 5); // the clamp on vehicles not the last in chain is stricter, as too short wagons can break the 'follow next vehicle' code + veh_len = clamp(veh_len, 0, u->Next() == NULL ? 7 : 5); // the clamp on vehicles not the last in chain is stricter, as too short wagons can break the 'follow next vehicle' code u->u.rail.cached_veh_length = 8 - veh_len; v->u.rail.cached_total_length += u->u.rail.cached_veh_length; } @@ -309,9 +309,9 @@ static int GetTrainAcceleration(Vehicle *v, bool mode) int sum = 0; int pos = 0; int lastpos = -1; - for (const Vehicle *u = v; u->next != NULL; u = u->next, pos++) { + for (const Vehicle *u = v; u->Next() != NULL; u = u->Next(), pos++) { Direction dir = u->direction; - Direction ndir = u->next->direction; + Direction ndir = u->Next()->direction; int i; for (i = 0; i < 2; i++) { @@ -371,7 +371,7 @@ static int GetTrainAcceleration(Vehicle *v, bool mode) int num = 0; //number of vehicles, change this into the number of axles later int incl = 0; int drag_coeff = 20; //[1e-4] - for (const Vehicle *u = v; u != NULL; u = u->next) { + for (const Vehicle *u = v; u != NULL; u = u->Next()) { num++; drag_coeff += 3; @@ -792,7 +792,7 @@ int CheckTrainInDepot(const Vehicle *v, bool needs_to_be_stopped) if (!IsTileDepotType(tile, TRANSPORT_RAIL) || v->cur_speed != 0) return -1; int count = 0; - for (; v != NULL; v = v->next) { + for (; v != NULL; v = v->Next()) { /* This count is used by the depot code to determine the number of engines * in the consist. Exclude articulated parts so that autoreplacing to * engines with more articulated parts than before works correctly. @@ -857,7 +857,7 @@ static Vehicle *FindGoodVehiclePos(const Vehicle *src) Vehicle *v = dst; while (v->engine_type == eng) { - v = v->next; + v = v->Next(); if (v == NULL) return dst; } } @@ -875,8 +875,8 @@ static void AddWagonToConsist(Vehicle *v, Vehicle *dest) UnlinkWagon(v, GetFirstVehicleInChain(v)); if (dest == NULL) return; - v->next = dest->next; - dest->next = v; + v->SetNext(dest->Next()); + dest->SetNext(v); ClearFreeWagon(v); ClearFrontEngine(v); } @@ -896,7 +896,7 @@ static void NormaliseTrainConsist(Vehicle *v) /* make sure that there are no free cars before next engine */ Vehicle *u; - for (u = v; u->next != NULL && !IsTrainEngine(u->next); u = u->next) {} + for (u = v; u->Next() != NULL && !IsTrainEngine(u->Next()); u = u->Next()) {} if (u == v->u.rail.other_multiheaded_part) continue; AddWagonToConsist(v->u.rail.other_multiheaded_part, u); @@ -1023,8 +1023,8 @@ CommandCost CmdMoveRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p /* do it? */ if (flags & DC_EXEC) { /* clear the ->first cache */ - for (Vehicle *u = src_head; u != NULL; u = u->next) u->first = NULL; - for (Vehicle *u = dst_head; u != NULL; u = u->next) u->first = NULL; + for (Vehicle *u = src_head; u != NULL; u = u->Next()) u->first = NULL; + for (Vehicle *u = dst_head; u != NULL; u = u->Next()) u->first = NULL; /* If we move the front Engine and if the second vehicle is not an engine add the whole vehicle to the DEFAULT_GROUP */ @@ -1097,13 +1097,13 @@ CommandCost CmdMoveRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p Vehicle *v; for (v = src; GetNextVehicle(v) != NULL; v = GetNextVehicle(v)); - GetLastEnginePart(v)->next = dst->next; + GetLastEnginePart(v)->SetNext(dst->Next()); } - dst->next = src; + dst->SetNext(src); } if (src->u.rail.other_multiheaded_part != NULL) { if (src->u.rail.other_multiheaded_part == src_head) { - src_head = src_head->next; + src_head = src_head->Next(); } AddWagonToConsist(src->u.rail.other_multiheaded_part, src); /* previous line set the front engine to the old front. We need to clear that */ @@ -1263,7 +1263,7 @@ CommandCost CmdSellRailWagon(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) Vehicle *new_f = GetNextVehicle(first); /* 2.1 If the first wagon is sold, update the first-> pointers to NULL */ - for (Vehicle *tmp = first; tmp != NULL; tmp = tmp->next) tmp->first = NULL; + for (Vehicle *tmp = first; tmp != NULL; tmp = tmp->Next()) tmp->first = NULL; /* 2.2 If there are wagons present after the deleted front engine, check * if the second wagon (which will be first) is an engine. If it is one, @@ -1470,8 +1470,8 @@ static void ReverseTrainSwapVeh(Vehicle *v, int l, int r) Vehicle *a, *b; /* locate vehicles to swap */ - for (a = v; l != 0; l--) a = a->next; - for (b = v; r != 0; r--) b = b->next; + for (a = v; l != 0; l--) a = a->Next(); + for (b = v; r != 0; r--) b = b->Next(); if (a != b) { /* swap the hidden bits */ @@ -1539,30 +1539,30 @@ static void DisableTrainCrossing(TileIndex tile) static void AdvanceWagons(Vehicle *v, bool before) { Vehicle *base = v; - Vehicle *first = base->next; + Vehicle *first = base->Next(); uint length = CountVehiclesInChain(v); while (length > 2) { /* find pairwise matching wagon * start<>end, start+1<>end-1, ... */ Vehicle *last = first; - for (uint i = length - 3; i > 0; i--) last = last->next; + for (uint i = length - 3; i > 0; i--) last = last->Next(); int differential = last->u.rail.cached_veh_length - base->u.rail.cached_veh_length; if (before) differential *= -1; if (differential > 0) { /* disconnect last car to make sure only this subset moves */ - Vehicle *tempnext = last->next; - last->next = NULL; + Vehicle *tempnext = last->Next(); + last->SetNext(NULL); for (int i = 0; i < differential; i++) TrainController(first, false); - last->next = tempnext; + last->SetNext(tempnext); } base = first; - first = first->next; + first = first->Next(); length -= 2; } } @@ -1593,7 +1593,7 @@ static void ReverseTrainDirection(Vehicle *v) /* count number of vehicles */ int r = -1; const Vehicle *u = v; - do r++; while ( (u = u->next) != NULL ); + do r++; while ((u = u->Next()) != NULL); AdvanceWagons(v, true); @@ -1772,7 +1772,7 @@ CommandCost CmdRefitRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 } } } - } while ((v = v->next) != NULL && !only_this); + } while ((v = v->Next()) != NULL && !only_this); _returned_refit_capacity = num; @@ -2017,7 +2017,7 @@ static void HandleLocomotiveSmokeCloud(const Vehicle* v) } break; } - } while ((v = v->next) != NULL); + } while ((v = v->Next()) != NULL); if (sound) PlayVehicleSound(u, VSE_TRAIN_EFFECT); } @@ -2046,7 +2046,7 @@ void Train::PlayLeaveStationSound() const static bool CheckTrainStayInDepot(Vehicle *v) { /* bail out if not all wagons are in the same depot or not in a depot at all */ - for (const Vehicle *u = v; u != NULL; u = u->next) { + for (const Vehicle *u = v; u != NULL; u = u->Next()) { if (u->u.rail.track != TRACK_BIT_DEPOT || u->tile != v->tile) return false; } @@ -2470,7 +2470,7 @@ void Train::MarkDirty() do { v->cur_image = v->GetImage(v->direction); MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1); - } while ((v = v->next) != NULL); + } while ((v = v->Next()) != NULL); /* need to update acceleration and cached values since the goods on the train changed. */ TrainCargoChanged(this); @@ -2756,7 +2756,7 @@ static void CheckTrainCollision(Vehicle *v) TrainCollideChecker tcc; tcc.v = v; - tcc.v_skip = v->next; + tcc.v_skip = v->Next(); tcc.num = 0; /* find colliding vehicles */ @@ -2807,7 +2807,7 @@ static void TrainController(Vehicle *v, bool update_image) Vehicle *prev; /* For every vehicle after and including the given vehicle */ - for (prev = GetPrevVehicleInChain(v); v != NULL; prev = v, v = v->next) { + for (prev = GetPrevVehicleInChain(v); v != NULL; prev = v, v = v->Next()) { DiagDirection enterdir = DIAGDIR_BEGIN; bool update_signals = false; BeginVehicleMove(v); @@ -2934,7 +2934,7 @@ static void TrainController(Vehicle *v, bool update_image) goto invalid_rail; } - if (IsLevelCrossingTile(v->tile) && v->next == NULL) { + if (IsLevelCrossingTile(v->tile) && v->Next() == NULL) { UnbarCrossing(v->tile); MarkTileDirtyByTile(v->tile); } @@ -2997,7 +2997,7 @@ static void TrainController(Vehicle *v, bool update_image) /* Signals can only change when the first * (above) or the last vehicle moves. */ - if (v->next == NULL) TrainMovedChangeSignals(gp.old_tile, ReverseDiagDir(enterdir)); + if (v->Next() == NULL) TrainMovedChangeSignals(gp.old_tile, ReverseDiagDir(enterdir)); } } return; @@ -3028,8 +3028,8 @@ static void DeleteLastWagon(Vehicle *v) * *u is then the one-before-last wagon, and *v the last * one which will physicially be removed */ Vehicle *u = v; - for (; v->next != NULL; v = v->next) u = v; - u->next = NULL; + for (; v->Next() != NULL; v = v->Next()) u = v; + u->SetNext(NULL); InvalidateWindow(WC_VEHICLE_DETAILS, v->index); DeleteWindowById(WC_VEHICLE_VIEW, v->index); @@ -3090,7 +3090,7 @@ static void ChangeTrainDirRandomly(Vehicle *v) the bridge in that case */ if (v->u.rail.track != TRACK_BIT_WORMHOLE) AfterSetTrainPos(v, false); } - } while ((v = v->next) != NULL); + } while ((v = v->Next()) != NULL); } static void HandleCrashedTrain(Vehicle *v) @@ -3117,7 +3117,7 @@ static void HandleCrashedTrain(Vehicle *v) EV_EXPLOSION_SMALL); break; } - } while ((u = u->next) != NULL); + } while ((u = u->Next()) != NULL); } if (state <= 240 && !(v->tick_counter & 3)) ChangeTrainDirRandomly(v); @@ -3498,7 +3498,7 @@ void ConnectMultiheadedTrains() } Vehicle *w; - for (w = u->next; w != NULL && (w->engine_type != u->engine_type || w->u.rail.other_multiheaded_part != NULL); w = GetNextVehicle(w)); + for (w = u->Next(); w != NULL && (w->engine_type != u->engine_type || w->u.rail.other_multiheaded_part != NULL); w = GetNextVehicle(w)); if (w != NULL) { /* we found a car to partner with this engine. Now we will make sure it face the right way */ if (IsTrainEngine(w)) { diff --git a/src/train_gui.cpp b/src/train_gui.cpp index f88ab54ab..cf8dcbc15 100644 --- a/src/train_gui.cpp +++ b/src/train_gui.cpp @@ -100,7 +100,7 @@ void DrawTrainImage(const Vehicle *v, int x, int y, int count, int skip, Vehicle } dx += width; - v = v->next; + v = v->Next(); } while (dx < count && v != NULL); if (highlight_l != highlight_r) { @@ -176,7 +176,7 @@ static void DrawTrainDetailsWindow(Window *w) do { act_cargo[u->cargo_type] += u->cargo.Count(); max_cargo[u->cargo_type] += u->cargo_cap; - } while ((u = u->next) != NULL); + } while ((u = u->Next()) != NULL); /* Set scroll-amount seperately from counting, as to not compute num double * for more carriages of the same type @@ -188,7 +188,7 @@ static void DrawTrainDetailsWindow(Window *w) } else { do { if (!IsArticulatedPart(u) || u->cargo_cap != 0) num++; - } while ((u = u->next) != NULL); + } while ((u = u->Next()) != NULL); } SetVScrollCount(w, num); @@ -249,7 +249,7 @@ static void DrawTrainDetailsWindow(Window *w) SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v); DrawSprite(u->GetImage(DIR_W), pal, x + WagonLengthToPixels(4 + dx), y + 6 + (is_custom_sprite(RailVehInfo(u->engine_type)->image_index) ? _traininfo_vehicle_pitch : 0)); dx += u->u.rail.cached_veh_length; - u = u->next; + u = u->Next(); } while (u != NULL && IsArticulatedPart(u) && u->cargo_cap == 0); px = x + WagonLengthToPixels(dx) + 2; @@ -271,7 +271,7 @@ static void DrawTrainDetailsWindow(Window *w) } else { /* Move to the next line */ do { - v = v->next; + v = v->Next(); } while (v != NULL && IsArticulatedPart(v) && v->cargo_cap == 0); } if (v == NULL) return; diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 46c1f3d4c..c28a2b9c4 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -243,12 +243,12 @@ void AfterLoadVehicles() v->cur_image = v->GetImage(v->direction); /* The plane's shadow will have the same image as the plane */ - Vehicle *shadow = v->next; + Vehicle *shadow = v->Next(); shadow->cur_image = v->cur_image; /* In the case of a helicopter we will update the rotor sprites */ if (v->subtype == AIR_HELICOPTER) { - Vehicle *rotor = shadow->next; + Vehicle *rotor = shadow->Next(); rotor->cur_image = GetRotorImage(v); } @@ -462,7 +462,7 @@ void InitializeVehicles() Vehicle *GetLastVehicleInChain(Vehicle *v) { - while (v->next != NULL) v = v->next; + while (v->Next() != NULL) v = v->Next(); return v; } @@ -476,7 +476,7 @@ static Vehicle *GetPrevVehicleInChain_bruteforce(const Vehicle *v) { Vehicle *u; - FOR_ALL_VEHICLES(u) if (u->type == v->type && u->next == v) return u; + FOR_ALL_VEHICLES(u) if (u->type == v->type && u->Next() == v) return u; return NULL; } @@ -495,7 +495,7 @@ Vehicle *GetPrevVehicleInChain(const Vehicle *v) /* Check to see if this is the first */ if (v == u) return NULL; - for (; u->next != v; u = u->next) assert(u->next != NULL); + for (; u->Next() != v; u = u->Next()) assert(u->Next() != NULL); return u; } @@ -532,7 +532,7 @@ Vehicle *GetFirstVehicleInChain(const Vehicle *v) /* Set the first pointer of all vehicles in that chain to the first wagon */ if ((v->type == VEH_TRAIN && (IsFrontEngine(v) || IsFreeWagon(v))) || (v->type == VEH_ROAD && IsRoadVehFront(v))) { - for (u = (Vehicle *)v; u != NULL; u = u->next) u->first = (Vehicle *)v; + for (u = (Vehicle *)v; u != NULL; u = u->Next()) u->first = (Vehicle *)v; } return (Vehicle*)v; @@ -541,7 +541,7 @@ Vehicle *GetFirstVehicleInChain(const Vehicle *v) uint CountVehiclesInChain(const Vehicle* v) { uint count = 0; - do count++; while ((v = v->next) != NULL); + do count++; while ((v = v->Next()) != NULL); return count; } @@ -594,7 +594,7 @@ void Vehicle::PreDestructor() * destroy vehicle, which on his turn can remove any * other artic parts. */ if ((this->type == VEH_TRAIN && EngineHasArticPart(this)) || (this->type == VEH_ROAD && RoadVehHasArticPart(this))) { - delete this->next; + delete this->Next(); } } @@ -626,7 +626,7 @@ void DeleteVehicleChain(Vehicle *v) do { Vehicle *u = v; - v = v->next; + v = v->Next(); delete u; } while (v != NULL); } @@ -1777,7 +1777,7 @@ CommandCost CmdCloneVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) int veh_counter = 0; do { veh_counter++; - } while ((v = v->next) != NULL); + } while ((v = v->Next()) != NULL); if (!Vehicle::AllocateList(NULL, veh_counter)) { return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); @@ -1861,7 +1861,7 @@ CommandCost CmdCloneVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) if (w->type == VEH_TRAIN && EngineHasArticPart(w)) { w = GetNextArticPart(w); } else if (w->type == VEH_ROAD && RoadVehHasArticPart(w)) { - w = w->next; + w = w->Next(); } else { break; } @@ -1876,7 +1876,7 @@ CommandCost CmdCloneVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) if (v->type == VEH_TRAIN && EngineHasArticPart(v)) { v = GetNextArticPart(v); } else if (v->type == VEH_ROAD && RoadVehHasArticPart(v)) { - v = v->next; + v = v->Next(); } else { break; } @@ -2153,7 +2153,7 @@ uint8 CalcPercentVehicleFilled(Vehicle *v, StringID *color) const Station *st = GetStation(v->last_station_visited); /* Count up max and used */ - for (; v != NULL; v = v->next) { + for (; v != NULL; v = v->Next()) { count += v->cargo.Count(); max += v->cargo_cap; if (v->cargo_cap != 0) { diff --git a/src/vehicle.h b/src/vehicle.h index fce09b18d..e2041229f 100644 --- a/src/vehicle.h +++ b/src/vehicle.h @@ -222,9 +222,9 @@ struct Vehicle : PoolItem<Vehicle, VehicleID, &_Vehicle_pool> { VehicleTypeByte type; ///< Type of vehicle byte subtype; // subtype (Filled with values from EffectVehicles/TrainSubTypes/AircraftSubTypes) - Vehicle *next; // next + Vehicle *next; // pointer to the next vehicle in the chain Vehicle *first; // NOSAVE: pointer to the first vehicle in the chain - Vehicle *depot_list; //NOSAVE: linked list to tell what vehicles entered a depot during the last tick. Used by autoreplace + Vehicle *depot_list; // NOSAVE: linked list to tell what vehicles entered a depot during the last tick. Used by autoreplace StringID string_id; // Displayed string @@ -455,7 +455,24 @@ struct Vehicle : PoolItem<Vehicle, VehicleID, &_Vehicle_pool> { */ Money GetDisplayRunningCost() const { return (this->GetRunningCost() >> 8); } - bool IsValid() const { return this->type != VEH_INVALID; } + /** + * Is this vehicle a valid vehicle? + * @return true if and only if the vehicle is valid. + */ + inline bool IsValid() const { return this->type != VEH_INVALID; } + + /** + * Set the next vehicle of this vehicle. + * @param next the next vehicle. NULL removes the next vehicle. + */ + void SetNext(Vehicle *next) { this->next = next; } + + /** + * Get the next vehicle of this vehicle. + * @note articulated parts are also counted as vehicles. + * @return the next vehicle or NULL when there isn't a next vehicle. + */ + inline Vehicle *Next() const { return this->next; } }; /** @@ -632,7 +649,7 @@ GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v); Direction GetDirectionTowards(const Vehicle *v, int x, int y); #define BEGIN_ENUM_WAGONS(v) do { -#define END_ENUM_WAGONS(v) } while ((v = v->next) != NULL); +#define END_ENUM_WAGONS(v) } while ((v = v->Next()) != NULL); static inline VehicleID GetMaxVehicleIndex() { diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 62b94105a..e2cd1d05c 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -261,7 +261,7 @@ static RefitList *BuildRefitList(const Vehicle *v) } } } - } while (v->type == VEH_TRAIN && (u = u->next) != NULL && num_lines < max_lines); + } while (v->type == VEH_TRAIN && (u = u->Next()) != NULL && num_lines < max_lines); list->num_lines = num_lines; list->items = refit; @@ -617,8 +617,8 @@ static int CDECL VehicleCargoSorter(const void *a, const void *b) memset(cargoa, 0, sizeof(cargoa)); memset(cargob, 0, sizeof(cargob)); - for (v = va; v != NULL; v = v->next) cargoa[v->cargo_type] += v->cargo_cap; - for (v = vb; v != NULL; v = v->next) cargob[v->cargo_type] += v->cargo_cap; + for (v = va; v != NULL; v = v->Next()) cargoa[v->cargo_type] += v->cargo_cap; + for (v = vb; v != NULL; v = v->Next()) cargob[v->cargo_type] += v->cargo_cap; for (CargoID i = 0; i < NUM_CARGO; i++) { r = cargoa[i] - cargob[i]; @@ -653,12 +653,12 @@ static int CDECL VehicleMaxSpeedSorter(const void *a, const void *b) do { if (RailVehInfo(ua->engine_type)->max_speed != 0) max_speed_a = min(max_speed_a, RailVehInfo(ua->engine_type)->max_speed); - } while ((ua = ua->next) != NULL); + } while ((ua = ua->Next()) != NULL); do { if (RailVehInfo(ub->engine_type)->max_speed != 0) max_speed_b = min(max_speed_b, RailVehInfo(ub->engine_type)->max_speed); - } while ((ub = ub->next) != NULL); + } while ((ub = ub->Next()) != NULL); r = max_speed_a - max_speed_b; } else { @@ -688,8 +688,8 @@ static int CDECL VehicleValueSorter(const void *a, const void *b) const Vehicle *u; Money valuea = 0, valueb = 0; - for (u = va; u != NULL; u = u->next) valuea += u->value; - for (u = vb; u != NULL; u = u->next) valueb += u->value; + for (u = va; u != NULL; u = u->Next()) valuea += u->value; + for (u = vb; u != NULL; u = u->Next()) valueb += u->value; int r = ClampToI32(valuea - valueb); @@ -1590,7 +1590,7 @@ static void DrawVehicleViewWindow(Window *w) if (is_localplayer) { /* See if any vehicle can be refitted */ - for (const Vehicle *u = v; u != NULL; u = u->next) { + for (const Vehicle *u = v; u != NULL; u = u->Next()) { if (EngInfo(u->engine_type)->refit_mask != 0 || (RailVehInfo(v->engine_type)->railveh_type != RAILVEH_WAGON && v->cargo_cap != 0)) { EnableWindowWidget(w, VVW_WIDGET_REFIT_VEH); |