mirror of https://github.com/OpenTTD/OpenTTD
(svn r17616) -Codechange [FS#3222]: Enumerize properties used in callback 0x36. Based on Terkhen's work.
parent
8f45efa8dd
commit
e261d8d9a0
|
@ -1207,6 +1207,10 @@
|
||||||
RelativePath=".\..\src\newgrf_industrytiles.h"
|
RelativePath=".\..\src\newgrf_industrytiles.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\..\src\newgrf_properties.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\..\src\newgrf_sound.h"
|
RelativePath=".\..\src\newgrf_sound.h"
|
||||||
>
|
>
|
||||||
|
|
|
@ -1204,6 +1204,10 @@
|
||||||
RelativePath=".\..\src\newgrf_industrytiles.h"
|
RelativePath=".\..\src\newgrf_industrytiles.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\..\src\newgrf_properties.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\..\src\newgrf_sound.h"
|
RelativePath=".\..\src\newgrf_sound.h"
|
||||||
>
|
>
|
||||||
|
|
|
@ -207,6 +207,7 @@ newgrf_generic.h
|
||||||
newgrf_house.h
|
newgrf_house.h
|
||||||
newgrf_industries.h
|
newgrf_industries.h
|
||||||
newgrf_industrytiles.h
|
newgrf_industrytiles.h
|
||||||
|
newgrf_properties.h
|
||||||
newgrf_sound.h
|
newgrf_sound.h
|
||||||
newgrf_spritegroup.h
|
newgrf_spritegroup.h
|
||||||
newgrf_station.h
|
newgrf_station.h
|
||||||
|
|
|
@ -619,7 +619,7 @@ static void CheckIfAircraftNeedsService(Aircraft *v)
|
||||||
|
|
||||||
Money Aircraft::GetRunningCost() const
|
Money Aircraft::GetRunningCost() const
|
||||||
{
|
{
|
||||||
return GetVehicleProperty(this, 0x0E, AircraftVehInfo(this->engine_type)->running_cost) * _price.aircraft_running;
|
return GetVehicleProperty(this, PROP_AIRCRAFT_RUNNING_COST_FACTOR, AircraftVehInfo(this->engine_type)->running_cost) * _price.aircraft_running;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Aircraft::OnNewDay()
|
void Aircraft::OnNewDay()
|
||||||
|
@ -753,7 +753,7 @@ static void PlayAircraftSound(const Vehicle *v)
|
||||||
|
|
||||||
void UpdateAircraftCache(Aircraft *v)
|
void UpdateAircraftCache(Aircraft *v)
|
||||||
{
|
{
|
||||||
uint max_speed = GetVehicleProperty(v, 0x0C, 0);
|
uint max_speed = GetVehicleProperty(v, PROP_AIRCRAFT_SPEED, 0);
|
||||||
if (max_speed != 0) {
|
if (max_speed != 0) {
|
||||||
/* Convert from original units to (approx) km/h */
|
/* Convert from original units to (approx) km/h */
|
||||||
max_speed = (max_speed * 129) / 10;
|
max_speed = (max_speed * 129) / 10;
|
||||||
|
|
|
@ -172,13 +172,13 @@ uint Engine::GetDisplayDefaultCapacity() const
|
||||||
if (!this->CanCarryCargo()) return 0;
|
if (!this->CanCarryCargo()) return 0;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case VEH_TRAIN:
|
case VEH_TRAIN:
|
||||||
return GetEngineProperty(this->index, 0x14, this->u.rail.capacity) + (this->u.rail.railveh_type == RAILVEH_MULTIHEAD ? this->u.rail.capacity : 0);
|
return GetEngineProperty(this->index, PROP_TRAIN_CARGO_CAPACITY, this->u.rail.capacity) + (this->u.rail.railveh_type == RAILVEH_MULTIHEAD ? this->u.rail.capacity : 0);
|
||||||
|
|
||||||
case VEH_ROAD:
|
case VEH_ROAD:
|
||||||
return GetEngineProperty(this->index, 0x0F, this->u.road.capacity);
|
return GetEngineProperty(this->index, PROP_ROADVEH_CARGO_CAPACITY, this->u.road.capacity);
|
||||||
|
|
||||||
case VEH_SHIP:
|
case VEH_SHIP:
|
||||||
return GetEngineProperty(this->index, 0x0D, this->u.ship.capacity);
|
return GetEngineProperty(this->index, PROP_SHIP_CARGO_CAPACITY, this->u.ship.capacity);
|
||||||
|
|
||||||
case VEH_AIRCRAFT:
|
case VEH_AIRCRAFT:
|
||||||
return AircraftDefaultCargoCapacity(this->GetDefaultCargoType(), &this->u.air);
|
return AircraftDefaultCargoCapacity(this->GetDefaultCargoType(), &this->u.air);
|
||||||
|
@ -194,13 +194,13 @@ Money Engine::GetRunningCost() const
|
||||||
return this->u.road.running_cost * GetPriceByIndex(this->u.road.running_cost_class) >> 8;
|
return this->u.road.running_cost * GetPriceByIndex(this->u.road.running_cost_class) >> 8;
|
||||||
|
|
||||||
case VEH_TRAIN:
|
case VEH_TRAIN:
|
||||||
return GetEngineProperty(this->index, 0x0D, this->u.rail.running_cost) * GetPriceByIndex(this->u.rail.running_cost_class) >> 8;
|
return GetEngineProperty(this->index, PROP_TRAIN_RUNNING_COST_FACTOR, this->u.rail.running_cost) * GetPriceByIndex(this->u.rail.running_cost_class) >> 8;
|
||||||
|
|
||||||
case VEH_SHIP:
|
case VEH_SHIP:
|
||||||
return GetEngineProperty(this->index, 0x0F, this->u.ship.running_cost) * _price.ship_running >> 8;
|
return GetEngineProperty(this->index, PROP_SHIP_RUNNING_COST_FACTOR, this->u.ship.running_cost) * _price.ship_running >> 8;
|
||||||
|
|
||||||
case VEH_AIRCRAFT:
|
case VEH_AIRCRAFT:
|
||||||
return GetEngineProperty(this->index, 0x0E, this->u.air.running_cost) * _price.aircraft_running >> 8;
|
return GetEngineProperty(this->index, PROP_AIRCRAFT_RUNNING_COST_FACTOR, this->u.air.running_cost) * _price.aircraft_running >> 8;
|
||||||
|
|
||||||
default: NOT_REACHED();
|
default: NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
@ -210,19 +210,19 @@ Money Engine::GetCost() const
|
||||||
{
|
{
|
||||||
switch (this->type) {
|
switch (this->type) {
|
||||||
case VEH_ROAD:
|
case VEH_ROAD:
|
||||||
return GetEngineProperty(this->index, 0x11, this->u.road.cost_factor) * (_price.roadveh_base >> 3) >> 5;
|
return GetEngineProperty(this->index, PROP_ROADVEH_COST_FACTOR, this->u.road.cost_factor) * (_price.roadveh_base >> 3) >> 5;
|
||||||
|
|
||||||
case VEH_TRAIN:
|
case VEH_TRAIN:
|
||||||
if (this->u.rail.railveh_type == RAILVEH_WAGON) {
|
if (this->u.rail.railveh_type == RAILVEH_WAGON) {
|
||||||
return (GetEngineProperty(this->index, 0x17, this->u.rail.cost_factor) * _price.build_railwagon) >> 8;
|
return (GetEngineProperty(this->index, PROP_TRAIN_COST_FACTOR, this->u.rail.cost_factor) * _price.build_railwagon) >> 8;
|
||||||
} else {
|
} else {
|
||||||
return GetEngineProperty(this->index, 0x17, this->u.rail.cost_factor) * (_price.build_railvehicle >> 3) >> 5;
|
return GetEngineProperty(this->index, PROP_TRAIN_COST_FACTOR, this->u.rail.cost_factor) * (_price.build_railvehicle >> 3) >> 5;
|
||||||
}
|
}
|
||||||
case VEH_SHIP:
|
case VEH_SHIP:
|
||||||
return GetEngineProperty(this->index, 0x0A, this->u.ship.cost_factor) * (_price.ship_base >> 3) >> 5;
|
return GetEngineProperty(this->index, PROP_SHIP_COST_FACTOR, this->u.ship.cost_factor) * (_price.ship_base >> 3) >> 5;
|
||||||
|
|
||||||
case VEH_AIRCRAFT:
|
case VEH_AIRCRAFT:
|
||||||
return GetEngineProperty(this->index, 0x0B, this->u.air.cost_factor) * (_price.aircraft_base >> 3) >> 5;
|
return GetEngineProperty(this->index, PROP_AIRCRAFT_COST_FACTOR, this->u.air.cost_factor) * (_price.aircraft_base >> 3) >> 5;
|
||||||
|
|
||||||
default: NOT_REACHED();
|
default: NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
@ -236,13 +236,13 @@ uint Engine::GetDisplayMaxSpeed() const
|
||||||
{
|
{
|
||||||
switch (this->type) {
|
switch (this->type) {
|
||||||
case VEH_TRAIN:
|
case VEH_TRAIN:
|
||||||
return GetEngineProperty(this->index, 0x09, this->u.rail.max_speed);
|
return GetEngineProperty(this->index, PROP_TRAIN_SPEED, this->u.rail.max_speed);
|
||||||
|
|
||||||
case VEH_ROAD:
|
case VEH_ROAD:
|
||||||
return this->u.road.max_speed / 2;
|
return this->u.road.max_speed / 2;
|
||||||
|
|
||||||
case VEH_SHIP:
|
case VEH_SHIP:
|
||||||
return GetEngineProperty(this->index, 0x0B, this->u.ship.max_speed) / 2;
|
return GetEngineProperty(this->index, PROP_SHIP_SPEED, this->u.ship.max_speed) / 2;
|
||||||
|
|
||||||
case VEH_AIRCRAFT:
|
case VEH_AIRCRAFT:
|
||||||
return this->u.air.max_speed;
|
return this->u.air.max_speed;
|
||||||
|
@ -256,7 +256,7 @@ uint Engine::GetPower() const
|
||||||
/* Currently only trains have 'power' */
|
/* Currently only trains have 'power' */
|
||||||
switch (this->type) {
|
switch (this->type) {
|
||||||
case VEH_TRAIN:
|
case VEH_TRAIN:
|
||||||
return GetEngineProperty(this->index, 0x0B, this->u.rail.power);
|
return GetEngineProperty(this->index, PROP_TRAIN_POWER, this->u.rail.power);
|
||||||
|
|
||||||
default: NOT_REACHED();
|
default: NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
@ -272,7 +272,7 @@ uint Engine::GetDisplayWeight() const
|
||||||
/* Currently only trains have 'weight' */
|
/* Currently only trains have 'weight' */
|
||||||
switch (this->type) {
|
switch (this->type) {
|
||||||
case VEH_TRAIN:
|
case VEH_TRAIN:
|
||||||
return GetEngineProperty(this->index, 0x16, this->u.rail.weight) << (this->u.rail.railveh_type == RAILVEH_MULTIHEAD ? 1 : 0);
|
return GetEngineProperty(this->index, PROP_TRAIN_WEIGHT, this->u.rail.weight) << (this->u.rail.railveh_type == RAILVEH_MULTIHEAD ? 1 : 0);
|
||||||
|
|
||||||
default: NOT_REACHED();
|
default: NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
@ -288,7 +288,7 @@ uint Engine::GetDisplayMaxTractiveEffort() const
|
||||||
/* Currently only trains have 'tractive effort' */
|
/* Currently only trains have 'tractive effort' */
|
||||||
switch (this->type) {
|
switch (this->type) {
|
||||||
case VEH_TRAIN:
|
case VEH_TRAIN:
|
||||||
return (10 * this->GetDisplayWeight() * GetEngineProperty(this->index, 0x1F, this->u.rail.tractive_effort)) / 256;
|
return (10 * this->GetDisplayWeight() * GetEngineProperty(this->index, PROP_TRAIN_TRACTIVE_EFFORT, this->u.rail.tractive_effort)) / 256;
|
||||||
|
|
||||||
default: NOT_REACHED();
|
default: NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
|
@ -506,14 +506,14 @@ static ChangeInfoResult RailVehicleChangeInfo(uint engine, int numinfo, int prop
|
||||||
rvi->ai_passenger_only = grf_load_byte(&buf);
|
rvi->ai_passenger_only = grf_load_byte(&buf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x09: { // Speed (1 unit is 1 kmh)
|
case PROP_TRAIN_SPEED: { // 0x09 Speed (1 unit is 1 km-ish/h)
|
||||||
uint16 speed = grf_load_word(&buf);
|
uint16 speed = grf_load_word(&buf);
|
||||||
if (speed == 0xFFFF) speed = 0;
|
if (speed == 0xFFFF) speed = 0;
|
||||||
|
|
||||||
rvi->max_speed = speed;
|
rvi->max_speed = speed;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case 0x0B: // Power
|
case PROP_TRAIN_POWER: // 0x0B Power
|
||||||
rvi->power = grf_load_word(&buf);
|
rvi->power = grf_load_word(&buf);
|
||||||
|
|
||||||
/* Set engine / wagon state based on power */
|
/* Set engine / wagon state based on power */
|
||||||
|
@ -526,7 +526,7 @@ static ChangeInfoResult RailVehicleChangeInfo(uint engine, int numinfo, int prop
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x0D: // Running cost factor
|
case PROP_TRAIN_RUNNING_COST_FACTOR: // 0x0D Running cost factor
|
||||||
rvi->running_cost = grf_load_byte(&buf);
|
rvi->running_cost = grf_load_byte(&buf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -567,7 +567,7 @@ static ChangeInfoResult RailVehicleChangeInfo(uint engine, int numinfo, int prop
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case 0x14: // Cargo capacity
|
case PROP_TRAIN_CARGO_CAPACITY: // 0x14 Cargo capacity
|
||||||
rvi->capacity = grf_load_byte(&buf);
|
rvi->capacity = grf_load_byte(&buf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -585,11 +585,11 @@ static ChangeInfoResult RailVehicleChangeInfo(uint engine, int numinfo, int prop
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case 0x16: // Weight
|
case PROP_TRAIN_WEIGHT: // 0x16 Weight
|
||||||
SB(rvi->weight, 0, 8, grf_load_byte(&buf));
|
SB(rvi->weight, 0, 8, grf_load_byte(&buf));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x17: // Cost factor
|
case PROP_TRAIN_COST_FACTOR: // 0x17 Cost factor
|
||||||
rvi->cost_factor = grf_load_byte(&buf);
|
rvi->cost_factor = grf_load_byte(&buf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -653,7 +653,7 @@ static ChangeInfoResult RailVehicleChangeInfo(uint engine, int numinfo, int prop
|
||||||
ei->callback_mask = grf_load_byte(&buf);
|
ei->callback_mask = grf_load_byte(&buf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x1F: // Tractive effort coefficient
|
case PROP_TRAIN_TRACTIVE_EFFORT: // 0x1F Tractive effort coefficient
|
||||||
rvi->tractive_effort = grf_load_byte(&buf);
|
rvi->tractive_effort = grf_load_byte(&buf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -686,7 +686,7 @@ static ChangeInfoResult RailVehicleChangeInfo(uint engine, int numinfo, int prop
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case 0x25: // User-defined bit mask to set when checking veh. var. 42
|
case PROP_TRAIN_USER_DATA: // 0x25 User-defined bit mask to set when checking veh. var. 42
|
||||||
rvi->user_def_data = grf_load_byte(&buf);
|
rvi->user_def_data = grf_load_byte(&buf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -769,7 +769,7 @@ static ChangeInfoResult RoadVehicleChangeInfo(uint engine, int numinfo, int prop
|
||||||
rvi->image_index = spriteid;
|
rvi->image_index = spriteid;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case 0x0F: // Cargo capacity
|
case PROP_ROADVEH_CARGO_CAPACITY: // 0x0F Cargo capacity
|
||||||
rvi->capacity = grf_load_byte(&buf);
|
rvi->capacity = grf_load_byte(&buf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -786,7 +786,7 @@ static ChangeInfoResult RoadVehicleChangeInfo(uint engine, int numinfo, int prop
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case 0x11: // Cost factor
|
case PROP_ROADVEH_COST_FACTOR: // 0x11 Cost factor
|
||||||
rvi->cost_factor = grf_load_byte(&buf);
|
rvi->cost_factor = grf_load_byte(&buf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -887,11 +887,11 @@ static ChangeInfoResult ShipVehicleChangeInfo(uint engine, int numinfo, int prop
|
||||||
svi->refittable = (grf_load_byte(&buf) != 0);
|
svi->refittable = (grf_load_byte(&buf) != 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x0A: // Cost factor
|
case PROP_SHIP_COST_FACTOR: // 0x0A Cost factor
|
||||||
svi->cost_factor = grf_load_byte(&buf);
|
svi->cost_factor = grf_load_byte(&buf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x0B: // Speed (1 unit is 0.5 kmh)
|
case PROP_SHIP_SPEED: // 0x0B Speed (1 unit is 0.5 km-ish/h)
|
||||||
svi->max_speed = grf_load_byte(&buf);
|
svi->max_speed = grf_load_byte(&buf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -908,11 +908,11 @@ static ChangeInfoResult ShipVehicleChangeInfo(uint engine, int numinfo, int prop
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case 0x0D: // Cargo capacity
|
case PROP_SHIP_CARGO_CAPACITY: // 0x0D Cargo capacity
|
||||||
svi->capacity = grf_load_word(&buf);
|
svi->capacity = grf_load_word(&buf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x0F: // Running cost factor
|
case PROP_SHIP_RUNNING_COST_FACTOR: // 0x0F Running cost factor
|
||||||
svi->running_cost = grf_load_byte(&buf);
|
svi->running_cost = grf_load_byte(&buf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1008,11 +1008,11 @@ static ChangeInfoResult AircraftVehicleChangeInfo(uint engine, int numinfo, int
|
||||||
SB(avi->subtype, 1, 1, (grf_load_byte(&buf) != 0 ? 1 : 0)); // AIR_FAST
|
SB(avi->subtype, 1, 1, (grf_load_byte(&buf) != 0 ? 1 : 0)); // AIR_FAST
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x0B: // Cost factor
|
case PROP_AIRCRAFT_COST_FACTOR: // 0x0B Cost factor
|
||||||
avi->cost_factor = grf_load_byte(&buf);
|
avi->cost_factor = grf_load_byte(&buf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x0C: // Speed (1 unit is 8 mph, we translate to 1 unit is 1 km/h)
|
case PROP_AIRCRAFT_SPEED: // 0x0C Speed (1 unit is 8 mph, we translate to 1 unit is 1 km/h)
|
||||||
avi->max_speed = (grf_load_byte(&buf) * 129) / 10;
|
avi->max_speed = (grf_load_byte(&buf) * 129) / 10;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1020,7 +1020,7 @@ static ChangeInfoResult AircraftVehicleChangeInfo(uint engine, int numinfo, int
|
||||||
avi->acceleration = (grf_load_byte(&buf) * 129) / 10;
|
avi->acceleration = (grf_load_byte(&buf) * 129) / 10;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x0E: // Running cost factor
|
case PROP_AIRCRAFT_RUNNING_COST_FACTOR: // 0x0E Running cost factor
|
||||||
avi->running_cost = grf_load_byte(&buf);
|
avi->running_cost = grf_load_byte(&buf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -1026,7 +1026,7 @@ uint16 GetVehicleCallbackParent(CallbackID callback, uint32 param1, uint32 param
|
||||||
|
|
||||||
|
|
||||||
/* Callback 36 handlers */
|
/* Callback 36 handlers */
|
||||||
uint GetVehicleProperty(const Vehicle *v, uint8 property, uint orig_value)
|
uint GetVehicleProperty(const Vehicle *v, PropertyID property, uint orig_value)
|
||||||
{
|
{
|
||||||
uint16 callback = GetVehicleCallback(CBID_VEHICLE_MODIFY_PROPERTY, property, 0, v->engine_type, v);
|
uint16 callback = GetVehicleCallback(CBID_VEHICLE_MODIFY_PROPERTY, property, 0, v->engine_type, v);
|
||||||
if (callback != CALLBACK_FAILED) return callback;
|
if (callback != CALLBACK_FAILED) return callback;
|
||||||
|
@ -1035,7 +1035,7 @@ uint GetVehicleProperty(const Vehicle *v, uint8 property, uint orig_value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint GetEngineProperty(EngineID engine, uint8 property, uint orig_value)
|
uint GetEngineProperty(EngineID engine, PropertyID property, uint orig_value)
|
||||||
{
|
{
|
||||||
uint16 callback = GetVehicleCallback(CBID_VEHICLE_MODIFY_PROPERTY, property, 0, engine, NULL);
|
uint16 callback = GetVehicleCallback(CBID_VEHICLE_MODIFY_PROPERTY, property, 0, engine, NULL);
|
||||||
if (callback != CALLBACK_FAILED) return callback;
|
if (callback != CALLBACK_FAILED) return callback;
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
#include "direction_type.h"
|
#include "direction_type.h"
|
||||||
#include "newgrf_callbacks.h"
|
#include "newgrf_callbacks.h"
|
||||||
|
#include "newgrf_properties.h"
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
TRAININFO_DEFAULT_VEHICLE_WIDTH = 29,
|
TRAININFO_DEFAULT_VEHICLE_WIDTH = 29,
|
||||||
|
@ -45,8 +46,8 @@ bool UsesWagonOverride(const Vehicle *v);
|
||||||
|
|
||||||
/* Handler to Evaluate callback 36. If the callback fails (i.e. most of the
|
/* Handler to Evaluate callback 36. If the callback fails (i.e. most of the
|
||||||
* time) orig_value is returned */
|
* time) orig_value is returned */
|
||||||
uint GetVehicleProperty(const Vehicle *v, uint8 property, uint orig_value);
|
uint GetVehicleProperty(const Vehicle *v, PropertyID property, uint orig_value);
|
||||||
uint GetEngineProperty(EngineID engine, uint8 property, uint orig_value);
|
uint GetEngineProperty(EngineID engine, PropertyID property, uint orig_value);
|
||||||
|
|
||||||
enum VehicleTrigger {
|
enum VehicleTrigger {
|
||||||
VEHICLE_TRIGGER_NEW_CARGO = 0x01,
|
VEHICLE_TRIGGER_NEW_CARGO = 0x01,
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of OpenTTD.
|
||||||
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||||
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @file newgrf_properties.h Properties of NewGRF Action 0. */
|
||||||
|
|
||||||
|
#ifndef NEWGRF_PROPERTIES_H
|
||||||
|
#define NEWGRF_PROPERTIES_H
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of NewGRF properties used in Action 0 or Callback 0x36 (CBID_VEHICLE_MODIFY_PROPERTY).
|
||||||
|
* Names are formatted as PROP_<CLASS>_<NAME>
|
||||||
|
* @todo Currently the list only contains properties which are used more than once in the code. I.e. they are available for callback 0x36.
|
||||||
|
*/
|
||||||
|
enum PropertyID {
|
||||||
|
PROP_TRAIN_SPEED = 0x09, ///< Max. speed: 1 unit = 1/1.6 mph = 1 km-ish/h
|
||||||
|
PROP_TRAIN_POWER = 0x0B, ///< Power in hp (if dualheaded: sum of both vehicles)
|
||||||
|
PROP_TRAIN_RUNNING_COST_FACTOR = 0x0D, ///< Yearly runningcost (if dualheaded: sum of both vehicles)
|
||||||
|
PROP_TRAIN_CARGO_CAPACITY = 0x14, ///< Capacity (if dualheaded: for each single vehicle)
|
||||||
|
PROP_TRAIN_WEIGHT = 0x16, ///< Weight in t (if dualheaded: for each single vehicle)
|
||||||
|
PROP_TRAIN_COST_FACTOR = 0x17, ///< Purchase cost (if dualheaded: sum of both vehicles)
|
||||||
|
PROP_TRAIN_TRACTIVE_EFFORT = 0x1F, ///< Tractive effort coefficient in 1/256
|
||||||
|
PROP_TRAIN_USER_DATA = 0x25, ///< User defined data for vehicle variable 0x42
|
||||||
|
|
||||||
|
PROP_ROADVEH_CARGO_CAPACITY = 0x0F, ///< Capacity
|
||||||
|
PROP_ROADVEH_COST_FACTOR = 0x11, ///< Purchase cost
|
||||||
|
|
||||||
|
PROP_SHIP_COST_FACTOR = 0x0A, ///< Purchase cost
|
||||||
|
PROP_SHIP_SPEED = 0x0B, ///< Max. speed: 1 unit = 1/3.2 mph = 0.5 km-ish/h
|
||||||
|
PROP_SHIP_CARGO_CAPACITY = 0x0D, ///< Capacity
|
||||||
|
PROP_SHIP_RUNNING_COST_FACTOR = 0x0F, ///< Yearly runningcost
|
||||||
|
|
||||||
|
PROP_AIRCRAFT_COST_FACTOR = 0x0B, ///< Purchase cost
|
||||||
|
PROP_AIRCRAFT_SPEED = 0x0C, ///< Max. speed: 1 unit = 8 mph = 12.8 km-ish/h
|
||||||
|
PROP_AIRCRAFT_RUNNING_COST_FACTOR = 0x0E, ///< Yearly runningcost
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* NEWGRF_PROPERTIES_H */
|
|
@ -1268,7 +1268,7 @@ Vehicle *UpdateTrainPowerProc(Vehicle *v, void *data)
|
||||||
if (t->IsArticulatedPart()) return NULL;
|
if (t->IsArticulatedPart()) return NULL;
|
||||||
|
|
||||||
const RailVehicleInfo *rvi = RailVehInfo(t->engine_type);
|
const RailVehicleInfo *rvi = RailVehInfo(t->engine_type);
|
||||||
if (GetVehicleProperty(t, 0x0B, rvi->power) != 0) TrainPowerChanged(t->First());
|
if (GetVehicleProperty(t, PROP_TRAIN_POWER, rvi->power) != 0) TrainPowerChanged(t->First());
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -288,7 +288,7 @@ CommandCost CmdBuildRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
|
||||||
for (RoadVehicle *u = v; u != NULL; u = u->Next()) {
|
for (RoadVehicle *u = v; u != NULL; u = u->Next()) {
|
||||||
u->rcache.cached_veh_length = GetRoadVehLength(u);
|
u->rcache.cached_veh_length = GetRoadVehLength(u);
|
||||||
/* Cargo capacity is zero if and only if the vehicle cannot carry anything */
|
/* Cargo capacity is zero if and only if the vehicle cannot carry anything */
|
||||||
if (u->cargo_cap != 0) u->cargo_cap = GetVehicleProperty(u, 0x0F, u->cargo_cap);
|
if (u->cargo_cap != 0) u->cargo_cap = GetVehicleProperty(u, PROP_ROADVEH_CARGO_CAPACITY, u->cargo_cap);
|
||||||
v->InvalidateNewGRFCache();
|
v->InvalidateNewGRFCache();
|
||||||
u->InvalidateNewGRFCache();
|
u->InvalidateNewGRFCache();
|
||||||
}
|
}
|
||||||
|
@ -2054,7 +2054,7 @@ CommandCost CmdRefitRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
|
||||||
* carry twice as much mail/goods as normal cargo, and four times as
|
* carry twice as much mail/goods as normal cargo, and four times as
|
||||||
* many passengers
|
* many passengers
|
||||||
*/
|
*/
|
||||||
capacity = GetVehicleProperty(v, 0x0F, e->u.road.capacity);
|
capacity = GetVehicleProperty(v, PROP_ROADVEH_CARGO_CAPACITY, e->u.road.capacity);
|
||||||
switch (old_cid) {
|
switch (old_cid) {
|
||||||
case CT_PASSENGERS: break;
|
case CT_PASSENGERS: break;
|
||||||
case CT_MAIL:
|
case CT_MAIL:
|
||||||
|
|
|
@ -158,7 +158,7 @@ static void CheckIfShipNeedsService(Vehicle *v)
|
||||||
|
|
||||||
Money Ship::GetRunningCost() const
|
Money Ship::GetRunningCost() const
|
||||||
{
|
{
|
||||||
return GetVehicleProperty(this, 0x0F, ShipVehInfo(this->engine_type)->running_cost) * _price.ship_running;
|
return GetVehicleProperty(this, PROP_SHIP_RUNNING_COST_FACTOR, ShipVehInfo(this->engine_type)->running_cost) * _price.ship_running;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ship::OnNewDay()
|
void Ship::OnNewDay()
|
||||||
|
@ -334,7 +334,7 @@ static bool ShipAccelerate(Vehicle *v)
|
||||||
uint spd;
|
uint spd;
|
||||||
byte t;
|
byte t;
|
||||||
|
|
||||||
spd = min(v->cur_speed + 1, GetVehicleProperty(v, 0x0B, v->max_speed));
|
spd = min(v->cur_speed + 1, GetVehicleProperty(v, PROP_SHIP_SPEED, v->max_speed));
|
||||||
|
|
||||||
/* updates statusbar only if speed have changed to save CPU time */
|
/* updates statusbar only if speed have changed to save CPU time */
|
||||||
if (spd != v->cur_speed) {
|
if (spd != v->cur_speed) {
|
||||||
|
@ -815,7 +815,7 @@ CommandCost CmdBuildShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
||||||
|
|
||||||
v->InvalidateNewGRFCacheOfChain();
|
v->InvalidateNewGRFCacheOfChain();
|
||||||
|
|
||||||
v->cargo_cap = GetVehicleProperty(v, 0x0D, svi->capacity);
|
v->cargo_cap = GetVehicleProperty(v, PROP_SHIP_CARGO_CAPACITY, svi->capacity);
|
||||||
|
|
||||||
v->InvalidateNewGRFCacheOfChain();
|
v->InvalidateNewGRFCacheOfChain();
|
||||||
|
|
||||||
|
@ -942,7 +942,7 @@ CommandCost CmdRefitShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
if (capacity == CALLBACK_FAILED) {
|
if (capacity == CALLBACK_FAILED) {
|
||||||
capacity = GetVehicleProperty(v, 0x0D, ShipVehInfo(v->engine_type)->capacity);
|
capacity = GetVehicleProperty(v, PROP_SHIP_CARGO_CAPACITY, ShipVehInfo(v->engine_type)->capacity);
|
||||||
}
|
}
|
||||||
_returned_refit_capacity = capacity;
|
_returned_refit_capacity = capacity;
|
||||||
|
|
||||||
|
|
|
@ -107,14 +107,14 @@ void TrainPowerChanged(Train *v)
|
||||||
const RailVehicleInfo *rvi_u = RailVehInfo(u->engine_type);
|
const RailVehicleInfo *rvi_u = RailVehInfo(u->engine_type);
|
||||||
|
|
||||||
if (engine_has_power) {
|
if (engine_has_power) {
|
||||||
uint16 power = GetVehicleProperty(u, 0x0B, rvi_u->power);
|
uint16 power = GetVehicleProperty(u, PROP_TRAIN_POWER, rvi_u->power);
|
||||||
if (power != 0) {
|
if (power != 0) {
|
||||||
/* Halve power for multiheaded parts */
|
/* Halve power for multiheaded parts */
|
||||||
if (u->IsMultiheaded()) power /= 2;
|
if (u->IsMultiheaded()) power /= 2;
|
||||||
|
|
||||||
total_power += power;
|
total_power += power;
|
||||||
/* Tractive effort in (tonnes * 1000 * 10 =) N */
|
/* Tractive effort in (tonnes * 1000 * 10 =) N */
|
||||||
max_te += (u->tcache.cached_veh_weight * 10000 * GetVehicleProperty(u, 0x1F, rvi_u->tractive_effort)) / 256;
|
max_te += (u->tcache.cached_veh_weight * 10000 * GetVehicleProperty(u, PROP_TRAIN_TRACTIVE_EFFORT, rvi_u->tractive_effort)) / 256;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,7 +151,7 @@ static void TrainCargoChanged(Train *v)
|
||||||
/* Vehicle weight is not added for articulated parts. */
|
/* Vehicle weight is not added for articulated parts. */
|
||||||
if (!u->IsArticulatedPart()) {
|
if (!u->IsArticulatedPart()) {
|
||||||
/* vehicle weight is the sum of the weight of the vehicle and the weight of its cargo */
|
/* vehicle weight is the sum of the weight of the vehicle and the weight of its cargo */
|
||||||
vweight += GetVehicleProperty(u, 0x16, RailVehInfo(u->engine_type)->weight);
|
vweight += GetVehicleProperty(u, PROP_TRAIN_WEIGHT, RailVehInfo(u->engine_type)->weight);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* powered wagons have extra weight added */
|
/* powered wagons have extra weight added */
|
||||||
|
@ -253,7 +253,7 @@ void TrainConsistChanged(Train *v, bool same_length)
|
||||||
|
|
||||||
for (Train *u = v; u != NULL; u = u->Next()) {
|
for (Train *u = v; u != NULL; u = u->Next()) {
|
||||||
/* Update user defined data (must be done before other properties) */
|
/* Update user defined data (must be done before other properties) */
|
||||||
u->tcache.user_def_data = GetVehicleProperty(u, 0x25, u->tcache.user_def_data);
|
u->tcache.user_def_data = GetVehicleProperty(u, PROP_TRAIN_USER_DATA, u->tcache.user_def_data);
|
||||||
v->InvalidateNewGRFCache();
|
v->InvalidateNewGRFCache();
|
||||||
u->InvalidateNewGRFCache();
|
u->InvalidateNewGRFCache();
|
||||||
}
|
}
|
||||||
|
@ -316,14 +316,14 @@ void TrainConsistChanged(Train *v, bool same_length)
|
||||||
|
|
||||||
/* max speed is the minimum of the speed limits of all vehicles in the consist */
|
/* max speed is the minimum of the speed limits of all vehicles in the consist */
|
||||||
if ((rvi_u->railveh_type != RAILVEH_WAGON || _settings_game.vehicle.wagon_speed_limits) && !UsesWagonOverride(u)) {
|
if ((rvi_u->railveh_type != RAILVEH_WAGON || _settings_game.vehicle.wagon_speed_limits) && !UsesWagonOverride(u)) {
|
||||||
uint16 speed = GetVehicleProperty(u, 0x09, rvi_u->max_speed);
|
uint16 speed = GetVehicleProperty(u, PROP_TRAIN_SPEED, rvi_u->max_speed);
|
||||||
if (speed != 0) max_speed = min(speed, max_speed);
|
if (speed != 0) max_speed = min(speed, max_speed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e_u->CanCarryCargo() && u->cargo_type == e_u->GetDefaultCargoType() && u->cargo_subtype == 0) {
|
if (e_u->CanCarryCargo() && u->cargo_type == e_u->GetDefaultCargoType() && u->cargo_subtype == 0) {
|
||||||
/* Set cargo capacity if we've not been refitted */
|
/* Set cargo capacity if we've not been refitted */
|
||||||
u->cargo_cap = GetVehicleProperty(u, 0x14, rvi_u->capacity);
|
u->cargo_cap = GetVehicleProperty(u, PROP_TRAIN_CARGO_CAPACITY, rvi_u->capacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check the vehicle length (callback) */
|
/* check the vehicle length (callback) */
|
||||||
|
@ -4491,7 +4491,7 @@ Money Train::GetRunningCost() const
|
||||||
do {
|
do {
|
||||||
const RailVehicleInfo *rvi = RailVehInfo(v->engine_type);
|
const RailVehicleInfo *rvi = RailVehInfo(v->engine_type);
|
||||||
|
|
||||||
byte cost_factor = GetVehicleProperty(v, 0x0D, rvi->running_cost);
|
byte cost_factor = GetVehicleProperty(v, PROP_TRAIN_RUNNING_COST_FACTOR, rvi->running_cost);
|
||||||
if (cost_factor == 0) continue;
|
if (cost_factor == 0) continue;
|
||||||
|
|
||||||
/* Halve running cost for multiheaded parts */
|
/* Halve running cost for multiheaded parts */
|
||||||
|
|
Loading…
Reference in New Issue