mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r8621) -Codechange: assigned new numbers to the VEH_(type) enum so that VEH_Train is 0, VEH_Road is 1 and so on
This means that "v->type" can be used as array indexes instead of VehTypeToIndex() (or "v->type - VEH_Train/0x10 as the code still used in some places) Surprisingly this can be done without changing the savegame format
This commit is contained in:
parent
5666d8d727
commit
037d636734
|
@ -251,7 +251,7 @@ static void ReplaceVehicleWndProc(Window *w, WindowEvent *e)
|
|||
!EngineHasReplacementForPlayer(p, selected_id[0]));
|
||||
|
||||
/* now the actual drawing of the window itself takes place */
|
||||
SetDParam(0, _vehicle_type_names[VehTypeToIndex(w->window_number)]);
|
||||
SetDParam(0, _vehicle_type_names[w->window_number]);
|
||||
|
||||
if (w->window_number == VEH_Train) {
|
||||
/* set on/off for renew_keep_length */
|
||||
|
|
|
@ -712,7 +712,7 @@ static void GenerateBuildList(Window *w)
|
|||
break;
|
||||
}
|
||||
_internal_sort_order = bv->descending_sort_order;
|
||||
EngList_Sort(&bv->eng_list, _sorter[VehTypeToIndex(bv->vehicle_type)][bv->sort_criteria]);
|
||||
EngList_Sort(&bv->eng_list, _sorter[bv->vehicle_type][bv->sort_criteria]);
|
||||
}
|
||||
|
||||
static void DrawVehicleEngine(byte type, int x, int y, EngineID engine, SpriteID pal)
|
||||
|
@ -799,7 +799,7 @@ static void DrawBuildVehicleWindow(Window *w)
|
|||
DrawVehiclePurchaseInfo(2, wi->top + 1, wi->right - wi->left - 2, bv->sel_engine);
|
||||
}
|
||||
|
||||
DrawString(85, 15, _sort_listing[VehTypeToIndex(bv->vehicle_type)][bv->sort_criteria], 0x10);
|
||||
DrawString(85, 15, _sort_listing[bv->vehicle_type][bv->sort_criteria], 0x10);
|
||||
DoDrawString(bv->descending_sort_order ? DOWNARROW : UPARROW, 69, 15, 0x10);
|
||||
}
|
||||
|
||||
|
@ -810,7 +810,7 @@ static void BuildVehicleClickEvent(Window *w, WindowEvent *e)
|
|||
switch (e->we.click.widget) {
|
||||
case BUILD_VEHICLE_WIDGET_SORT_ASSENDING_DESCENDING:
|
||||
bv->descending_sort_order ^= true;
|
||||
_last_sort_order[VehTypeToIndex(bv->vehicle_type)] = bv->descending_sort_order;
|
||||
_last_sort_order[bv->vehicle_type] = bv->descending_sort_order;
|
||||
bv->regenerate_list = true;
|
||||
SetWindowDirty(w);
|
||||
break;
|
||||
|
@ -824,7 +824,7 @@ static void BuildVehicleClickEvent(Window *w, WindowEvent *e)
|
|||
}
|
||||
|
||||
case BUILD_VEHICLE_WIDGET_SORT_TEXT: case BUILD_VEHICLE_WIDGET_SORT_DROPDOWN: // Select sorting criteria dropdown menu
|
||||
ShowDropDownMenu(w, _sort_listing[VehTypeToIndex(bv->vehicle_type)], bv->sort_criteria, BUILD_VEHICLE_WIDGET_SORT_DROPDOWN, 0, 0);
|
||||
ShowDropDownMenu(w, _sort_listing[bv->vehicle_type], bv->sort_criteria, BUILD_VEHICLE_WIDGET_SORT_DROPDOWN, 0, 0);
|
||||
break;
|
||||
|
||||
case BUILD_VEHICLE_WIDGET_BUILD: {
|
||||
|
@ -912,7 +912,7 @@ static void NewVehicleWndProc(Window *w, WindowEvent *e)
|
|||
case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
|
||||
if (bv->sort_criteria != e->we.dropdown.index) {
|
||||
bv->sort_criteria = e->we.dropdown.index;
|
||||
_last_sort_criteria[VehTypeToIndex(bv->vehicle_type)] = bv->sort_criteria;
|
||||
_last_sort_criteria[bv->vehicle_type] = bv->sort_criteria;
|
||||
bv->regenerate_list = true;
|
||||
}
|
||||
SetWindowDirty(w);
|
||||
|
@ -961,8 +961,8 @@ void ShowBuildVehicleWindow(TileIndex tile, byte type)
|
|||
bv->vehicle_type = type;
|
||||
bv->regenerate_list = false;
|
||||
|
||||
bv->sort_criteria = _last_sort_criteria[VehTypeToIndex(type)];
|
||||
bv->descending_sort_order = _last_sort_order[VehTypeToIndex(type)];
|
||||
bv->sort_criteria = _last_sort_criteria[type];
|
||||
bv->descending_sort_order = _last_sort_order[type];
|
||||
|
||||
switch (type) {
|
||||
case VEH_Train:
|
||||
|
|
|
@ -215,7 +215,7 @@ static void RunVehicleDayProc(uint daytick)
|
|||
for (i = daytick; i < total; i += DAY_TICKS) {
|
||||
Vehicle *v = GetVehicle(i);
|
||||
|
||||
if (IsValidVehicle(v)) _on_new_vehicle_day_proc[v->type - 0x10](v);
|
||||
if (IsValidVehicle(v)) _on_new_vehicle_day_proc[v->type](v);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -743,7 +743,7 @@ static void DepotWndProc(Window *w, WindowEvent *e)
|
|||
};
|
||||
|
||||
_place_clicked_vehicle = NULL;
|
||||
SetObjectToPlaceWnd(clone_icons[WP(w, depot_d).type - VEH_Train], PAL_NONE, VHM_RECT, w);
|
||||
SetObjectToPlaceWnd(clone_icons[WP(w, depot_d).type], PAL_NONE, VHM_RECT, w);
|
||||
} else {
|
||||
ResetObjectToPlace();
|
||||
}
|
||||
|
@ -770,7 +770,7 @@ static void DepotWndProc(Window *w, WindowEvent *e)
|
|||
|
||||
SetDParam(0, (vehtype == VEH_Aircraft) ? GetStationIndex(tile) : GetDepotByTile(tile)->town_index);
|
||||
ShowQuery(
|
||||
confirm_captions[vehtype - VEH_Train],
|
||||
confirm_captions[vehtype],
|
||||
STR_DEPOT_SELL_CONFIRMATION_TEXT,
|
||||
w,
|
||||
DepotSellAllConfirmationCallback
|
||||
|
|
|
@ -1503,7 +1503,7 @@ int LoadUnloadVehicle(Vehicle *v, bool just_arrived)
|
|||
* on the vehicle type - the values here are those found in TTDPatch */
|
||||
uint gradual_loading_wait_time[] = { 40, 20, 10, 20 };
|
||||
|
||||
unloading_time = gradual_loading_wait_time[v->type - VEH_Train];
|
||||
unloading_time = gradual_loading_wait_time[v->type];
|
||||
if (HASBIT(v->load_status, LS_LOADING_FINISHED)) {
|
||||
if (anything_loaded) {
|
||||
unloading_time += 20;
|
||||
|
|
|
@ -163,7 +163,7 @@ static inline EngineID GetFirstEngineOfType(byte type)
|
|||
{
|
||||
const EngineID start[] = {0, ROAD_ENGINES_INDEX, SHIP_ENGINES_INDEX, AIRCRAFT_ENGINES_INDEX};
|
||||
|
||||
return start[VehTypeToIndex(type)];
|
||||
return start[type];
|
||||
}
|
||||
|
||||
static inline EngineID GetLastEngineOfType(byte type)
|
||||
|
@ -174,7 +174,7 @@ static inline EngineID GetLastEngineOfType(byte type)
|
|||
SHIP_ENGINES_INDEX + NUM_SHIP_ENGINES,
|
||||
AIRCRAFT_ENGINES_INDEX + NUM_AIRCRAFT_ENGINES};
|
||||
|
||||
return end[VehTypeToIndex(type)];
|
||||
return end[type];
|
||||
}
|
||||
|
||||
VARDEF Engine _engines[TOTAL_NUM_ENGINES];
|
||||
|
|
|
@ -3617,7 +3617,7 @@ static void CalculateRefitMasks(void)
|
|||
RailVehInfo(engine)->railveh_type != RAILVEH_WAGON
|
||||
)
|
||||
)) {
|
||||
xor_mask = _default_refitmasks[GetEngine(engine)->type - VEH_Train];
|
||||
xor_mask = _default_refitmasks[GetEngine(engine)->type];
|
||||
}
|
||||
}
|
||||
_engine_info[engine].refit_mask = ((mask & ~not_mask) ^ xor_mask) & _landscape_global_cargo_mask[_opt.landscape];
|
||||
|
|
|
@ -160,10 +160,10 @@ void AssignOrder(Order *order, Order data)
|
|||
*/
|
||||
static void DeleteOrderWarnings(const Vehicle* v)
|
||||
{
|
||||
DeleteVehicleNews(v->index, STR_TRAIN_HAS_TOO_FEW_ORDERS + (v->type - VEH_Train) * 4);
|
||||
DeleteVehicleNews(v->index, STR_TRAIN_HAS_VOID_ORDER + (v->type - VEH_Train) * 4);
|
||||
DeleteVehicleNews(v->index, STR_TRAIN_HAS_DUPLICATE_ENTRY + (v->type - VEH_Train) * 4);
|
||||
DeleteVehicleNews(v->index, STR_TRAIN_HAS_INVALID_ENTRY + (v->type - VEH_Train) * 4);
|
||||
DeleteVehicleNews(v->index, STR_TRAIN_HAS_TOO_FEW_ORDERS + v->type * 4);
|
||||
DeleteVehicleNews(v->index, STR_TRAIN_HAS_VOID_ORDER + v->type * 4);
|
||||
DeleteVehicleNews(v->index, STR_TRAIN_HAS_DUPLICATE_ENTRY + v->type * 4);
|
||||
DeleteVehicleNews(v->index, STR_TRAIN_HAS_INVALID_ENTRY + v->type * 4);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1005,7 +1005,7 @@ void CheckOrders(const Vehicle* v)
|
|||
/* We don't have a problem */
|
||||
if (problem_type < 0) return;
|
||||
|
||||
message = STR_TRAIN_HAS_TOO_FEW_ORDERS + ((v->type - VEH_Train) << 2) + problem_type;
|
||||
message = STR_TRAIN_HAS_TOO_FEW_ORDERS + (v->type << 2) + problem_type;
|
||||
//DEBUG(misc, 3, "Triggered News Item for vehicle %d", v->index);
|
||||
|
||||
SetDParam(0, v->unitnumber);
|
||||
|
|
|
@ -724,7 +724,7 @@ skip_column:
|
|||
|
||||
// Calculate pointer to pixel and the color
|
||||
ptr = dpi->dst_ptr + y * dpi->pitch + x;
|
||||
color = (type == 1) ? _vehicle_type_colors[v->type-0x10] : 0xF;
|
||||
color = (type == 1) ? _vehicle_type_colors[v->type] : 0xF;
|
||||
|
||||
// And draw either one or two pixels depending on clipping
|
||||
ptr[0] = color;
|
||||
|
|
|
@ -84,7 +84,10 @@ static void VehiclePoolNewBlock(uint start_item)
|
|||
|
||||
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
|
||||
* TODO - This is just a temporary stage, this will be removed. */
|
||||
for (v = GetVehicle(start_item); v != NULL; v = (v->index + 1U < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) v->index = start_item++;
|
||||
for (v = GetVehicle(start_item); v != NULL; v = (v->index + 1U < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) {
|
||||
v->index = start_item++;
|
||||
v->type = VEH_Invalid;
|
||||
}
|
||||
}
|
||||
|
||||
/* Initialize the vehicle-pool */
|
||||
|
@ -263,6 +266,7 @@ static Vehicle *InitializeVehicle(Vehicle *v)
|
|||
|
||||
assert(v->orders == NULL);
|
||||
|
||||
v->type = VEH_Invalid;
|
||||
v->left_coord = INVALID_COORD;
|
||||
v->first = NULL;
|
||||
v->next = NULL;
|
||||
|
@ -656,7 +660,7 @@ void CallVehicleTicks(void)
|
|||
_first_veh_in_depot_list = NULL; // now we are sure it's initialized at the start of each tick
|
||||
|
||||
FOR_ALL_VEHICLES(v) {
|
||||
_vehicle_tick_procs[v->type - 0x10](v);
|
||||
_vehicle_tick_procs[v->type](v);
|
||||
|
||||
switch (v->type) {
|
||||
case VEH_Train:
|
||||
|
@ -1568,7 +1572,7 @@ static void ShowVehicleGettingOld(Vehicle *v, StringID msg)
|
|||
// Do not show getting-old message if autorenew is active
|
||||
if (GetPlayer(v->owner)->engine_renew) return;
|
||||
|
||||
SetDParam(0, _vehicle_type_names[v->type - 0x10]);
|
||||
SetDParam(0, _vehicle_type_names[v->type]);
|
||||
SetDParam(1, v->unitnumber);
|
||||
AddNewsItem(msg, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), v->index, 0);
|
||||
}
|
||||
|
@ -2569,7 +2573,7 @@ void VehicleEnterDepot(Vehicle *v)
|
|||
v->leave_depot_instantly = false; // We ensure that the vehicle stays in the depot
|
||||
if (v->owner == _local_player) {
|
||||
/* Notify the user that we stopped the vehicle */
|
||||
SetDParam(0, _vehicle_type_names[v->type - 0x10]);
|
||||
SetDParam(0, _vehicle_type_names[v->type]);
|
||||
SetDParam(1, v->unitnumber);
|
||||
AddNewsItem(STR_ORDER_REFIT_FAILED, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), v->index, 0);
|
||||
}
|
||||
|
@ -3212,7 +3216,7 @@ static void Save_VEHS(void)
|
|||
// Write the vehicles
|
||||
FOR_ALL_VEHICLES(v) {
|
||||
SlSetArrayIndex(v->index);
|
||||
SlObject(v, (SaveLoad*)_veh_descs[v->type - 0x10]);
|
||||
SlObject(v, (SaveLoad*)_veh_descs[v->type]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,13 +8,13 @@
|
|||
#include "rail.h"
|
||||
|
||||
enum {
|
||||
VEH_Invalid = 0x00,
|
||||
VEH_Train = 0x10,
|
||||
VEH_Road = 0x11,
|
||||
VEH_Ship = 0x12,
|
||||
VEH_Aircraft = 0x13,
|
||||
VEH_Special = 0x14,
|
||||
VEH_Disaster = 0x15,
|
||||
VEH_Train,
|
||||
VEH_Road,
|
||||
VEH_Ship,
|
||||
VEH_Aircraft,
|
||||
VEH_Special,
|
||||
VEH_Disaster,
|
||||
VEH_Invalid = 0xFF,
|
||||
} ;
|
||||
|
||||
enum VehStatus {
|
||||
|
@ -400,7 +400,7 @@ static inline uint GetNumVehicles(void)
|
|||
*/
|
||||
static inline bool IsValidVehicle(const Vehicle *v)
|
||||
{
|
||||
return v->type != 0;
|
||||
return v->type != VEH_Invalid;
|
||||
}
|
||||
|
||||
void DestroyVehicle(Vehicle *v);
|
||||
|
@ -408,7 +408,7 @@ void DestroyVehicle(Vehicle *v);
|
|||
static inline void DeleteVehicle(Vehicle *v)
|
||||
{
|
||||
DestroyVehicle(v);
|
||||
v->type = 0;
|
||||
v->type = VEH_Invalid;
|
||||
}
|
||||
|
||||
static inline bool IsPlayerBuildableVehicleType(byte type)
|
||||
|
@ -428,20 +428,6 @@ static inline bool IsPlayerBuildableVehicleType(const Vehicle *v)
|
|||
return IsPlayerBuildableVehicleType(v->type);
|
||||
}
|
||||
|
||||
/** Function to give index of a vehicle type
|
||||
* Since the return value is 0 for VEH_train, it's perfect for index to arrays
|
||||
*/
|
||||
static inline byte VehTypeToIndex(byte type)
|
||||
{
|
||||
assert(IsPlayerBuildableVehicleType(type));
|
||||
return type - VEH_Train;
|
||||
}
|
||||
|
||||
static inline byte VehTypeToIndex(const Vehicle *v)
|
||||
{
|
||||
return VehTypeToIndex(v->type);
|
||||
}
|
||||
|
||||
#define FOR_ALL_VEHICLES_FROM(v, start) for (v = GetVehicle(start); v != NULL; v = (v->index + 1U < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) if (IsValidVehicle(v))
|
||||
#define FOR_ALL_VEHICLES(v) FOR_ALL_VEHICLES_FROM(v, 0)
|
||||
|
||||
|
@ -523,7 +509,7 @@ extern const uint32 _send_to_depot_proc_table[];
|
|||
/* Functions to find the right command for certain vehicle type */
|
||||
static inline uint32 GetCmdBuildVeh(byte type)
|
||||
{
|
||||
return _veh_build_proc_table[VehTypeToIndex(type)];
|
||||
return _veh_build_proc_table[type];
|
||||
}
|
||||
|
||||
static inline uint32 GetCmdBuildVeh(const Vehicle *v)
|
||||
|
@ -533,7 +519,7 @@ static inline uint32 GetCmdBuildVeh(const Vehicle *v)
|
|||
|
||||
static inline uint32 GetCmdSellVeh(byte type)
|
||||
{
|
||||
return _veh_sell_proc_table[VehTypeToIndex(type)];
|
||||
return _veh_sell_proc_table[type];
|
||||
}
|
||||
|
||||
static inline uint32 GetCmdSellVeh(const Vehicle *v)
|
||||
|
@ -543,7 +529,7 @@ static inline uint32 GetCmdSellVeh(const Vehicle *v)
|
|||
|
||||
static inline uint32 GetCmdRefitVeh(byte type)
|
||||
{
|
||||
return _veh_refit_proc_table[VehTypeToIndex(type)];
|
||||
return _veh_refit_proc_table[type];
|
||||
}
|
||||
|
||||
static inline uint32 GetCmdRefitVeh(const Vehicle *v)
|
||||
|
@ -553,7 +539,7 @@ static inline uint32 GetCmdRefitVeh(const Vehicle *v)
|
|||
|
||||
static inline uint32 GetCmdSendToDepot(byte type)
|
||||
{
|
||||
return _send_to_depot_proc_table[VehTypeToIndex(type)];
|
||||
return _send_to_depot_proc_table[type];
|
||||
}
|
||||
|
||||
static inline uint32 GetCmdSendToDepot(const Vehicle *v)
|
||||
|
|
|
@ -1132,7 +1132,7 @@ void PlayerVehWndProc(Window *w, WindowEvent *e)
|
|||
};
|
||||
|
||||
/* XXX - Substite string since the dropdown cannot handle dynamic strings */
|
||||
action_str[2] = depot_name[vl->vehicle_type - VEH_Train];
|
||||
action_str[2] = depot_name[vl->vehicle_type];
|
||||
ShowDropDownMenu(w, action_str, 0, VLW_WIDGET_MANAGE_VEHICLES_DROPDOWN, 0, 0);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1738,7 +1738,7 @@ void HandleViewportClicked(const ViewPort *vp, int x, int y)
|
|||
v = CheckClickOnVehicle(vp, x, y);
|
||||
if (v != NULL) {
|
||||
DEBUG(misc, 2, "Vehicle %d (index %d) at %p", v->unitnumber, v->index, v);
|
||||
_on_vehicle_click_proc[v->type - 0x10](v);
|
||||
_on_vehicle_click_proc[v->type](v);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue