vehicle.c
changeset 1802 448f187042d3
parent 1796 cae31916ae54
child 1820 9b6458526480
--- a/vehicle.c	Sat May 14 06:48:14 2005 +0000
+++ b/vehicle.c	Sat May 14 12:36:16 2005 +0000
@@ -501,6 +501,28 @@
 	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;