(svn r13525) [NoAI] -Add: added AIEventEngineAvailable and AIEventStationFirstVehicle noai
authorglx
Sun, 15 Jun 2008 22:18:10 +0000
branchnoai
changeset 10971 aaf89f8c59b9
parent 10958 65088d587094
child 10972 986675d19245
(svn r13525) [NoAI] -Add: added AIEventEngineAvailable and AIEventStationFirstVehicle
src/ai/api/ai_controller.cpp
src/ai/api/ai_event.hpp
src/ai/api/ai_event.hpp.sq
src/ai/api/ai_event_types.hpp
src/ai/api/ai_event_types.hpp.sq
src/aircraft_cmd.cpp
src/engine.cpp
src/roadveh_cmd.cpp
src/ship_cmd.cpp
src/train_cmd.cpp
--- a/src/ai/api/ai_controller.cpp	Fri Jun 13 20:19:00 2008 +0000
+++ b/src/ai/api/ai_controller.cpp	Sun Jun 15 22:18:10 2008 +0000
@@ -99,6 +99,7 @@
 	SQAIEventCompanyMerger_Register(this->engine);
 	SQAIEventCompanyNew_Register(this->engine);
 	SQAIEventController_Register(this->engine);
+	SQAIEventEngineAvailable_Register(this->engine);
 	SQAIEventEnginePreview_Register(this->engine);
 	SQAIEventIndustryClose_Register(this->engine);
 	SQAIEventIndustryOpen_Register(this->engine);
--- a/src/ai/api/ai_event.hpp	Fri Jun 13 20:19:00 2008 +0000
+++ b/src/ai/api/ai_event.hpp	Sun Jun 15 22:18:10 2008 +0000
@@ -37,6 +37,8 @@
 		AI_ET_VEHICLE_UNPROFITABLE,
 		AI_ET_INDUSTRY_OPEN,
 		AI_ET_INDUSTRY_CLOSE,
+		AI_ET_ENGINE_AVAILABLE,
+		AI_ET_STATION_FIRST_VEHICLE,
 	};
 
 	/**
--- a/src/ai/api/ai_event.hpp.sq	Fri Jun 13 20:19:00 2008 +0000
+++ b/src/ai/api/ai_event.hpp.sq	Sun Jun 15 22:18:10 2008 +0000
@@ -38,6 +38,8 @@
 	SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_VEHICLE_UNPROFITABLE,     "AI_ET_VEHICLE_UNPROFITABLE");
 	SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_INDUSTRY_OPEN,            "AI_ET_INDUSTRY_OPEN");
 	SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_INDUSTRY_CLOSE,           "AI_ET_INDUSTRY_CLOSE");
+	SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_ENGINE_AVAILABLE,         "AI_ET_ENGINE_AVAILABLE");
+	SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_STATION_FIRST_VEHICLE,    "AI_ET_STATION_FIRST_VEHICLE");
 
 	SQAIEvent.DefSQStaticMethod(engine, &AIEvent::GetClassName, "GetClassName", 1, "x");
 
--- a/src/ai/api/ai_event_types.hpp	Fri Jun 13 20:19:00 2008 +0000
+++ b/src/ai/api/ai_event_types.hpp	Sun Jun 15 22:18:10 2008 +0000
@@ -608,4 +608,77 @@
 	IndustryID industry_id;
 };
 
+/**
+ * Event Engine Available, indicating a new engine is available.
+ */
+class AIEventEngineAvailable : public AIEvent {
+public:
+	static const char *GetClassName() { return "AIEventEngineAvailable"; }
+
+	/**
+	 * @param engine The engine that is available.
+	 */
+	AIEventEngineAvailable(EngineID engine) :
+		AIEvent(AI_ET_ENGINE_AVAILABLE),
+		engine(engine)
+	{}
+
+	/**
+	 * Convert an AIEvent to the real instance.
+	 * @param instance The instance to convert.
+	 * @return The converted instance.
+	 */
+	static AIEventEngineAvailable *Convert(AIEvent *instance) { return (AIEventEngineAvailable *)instance; }
+
+	/**
+	 * Get the EngineID of the new engine.
+	 * @return The EngineID of the new engine.
+	 */
+	EngineID GetEngineID() { return engine; };
+
+private:
+	EngineID engine;
+};
+
+/**
+ * Event Station First Vehicle, indicating a station has been visited by a vehicle for the first time.
+ */
+class AIEventStationFirstVehicle : public AIEvent {
+public:
+	static const char *GetClassName() { return "AIEventStationFirstVehicle"; }
+
+	/**
+	 * @param station The station visited for the first time.
+	 * @param vehicle The vehicle visiting the station.
+	 */
+	AIEventStationFirstVehicle(StationID station, VehicleID vehicle) :
+		AIEvent(AI_ET_STATION_FIRST_VEHICLE),
+		station(station),
+		vehicle(vehicle)
+	{}
+
+	/**
+	 * Convert an AIEvent to the real instance.
+	 * @param instance The instance to convert.
+	 * @return The converted instance.
+	 */
+	static AIEventStationFirstVehicle *Convert(AIEvent *instance) { return (AIEventStationFirstVehicle *)instance; }
+
+	/**
+	 * Get the StationID of the visited station.
+	 * @return The StationID of the visited station.
+	 */
+	StationID GetStationID() { return station; };
+
+	/**
+	 * Get the VehicleID of the first vehicle.
+	 * @return The VehicleID of the first vehicle.
+	 */
+	VehicleID GetVehicleID() { return vehicle; };
+
+private:
+	StationID station;
+	VehicleID vehicle;
+};
+
 #endif /* AI_EVENT_TYPES_HPP */
