summaryrefslogtreecommitdiff
path: root/vehicle.c
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2005-05-14 12:36:16 +0000
committerDarkvater <darkvater@openttd.org>2005-05-14 12:36:16 +0000
commit5174d3adfe9e3b120fd2c50847c7f9cf772a702b (patch)
tree1e61fee7bb3cc51b1847fb0b48b1f3cec7699f5a /vehicle.c
parent3a4bedaad61c990c511cd1c23380546a9eebd358 (diff)
downloadopenttd-5174d3adfe9e3b120fd2c50847c7f9cf772a702b.tar.xz
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Diffstat (limited to 'vehicle.c')
-rw-r--r--vehicle.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/vehicle.c b/vehicle.c
index 025bb0679..a705ed93b 100644
--- a/vehicle.c
+++ b/vehicle.c
@@ -501,6 +501,28 @@ bool CanFillVehicle(Vehicle *v)
return false;
}
+/** Check if a given vehicle (type) can be refitted to a given cargo
+ * @param *v vehicle to check
+ * @param cid_to check refit to this cargo-type
+ * @return true if it is possible, false otherwise
+ */
+bool CanRefitTo(const Vehicle *v, CargoID cid_to)
+{
+ CargoID cid = _global_cargo_id[_opt_ptr->landscape][cid_to];
+
+ if (cid == GC_INVALID) return false;
+
+ if (_engine_refit_masks[v->engine_type]) {
+ if (!HASBIT(_engine_refit_masks[v->engine_type], cid)) return false;
+ } else {
+ /* If we are talking about normal vehicles (no newgrf), you can only refit engines */
+ if (v->type == VEH_Train && (RailVehInfo(v->engine_type)->flags & RVI_WAGON)) return false;
+ if (!HASBIT(_default_refitmasks[v->type - VEH_Train], cid)) return false;
+ }
+
+ return true;
+}
+
static void DoDrawVehicle(Vehicle *v)
{
uint32 image = v->cur_image;