summaryrefslogtreecommitdiff
path: root/src/newgrf_engine.cpp
diff options
context:
space:
mode:
authorVít Šefl <vituscze@gmail.com>2021-08-15 11:17:05 +0200
committerGitHub <noreply@github.com>2021-08-15 11:17:05 +0200
commit2183fd4dabe72bd96b264bf8cdb3a2a8be625cf8 (patch)
tree7a94f94723ac65e43d5ab856d5945b3bce9a5b31 /src/newgrf_engine.cpp
parent579f393374c4fae2458523a674c453349fce7c59 (diff)
downloadopenttd-2183fd4dabe72bd96b264bf8cdb3a2a8be625cf8.tar.xz
Feature: [NewGRF] Maximum curve speed modifier for rail vehicles (#9346)
Diffstat (limited to 'src/newgrf_engine.cpp')
-rw-r--r--src/newgrf_engine.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp
index fa26f7b68..e57410224 100644
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -1177,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) >> 1;
+ } else {
+ return callback;
+ }
+ }
return orig_value;
}