summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2009-06-21 10:11:04 +0000
committeryexo <yexo@openttd.org>2009-06-21 10:11:04 +0000
commit548a605263f7764602d6ee7fc9ca3856bf00918b (patch)
tree6eabc072c7905e2561c83ddfb8cc0efd51147c75
parent41c8baa7dcf38e85b1ebbee9de77d5b5a31b6622 (diff)
downloadopenttd-548a605263f7764602d6ee7fc9ca3856bf00918b.tar.xz
(svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
-rw-r--r--src/newgrf_engine.cpp22
-rw-r--r--src/order_base.h7
-rw-r--r--src/order_cmd.cpp22
3 files changed, 44 insertions, 7 deletions
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp
index 1637aef46..89da896ad 100644
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -130,10 +130,18 @@ uint32 GetEngineGRFID(EngineID engine)
static int MapOldSubType(const Vehicle *v)
{
- if (v->type != VEH_TRAIN) return v->subtype;
- if (IsTrainEngine(v)) return 0;
- if (IsFreeWagon(v)) return 4;
- return 2;
+ switch (v->type) {
+ case VEH_TRAIN:
+ if (IsTrainEngine(v)) return 0;
+ if (IsFreeWagon(v)) return 4;
+ return 2;
+ case VEH_ROAD:
+ case VEH_SHIP: return 0;
+ case VEH_AIRCRAFT:
+ case VEH_DISASTER: return v->subtype;
+ case VEH_EFFECT: return v->subtype << 1;
+ default: NOT_REACHED();
+ }
}
@@ -687,12 +695,12 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
/* General vehicle properties */
switch (variable - 0x80) {
- case 0x00: return v->type;
+ case 0x00: return v->type + 2;
case 0x01: return MapOldSubType(v);
case 0x04: return v->index;
case 0x05: return GB(v->index, 8, 8);
- case 0x0A: return v->current_order.Pack();
- case 0x0B: return GB(v->current_order.Pack(), 8, 8);
+ case 0x0A: return v->current_order.MapOldOrder();
+ case 0x0B: return v->current_order.GetDestination();
case 0x0C: return v->GetNumOrders();
case 0x0D: return v->cur_order_index;
case 0x10: return v->load_unload_time_rem;
diff --git a/src/order_base.h b/src/order_base.h
index 442a9ae21..4b1aba9b4 100644
--- a/src/order_base.h
+++ b/src/order_base.h
@@ -233,6 +233,13 @@ public:
uint32 Pack() const;
/**
+ * Pack this order into a 16 bits integer as close to the TTD
+ * representation as possible.
+ * @return the TTD-like packed representation.
+ */
+ uint16 MapOldOrder() const;
+
+ /**
* Converts this order from an old savegame's version;
* it moves all bits to the new location.
*/
diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp
index 48e2f6fd5..2ec2110c6 100644
--- a/src/order_cmd.cpp
+++ b/src/order_cmd.cpp
@@ -129,6 +129,28 @@ uint32 Order::Pack() const
return this->dest << 16 | this->flags << 8 | this->type;
}
+uint16 Order::MapOldOrder() const
+{
+ uint16 order = this->GetType();
+ switch (this->type) {
+ case OT_GOTO_STATION:
+ if (this->GetUnloadType() & OUFB_UNLOAD) SetBit(order, 5);
+ if (this->GetLoadType() & OLFB_FULL_LOAD) SetBit(order, 6);
+ if (this->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) SetBit(order, 7);
+ order |= GB(this->GetDestination(), 0, 8) << 8;
+ break;
+ case OT_GOTO_DEPOT:
+ if (!(this->GetDepotOrderType() & ODTFB_PART_OF_ORDERS)) SetBit(order, 6);
+ SetBit(order, 7);
+ order |= GB(this->GetDestination(), 0, 8) << 8;
+ break;
+ case OT_LOADING:
+ if (this->GetLoadType() & OLFB_FULL_LOAD) SetBit(order, 6);
+ break;
+ }
+ return order;
+}
+
Order::Order(uint32 packed)
{
this->type = (OrderType)GB(packed, 0, 8);