Index: src/ai/ai_instance.cpp =================================================================== --- src/ai/ai_instance.cpp (révision 24489) +++ src/ai/ai_instance.cpp (copie de travail) @@ -145,6 +145,7 @@ SQAIEventTownFounded_Register(this->engine); SQAIEventVehicleCrashed_Register(this->engine); SQAIEventVehicleLost_Register(this->engine); + SQAIEventVehicleOld_Register(this->engine); SQAIEventVehicleUnprofitable_Register(this->engine); SQAIEventVehicleWaitingInDepot_Register(this->engine); SQAIExecMode_Register(this->engine); Index: src/script/api/script_event.hpp =================================================================== --- src/script/api/script_event.hpp (révision 24489) +++ src/script/api/script_event.hpp (copie de travail) @@ -53,6 +53,7 @@ ET_ADMIN_PORT, ET_WINDOW_WIDGET_CLICK, ET_GOAL_QUESTION_ANSWER, + ET_VEHICLE_OLD, ET_EXCLUSIVE_TRANSPORT_RIGHTS, ET_ROAD_RECONSTRUCTION, }; Index: src/script/api/game/game_event.hpp.sq =================================================================== --- src/script/api/game/game_event.hpp.sq (révision 24489) +++ src/script/api/game/game_event.hpp.sq (copie de travail) @@ -48,6 +48,7 @@ SQGSEvent.DefSQConst(engine, ScriptEvent::ET_ADMIN_PORT, "ET_ADMIN_PORT"); SQGSEvent.DefSQConst(engine, ScriptEvent::ET_WINDOW_WIDGET_CLICK, "ET_WINDOW_WIDGET_CLICK"); SQGSEvent.DefSQConst(engine, ScriptEvent::ET_GOAL_QUESTION_ANSWER, "ET_GOAL_QUESTION_ANSWER"); + SQGSEvent.DefSQConst(engine, ScriptEvent::ET_VEHICLE_OLD, "ET_VEHICLE_OLD"); SQGSEvent.DefSQConst(engine, ScriptEvent::ET_EXCLUSIVE_TRANSPORT_RIGHTS, "ET_EXCLUSIVE_TRANSPORT_RIGHTS"); SQGSEvent.DefSQConst(engine, ScriptEvent::ET_ROAD_RECONSTRUCTION, "ET_ROAD_RECONSTRUCTION"); Index: src/script/api/game/game_window.hpp.sq =================================================================== --- src/script/api/game/game_window.hpp.sq (révision 24489) +++ src/script/api/game/game_window.hpp.sq (copie de travail) @@ -644,6 +644,7 @@ SQGSWindow.DefSQConst(engine, ScriptWindow::WID_NCL_SELECT_ALL, "WID_NCL_SELECT_ALL"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_NCL_SELECT_UPDATE, "WID_NCL_SELECT_UPDATE"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_NCL_UNSELECT, "WID_NCL_UNSELECT"); + SQGSWindow.DefSQConst(engine, ScriptWindow::WID_NCL_TEXTFILE, "WID_NCL_TEXTFILE"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_NCL_OPEN_URL, "WID_NCL_OPEN_URL"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_NCL_CANCEL, "WID_NCL_CANCEL"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_NCL_DOWNLOAD, "WID_NCL_DOWNLOAD"); Index: src/script/api/script_event_types.hpp =================================================================== --- src/script/api/script_event_types.hpp (révision 24489) +++ src/script/api/script_event_types.hpp (copie de travail) @@ -510,6 +510,37 @@ }; /** + * Event Vehicle Old, indicating a vehicle is Old and need to be replaced + * @api ai + */ +class ScriptEventVehicleOld : public ScriptEvent { +public: + /** + * @param vehicle_id The vehicle who is old. + */ + ScriptEventVehicleOld(VehicleID vehicle_id) : + ScriptEvent(ET_VEHICLE_OLD), + vehicle_id(vehicle_id) + {} + + /** + * Convert an ScriptEvent to the real instance. + * @param instance The instance to convert. + * @return The converted instance. + */ + static ScriptEventVehicleOld *Convert(ScriptEvent *instance) { return (ScriptEventVehicleOld *)instance; } + + /** + * Get the VehicleID of the vehicle who is old. + * @return The VehicleID of the vehicle who is old. + */ + VehicleID GetVehicleID() { return this->vehicle_id; } + +private: + VehicleID vehicle_id; ///< The vehicle who is old. +}; + +/** * Event VehicleWaitingInDepot, indicating a vehicle has arrived a depot and is now waiting there. * @api ai */ Index: src/script/api/ai/ai_event_types.hpp.sq =================================================================== --- src/script/api/ai/ai_event_types.hpp.sq (révision 24489) +++ src/script/api/ai/ai_event_types.hpp.sq (copie de travail) @@ -212,6 +212,21 @@ } +template <> const char *GetClassName() { return "AIEventVehicleOld"; } + +void SQAIEventVehicleOld_Register(Squirrel *engine) +{ + DefSQClass SQAIEventVehicleOld("AIEventVehicleOld"); + SQAIEventVehicleOld.PreRegister(engine, "AIEvent"); + + SQAIEventVehicleOld.DefSQStaticMethod(engine, &ScriptEventVehicleOld::Convert, "Convert", 2, ".x"); + + SQAIEventVehicleOld.DefSQMethod(engine, &ScriptEventVehicleOld::GetVehicleID, "GetVehicleID", 1, "x"); + + SQAIEventVehicleOld.PostRegister(engine); +} + + template <> const char *GetClassName() { return "AIEventVehicleWaitingInDepot"; } void SQAIEventVehicleWaitingInDepot_Register(Squirrel *engine) Index: src/script/api/ai/ai_event.hpp.sq =================================================================== --- src/script/api/ai/ai_event.hpp.sq (révision 24489) +++ src/script/api/ai/ai_event.hpp.sq (copie de travail) @@ -48,6 +48,7 @@ SQAIEvent.DefSQConst(engine, ScriptEvent::ET_ADMIN_PORT, "ET_ADMIN_PORT"); SQAIEvent.DefSQConst(engine, ScriptEvent::ET_WINDOW_WIDGET_CLICK, "ET_WINDOW_WIDGET_CLICK"); SQAIEvent.DefSQConst(engine, ScriptEvent::ET_GOAL_QUESTION_ANSWER, "ET_GOAL_QUESTION_ANSWER"); + SQAIEvent.DefSQConst(engine, ScriptEvent::ET_VEHICLE_OLD, "ET_VEHICLE_OLD"); SQAIEvent.DefSQConst(engine, ScriptEvent::ET_EXCLUSIVE_TRANSPORT_RIGHTS, "ET_EXCLUSIVE_TRANSPORT_RIGHTS"); SQAIEvent.DefSQConst(engine, ScriptEvent::ET_ROAD_RECONSTRUCTION, "ET_ROAD_RECONSTRUCTION"); Index: src/script/api/template/template_event_types.hpp.sq =================================================================== --- src/script/api/template/template_event_types.hpp.sq (révision 24489) +++ src/script/api/template/template_event_types.hpp.sq (copie de travail) @@ -124,6 +124,15 @@ } // namespace SQConvert namespace SQConvert { + /* Allow ScriptEventVehicleOld to be used as Squirrel parameter */ + template <> inline ScriptEventVehicleOld *GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptEventVehicleOld *)instance; } + template <> inline ScriptEventVehicleOld &GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptEventVehicleOld *)instance; } + template <> inline const ScriptEventVehicleOld *GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptEventVehicleOld *)instance; } + template <> inline const ScriptEventVehicleOld &GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptEventVehicleOld *)instance; } + template <> inline int Return(HSQUIRRELVM vm, ScriptEventVehicleOld *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "EventVehicleOld", res, NULL, DefSQDestructorCallback, true); return 1; } +} // namespace SQConvert + +namespace SQConvert { /* Allow ScriptEventVehicleWaitingInDepot to be used as Squirrel parameter */ template <> inline ScriptEventVehicleWaitingInDepot *GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptEventVehicleWaitingInDepot *)instance; } template <> inline ScriptEventVehicleWaitingInDepot &GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptEventVehicleWaitingInDepot *)instance; } Index: src/vehicle.cpp =================================================================== --- src/vehicle.cpp (révision 24489) +++ src/vehicle.cpp (copie de travail) @@ -1224,6 +1224,7 @@ SetDParam(0, v->index); AddVehicleAdviceNewsItem(str, v->index); + AI::NewEvent(v->owner, new ScriptEventVehicleOld(v->index)); } /**