Update to 12.0-beta1
This commit is contained in:
+20
-46
@@ -26,62 +26,29 @@
|
||||
|
||||
#include "safeguards.h"
|
||||
|
||||
struct WagonOverride {
|
||||
EngineID *train_id;
|
||||
uint trains;
|
||||
CargoID cargo;
|
||||
const SpriteGroup *group;
|
||||
};
|
||||
|
||||
void SetWagonOverrideSprites(EngineID engine, CargoID cargo, const SpriteGroup *group, EngineID *train_id, uint trains)
|
||||
{
|
||||
Engine *e = Engine::Get(engine);
|
||||
WagonOverride *wo;
|
||||
|
||||
assert(cargo < NUM_CARGO + 2); // Include CT_DEFAULT and CT_PURCHASE pseudo cargoes.
|
||||
|
||||
e->overrides_count++;
|
||||
e->overrides = ReallocT(e->overrides, e->overrides_count);
|
||||
|
||||
wo = &e->overrides[e->overrides_count - 1];
|
||||
WagonOverride *wo = &e->overrides.emplace_back();
|
||||
wo->group = group;
|
||||
wo->cargo = cargo;
|
||||
wo->trains = trains;
|
||||
wo->train_id = MallocT<EngineID>(trains);
|
||||
memcpy(wo->train_id, train_id, trains * sizeof *train_id);
|
||||
wo->engines.assign(train_id, train_id + trains);
|
||||
}
|
||||
|
||||
const SpriteGroup *GetWagonOverrideSpriteSet(EngineID engine, CargoID cargo, EngineID overriding_engine)
|
||||
{
|
||||
const Engine *e = Engine::Get(engine);
|
||||
|
||||
for (uint i = 0; i < e->overrides_count; i++) {
|
||||
const WagonOverride *wo = &e->overrides[i];
|
||||
|
||||
if (wo->cargo != cargo && wo->cargo != CT_DEFAULT) continue;
|
||||
|
||||
for (uint j = 0; j < wo->trains; j++) {
|
||||
if (wo->train_id[j] == overriding_engine) return wo->group;
|
||||
}
|
||||
for (const WagonOverride &wo : e->overrides) {
|
||||
if (wo.cargo != cargo && wo.cargo != CT_DEFAULT) continue;
|
||||
if (std::find(wo.engines.begin(), wo.engines.end(), overriding_engine) != wo.engines.end()) return wo.group;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unload all wagon override sprite groups.
|
||||
*/
|
||||
void UnloadWagonOverrides(Engine *e)
|
||||
{
|
||||
for (uint i = 0; i < e->overrides_count; i++) {
|
||||
WagonOverride *wo = &e->overrides[i];
|
||||
free(wo->train_id);
|
||||
}
|
||||
free(e->overrides);
|
||||
e->overrides_count = 0;
|
||||
e->overrides = nullptr;
|
||||
}
|
||||
|
||||
|
||||
void SetCustomEngineSprites(EngineID engine, byte cargo, const SpriteGroup *group)
|
||||
{
|
||||
Engine *e = Engine::Get(engine);
|
||||
@@ -979,7 +946,7 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
|
||||
default: break;
|
||||
}
|
||||
|
||||
DEBUG(grf, 1, "Unhandled vehicle variable 0x%X, type 0x%X", variable, (uint)v->type);
|
||||
Debug(grf, 1, "Unhandled vehicle variable 0x{:X}, type 0x{:X}", variable, (uint)v->type);
|
||||
|
||||
*available = false;
|
||||
return UINT_MAX;
|
||||
@@ -1025,14 +992,14 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
|
||||
const Vehicle *v = this->self_scope.v;
|
||||
|
||||
if (v == nullptr) {
|
||||
if (group->num_loading > 0) return group->loading[0];
|
||||
if (group->num_loaded > 0) return group->loaded[0];
|
||||
if (!group->loading.empty()) return group->loading[0];
|
||||
if (!group->loaded.empty()) return group->loaded[0];
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool in_motion = !v->First()->current_order.IsType(OT_LOADING);
|
||||
|
||||
uint totalsets = in_motion ? group->num_loaded : group->num_loading;
|
||||
uint totalsets = in_motion ? (uint)group->loaded.size() : (uint)group->loading.size();
|
||||
|
||||
if (totalsets == 0) return nullptr;
|
||||
|
||||
@@ -1210,16 +1177,23 @@ uint16 GetVehicleCallbackParent(CallbackID callback, uint32 param1, uint32 param
|
||||
|
||||
|
||||
/* Callback 36 handlers */
|
||||
uint GetVehicleProperty(const Vehicle *v, PropertyID property, uint orig_value)
|
||||
int GetVehicleProperty(const Vehicle *v, PropertyID property, int orig_value, bool is_signed)
|
||||
{
|
||||
return GetEngineProperty(v->engine_type, property, orig_value, v);
|
||||
return GetEngineProperty(v->engine_type, property, orig_value, v, is_signed);
|
||||
}
|
||||
|
||||
|
||||
uint GetEngineProperty(EngineID engine, PropertyID property, uint orig_value, const Vehicle *v)
|
||||
int GetEngineProperty(EngineID engine, PropertyID property, int orig_value, const Vehicle *v, bool is_signed)
|
||||
{
|
||||
uint16 callback = GetVehicleCallback(CBID_VEHICLE_MODIFY_PROPERTY, property, 0, engine, v);
|
||||
if (callback != CALLBACK_FAILED) return callback;
|
||||
if (callback != CALLBACK_FAILED) {
|
||||
if (is_signed) {
|
||||
/* Sign extend 15 bit integer */
|
||||
return static_cast<int16>(callback << 1) / 2;
|
||||
} else {
|
||||
return callback;
|
||||
}
|
||||
}
|
||||
|
||||
return orig_value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user