--- a/src/ai/api/ai_event_types.hpp.sq	Fri Jun 13 20:19:00 2008 +0000
+++ b/src/ai/api/ai_event_types.hpp.sq	Sun Jun 15 22:18:10 2008 +0000
@@ -348,3 +348,22 @@
 
 	SQAIEventIndustryClose.PostRegister(engine);
 }
+
+namespace SQConvert {
+	/* Allow AIEventEngineAvailable to be used as Squirrel parameter */
+	template <> AIEventEngineAvailable *GetParam(ForceType<AIEventEngineAvailable *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return  (AIEventEngineAvailable *)instance; }
+	template <> AIEventEngineAvailable &GetParam(ForceType<AIEventEngineAvailable &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIEventEngineAvailable *)instance; }
+	template <> const AIEventEngineAvailable *GetParam(ForceType<const AIEventEngineAvailable *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return  (AIEventEngineAvailable *)instance; }
+	template <> const AIEventEngineAvailable &GetParam(ForceType<const AIEventEngineAvailable &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIEventEngineAvailable *)instance; }
+	template <> int Return<AIEventEngineAvailable *>(HSQUIRRELVM vm, AIEventEngineAvailable *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "AIEventEngineAvailable", res, NULL, DefSQDestructorCallback<AIEventEngineAvailable>); return 1; }
+}; // namespace SQConvert
+
+void SQAIEventEngineAvailable_Register(Squirrel *engine) {
+	DefSQClass <AIEventEngineAvailable> SQAIEventEngineAvailable("AIEventEngineAvailable");
+	SQAIEventEngineAvailable.PreRegister(engine, "AIEvent");
+
+	SQAIEventEngineAvailable.DefSQStaticMethod(engine, &AIEventEngineAvailable::GetClassName, "GetClassName", 1, "x");
+	SQAIEventEngineAvailable.DefSQStaticMethod(engine, &AIEventEngineAvailable::Convert,      "Convert",      2, "xx");
+
+	SQAIEventEngineAvailable.PostRegister(engine);
+}
--- a/src/aircraft_cmd.cpp	Fri Jun 13 20:19:00 2008 +0000
+++ b/src/aircraft_cmd.cpp	Sun Jun 15 22:18:10 2008 +0000
@@ -1451,6 +1451,7 @@
 			(v->owner == _local_player) ? NS_ARRIVAL_PLAYER : NS_ARRIVAL_OTHER,
 			v->index,
 			0);
+		AI_Event(v->owner, new AIEventStationFirstVehicle(st->index, v->index));
 	}
 
 	v->BeginLoading();
--- a/src/engine.cpp	Fri Jun 13 20:19:00 2008 +0000
+++ b/src/engine.cpp	Sun Jun 15 22:18:10 2008 +0000
@@ -435,6 +435,10 @@
 		}
 	}
 
+	for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) {
+		AI_Event(i, new AIEventEngineAvailable(index));
+	}
+
 	SetDParam(0, GetEngineCategoryName(index));
 	SetDParam(1, index);
 	AddNewsItem(STR_NEW_VEHICLE_NOW_AVAILABLE_WITH_TYPE, NS_NEW_VEHICLES, index, 0);
--- a/src/roadveh_cmd.cpp	Fri Jun 13 20:19:00 2008 +0000
+++ b/src/roadveh_cmd.cpp	Sun Jun 15 22:18:10 2008 +0000
@@ -836,6 +836,7 @@
 				(v->owner == _local_player) ? NS_ARRIVAL_PLAYER : NS_ARRIVAL_OTHER,
 				v->index,
 				0);
+			AI_Event(v->owner, new AIEventStationFirstVehicle(st->index, v->index));
 		}
 	} else {
 		/* Check if station was ever visited before */
@@ -848,6 +849,7 @@
 				v->index,
 				0
 			);
+			AI_Event(v->owner, new AIEventStationFirstVehicle(st->index, v->index));
 		}
 	}
 }
--- a/src/ship_cmd.cpp	Fri Jun 13 20:19:00 2008 +0000
+++ b/src/ship_cmd.cpp	Sun Jun 15 22:18:10 2008 +0000
@@ -353,6 +353,7 @@
 			(v->owner == _local_player) ? NS_ARRIVAL_PLAYER : NS_ARRIVAL_OTHER,
 			v->index,
 			0);
+		AI_Event(v->owner, new AIEventStationFirstVehicle(st->index, v->index));
 	}
 }
 
--- a/src/train_cmd.cpp	Fri Jun 13 20:19:00 2008 +0000
+++ b/src/train_cmd.cpp	Sun Jun 15 22:18:10 2008 +0000
@@ -2653,6 +2653,7 @@
 			v->index,
 			0
 		);
+		AI_Event(v->owner, new AIEventStationFirstVehicle(st->index, v->index));
 	}
 
 	v->BeginLoading();