(svn r4703) - NewGRF: add support for callback 0x1D, "can wagon be attached". This can be used to disallow freight wagons to be placed in passenger trains, along with other uses.
authorpeter1138
Tue, 02 May 2006 21:43:47 +0000
changeset 3727 b4d9a8ab4ce4
parent 3726 a446208c7296
child 3728 1ebf0a7a2492
(svn r4703) - NewGRF: add support for callback 0x1D, "can wagon be attached". This can be used to disallow freight wagons to be placed in passenger trains, along with other uses.
newgrf_callbacks.h
train_cmd.c
--- a/newgrf_callbacks.h	Tue May 02 21:42:11 2006 +0000
+++ b/newgrf_callbacks.h	Tue May 02 21:43:47 2006 +0000
@@ -25,6 +25,8 @@
 
 	CBID_TRAIN_ARTIC_ENGINE         = 0x16,
 
+	CBID_TRAIN_ALLOW_WAGON_ATTACH   = 0x1D,
+
 	/* This callback is called from vehicle purchase lists. It returns a value to be
 	 * used as a custom string ID in the 0xD000 range. */
 	CBID_VEHICLE_ADDITIONAL_TEXT    = 0x23,
--- a/train_cmd.c	Tue May 02 21:42:11 2006 +0000
+++ b/train_cmd.c	Tue May 02 21:43:47 2006 +0000
@@ -27,6 +27,7 @@
 #include "train.h"
 #include "newgrf_callbacks.h"
 #include "newgrf_engine.h"
+#include "newgrf_text.h"
 #include "direction.h"
 
 static bool TrainCheckIfLineEnds(Vehicle *v);
@@ -1076,6 +1077,17 @@
 		if (flags & DC_EXEC) src->unitnumber = unit_num;
 	}
 
+	if (dst_head != NULL) {
+		/* Check NewGRF Callback 0x1D */
+		uint16 callback = GetVehicleCallbackParent(CBID_TRAIN_ALLOW_WAGON_ATTACH, 0, 0, dst_head->engine_type, src, dst_head);
+		if (callback != CALLBACK_FAILED) {
+			if (callback == 0xFD) return CMD_ERROR;
+			if (callback < 0xFD) {
+				StringID error = GetGRFStringID(GetEngineGRFID(dst_head->engine_type), 0xD000 + callback);
+				return_cmd_error(error);
+			}
+		}
+	}
 
 	/* do it? */
 	if (flags & DC_EXEC) {