(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
(in prepare of dynamic arrays):
- DEREF_XXX is changed into GetXXX
- All direct call are directed via GetXXX
- struct Industry has now an index-field
- ENUM'd some stuff
- Replaced home built loops with FOR_ALL_XXX
- Added _stations_size, _vehicles_size, ... which gives the length of the
array (which will be dynamic in the near future)
- Changed lengtof(XXX) to _XXX_size (e.g. _stations_size)
- Removed all endof(XXX) (because mostly it was part of a FOR_ALL_XXX)
- Made the sort-functions of all 4 dynamic
- Made all 4 Initialize functions more of the same
- Some minor tab-fixing and stuff
(tnx to Tron for proof-reading my 100kb patch ;))
Note for all: please do NOT directly call _stations, _vehicles, _towns and
_industries, but use the right wrapper to access them. Thank you.
Ps: please also do not use 'v++', where v is of type Vehicle *.
This commit is contained in:
@@ -217,7 +217,7 @@ int32 CmdBuildAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||
const AirportFTAClass *Airport;
|
||||
const TileIndexDiffC *cur_depot;
|
||||
byte i = 0;
|
||||
st = DEREF_STATION(_map2[tile]);
|
||||
st = GetStation(_map2[tile]);
|
||||
Airport = GetAirport(st->airport_type);
|
||||
for (cur_depot = Airport->airport_depots; i != Airport->nof_depots; cur_depot++) {
|
||||
if ((uint)(st->airport_tile + ToTileIndexDiff(*cur_depot)) == tile) {
|
||||
@@ -311,7 +311,7 @@ int32 CmdSellAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||
|
||||
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
|
||||
|
||||
v = &_vehicles[p1];
|
||||
v = GetVehicle(p1);
|
||||
|
||||
if (!CheckOwnership(v->owner) || !CheckStoppedInHangar(v))
|
||||
return CMD_ERROR;
|
||||
@@ -332,7 +332,7 @@ int32 CmdStartStopAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||
{
|
||||
Vehicle *v;
|
||||
|
||||
v = &_vehicles[p1];
|
||||
v = GetVehicle(p1);
|
||||
|
||||
if (!CheckOwnership(v->owner))
|
||||
return CMD_ERROR;
|
||||
@@ -357,7 +357,7 @@ int32 CmdSendAircraftToHangar(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||
Vehicle *v;
|
||||
Station *st;
|
||||
|
||||
v = &_vehicles[p1];
|
||||
v = GetVehicle(p1);
|
||||
|
||||
if (!CheckOwnership(v->owner))
|
||||
return CMD_ERROR;
|
||||
@@ -370,7 +370,7 @@ int32 CmdSendAircraftToHangar(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
|
||||
}
|
||||
} else {
|
||||
st = DEREF_STATION(v->u.air.targetairport);
|
||||
st = GetStation(v->u.air.targetairport);
|
||||
// If an airport doesn't have terminals (so no landing space for airports),
|
||||
// it surely doesn't have any hangars
|
||||
if (st->xy == 0 || st->airport_tile == 0 || GetAirport(st->airport_type)->nofterminals == 0)
|
||||
@@ -393,7 +393,7 @@ int32 CmdChangeAircraftServiceInt(int x, int y, uint32 flags, uint32 p1, uint32
|
||||
{
|
||||
Vehicle *v;
|
||||
|
||||
v = &_vehicles[p1];
|
||||
v = GetVehicle(p1);
|
||||
|
||||
if (!CheckOwnership(v->owner))
|
||||
return CMD_ERROR;
|
||||
@@ -419,7 +419,7 @@ int32 CmdRefitAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||
|
||||
SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_RUN);
|
||||
|
||||
v = &_vehicles[p1];
|
||||
v = GetVehicle(p1);
|
||||
if (!CheckOwnership(v->owner) || (!CheckStoppedInHangar(v) && !(SkipStoppedInHangerCheck)))
|
||||
return CMD_ERROR;
|
||||
|
||||
@@ -481,7 +481,7 @@ static void CheckIfAircraftNeedsService(Vehicle *v)
|
||||
if (_patches.gotodepot && ScheduleHasDepotOrders(v->schedule_ptr))
|
||||
return;
|
||||
|
||||
st = DEREF_STATION(v->current_order.station);
|
||||
st = GetStation(v->current_order.station);
|
||||
// only goto depot if the target airport has terminals (eg. it is airport)
|
||||
if (st->xy != 0 && st->airport_tile != 0 && GetAirport(st->airport_type)->nofterminals != 0) {
|
||||
// printf("targetairport = %d, st->index = %d\n", v->u.air.targetairport, st->index);
|
||||
@@ -720,7 +720,7 @@ static bool Aircraft_5(Vehicle *v)
|
||||
uint dist;
|
||||
int x,y;
|
||||
|
||||
st = DEREF_STATION(v->u.air.targetairport);
|
||||
st = GetStation(v->u.air.targetairport);
|
||||
|
||||
// prevent going to 0,0 if airport is deleted.
|
||||
{
|
||||
@@ -925,7 +925,7 @@ static void HandleCrashedAircraft(Vehicle *v)
|
||||
|
||||
v->u.air.crashed_counter++;
|
||||
|
||||
st = DEREF_STATION(v->u.air.targetairport);
|
||||
st = GetStation(v->u.air.targetairport);
|
||||
|
||||
// make aircraft crash down to the ground
|
||||
if ( st->airport_tile==0 && ((v->u.air.crashed_counter % 3) == 0) ) {
|
||||
@@ -1112,7 +1112,7 @@ static void CrashAirplane(Vehicle *v)
|
||||
|
||||
v->cargo_count = 0;
|
||||
v->next->cargo_count = 0,
|
||||
st = DEREF_STATION(v->u.air.targetairport);
|
||||
st = GetStation(v->u.air.targetairport);
|
||||
if(st->airport_tile==0) {
|
||||
newsitem = STR_PLANE_CRASH_OUT_OF_FUEL;
|
||||
} else {
|
||||
@@ -1135,7 +1135,7 @@ static void MaybeCrashAirplane(Vehicle *v)
|
||||
uint16 prob;
|
||||
int i;
|
||||
|
||||
st = DEREF_STATION(v->u.air.targetairport);
|
||||
st = GetStation(v->u.air.targetairport);
|
||||
|
||||
//FIXME -- MaybeCrashAirplane -> increase crashing chances of very modern airplanes on smaller than AT_METROPOLITAN airports
|
||||
prob = 0x10000 / 1500;
|
||||
@@ -1164,7 +1164,7 @@ static void AircraftEntersTerminal(Vehicle *v)
|
||||
if (v->current_order.type == OT_GOTO_DEPOT)
|
||||
return;
|
||||
|
||||
st = DEREF_STATION(v->u.air.targetairport);
|
||||
st = GetStation(v->u.air.targetairport);
|
||||
v->last_station_visited = v->u.air.targetairport;
|
||||
|
||||
/* Check if station was ever visited before */
|
||||
@@ -1253,7 +1253,7 @@ static void AircraftNextAirportPos_and_Order(Vehicle *v)
|
||||
v->current_order.type == OT_GOTO_DEPOT)
|
||||
v->u.air.targetairport = v->current_order.station;
|
||||
|
||||
st = DEREF_STATION(v->u.air.targetairport);
|
||||
st = GetStation(v->u.air.targetairport);
|
||||
Airport = GetAirport(st->airport_type);
|
||||
v->u.air.pos = v->u.air.previous_pos = Airport->entry_point;
|
||||
}
|
||||
@@ -1423,7 +1423,7 @@ static void AircraftEventHandler_Flying(Vehicle *v, const AirportFTAClass *Airpo
|
||||
AirportFTA *current;
|
||||
uint16 tcur_speed, tsubspeed;
|
||||
|
||||
st = DEREF_STATION(v->u.air.targetairport);
|
||||
st = GetStation(v->u.air.targetairport);
|
||||
// flying device is accepted at this station
|
||||
// small airport --> no helicopters (AIRCRAFT_ONLY)
|
||||
// all other airports --> all types of flying devices (ALL)
|
||||
@@ -1537,7 +1537,7 @@ static void AirportClearBlock(Vehicle *v, const AirportFTAClass *Airport)
|
||||
Station *st;
|
||||
// we have left the previous block, and entered the new one. Free the previous block
|
||||
if (Airport->layout[v->u.air.previous_pos].block != Airport->layout[v->u.air.pos].block) {
|
||||
st = DEREF_STATION(v->u.air.targetairport);
|
||||
st = GetStation(v->u.air.targetairport);
|
||||
CLRBITS(st->airport_flags, Airport->layout[v->u.air.previous_pos].block);
|
||||
}
|
||||
}
|
||||
@@ -1613,7 +1613,7 @@ static bool AirportHasBlock(Vehicle *v, AirportFTA *current_pos, const AirportFT
|
||||
// same block, then of course we can move
|
||||
if (Airport->layout[current_pos->position].block != next->block) {
|
||||
airport_flags = next->block;
|
||||
st = DEREF_STATION(v->u.air.targetairport);
|
||||
st = GetStation(v->u.air.targetairport);
|
||||
// check additional possible extra blocks
|
||||
if (current_pos != reference && current_pos->block != NOTHING_block) {
|
||||
airport_flags |= current_pos->block;
|
||||
@@ -1640,7 +1640,7 @@ static bool AirportSetBlocks(Vehicle *v, AirportFTA *current_pos, const AirportF
|
||||
// if the next position is in another block, check it and wait until it is free
|
||||
if (Airport->layout[current_pos->position].block != next->block) {
|
||||
airport_flags = next->block;
|
||||
st = DEREF_STATION(v->u.air.targetairport);
|
||||
st = GetStation(v->u.air.targetairport);
|
||||
//search for all all elements in the list with the same state, and blocks != N
|
||||
// this means more blocks should be checked/set
|
||||
current = current_pos;
|
||||
@@ -1672,7 +1672,7 @@ static bool AirportSetBlocks(Vehicle *v, AirportFTA *current_pos, const AirportF
|
||||
|
||||
static bool FreeTerminal(Vehicle *v, byte i, byte last_terminal)
|
||||
{
|
||||
Station *st = DEREF_STATION(v->u.air.targetairport);
|
||||
Station *st = GetStation(v->u.air.targetairport);
|
||||
for (; i < last_terminal; i++) {
|
||||
if (!HASBIT(st->airport_flags, i)) {
|
||||
// TERMINAL# HELIPAD#
|
||||
@@ -1701,7 +1701,7 @@ static bool AirportFindFreeTerminal(Vehicle *v, const AirportFTAClass *Airport)
|
||||
fails, then attempt fails and plane waits
|
||||
*/
|
||||
if (Airport->nofterminalgroups > 1) {
|
||||
st = DEREF_STATION(v->u.air.targetairport);
|
||||
st = GetStation(v->u.air.targetairport);
|
||||
nofterminalspergroup = Airport->nofterminals / Airport->nofterminalgroups;
|
||||
temp = Airport->layout[v->u.air.pos].next_in_chain;
|
||||
while (temp != NULL) {
|
||||
@@ -1734,7 +1734,7 @@ static bool AirportFindFreeHelipad(Vehicle *v, const AirportFTAClass *Airport)
|
||||
|
||||
// if there are more helicoptergroups, pick one, just as in AirportFindFreeTerminal()
|
||||
if (Airport->nofhelipadgroups > 1) {
|
||||
st = DEREF_STATION(v->u.air.targetairport);
|
||||
st = GetStation(v->u.air.targetairport);
|
||||
nofhelipadspergroup = Airport->nofhelipads / Airport->nofhelipadgroups;
|
||||
temp = Airport->layout[v->u.air.pos].next_in_chain;
|
||||
while (temp != NULL) {
|
||||
@@ -1787,7 +1787,7 @@ static void AircraftEventHandler(Vehicle *v, int loop)
|
||||
// pass the right airport structure to the functions
|
||||
// DEREF_STATION gets target airport (Station *st), its type is passed to GetAirport
|
||||
// that returns the correct layout depending on type
|
||||
AirportGoToNextPosition(v, GetAirport(DEREF_STATION(v->u.air.targetairport)->airport_type));
|
||||
AirportGoToNextPosition(v, GetAirport(GetStation(v->u.air.targetairport)->airport_type));
|
||||
}
|
||||
|
||||
void Aircraft_Tick(Vehicle *v)
|
||||
|
||||
Reference in New Issue
Block a user