diff options
author | frosch <frosch@openttd.org> | 2009-02-05 17:38:47 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2009-02-05 17:38:47 +0000 |
commit | cb049e4e5816446f7d23fcee43764cb3994780d5 (patch) | |
tree | 1a013cfc1d70f310a734feab5c052ba4c88d45ea /src | |
parent | 7f198507f724a20bc2c1257ad385a1fa4983a08e (diff) | |
download | openttd-cb049e4e5816446f7d23fcee43764cb3994780d5.tar.xz |
(svn r15359) -Add [NoAI]: AIEventVehicleCrashed::CRASH_RV_UFO, AIEventDisasterZeppelinerCrashed and AIEventDisasterZeppelinerCleared as aliens accepted NoAIs as competing life-form.
Diffstat (limited to 'src')
-rw-r--r-- | src/ai/ai_instance.cpp | 2 | ||||
-rw-r--r-- | src/ai/api/ai_event.hpp | 2 | ||||
-rw-r--r-- | src/ai/api/ai_event.hpp.sq | 40 | ||||
-rw-r--r-- | src/ai/api/ai_event_types.hpp | 65 | ||||
-rw-r--r-- | src/ai/api/ai_event_types.hpp.sq | 43 | ||||
-rw-r--r-- | src/disaster_cmd.cpp | 20 |
6 files changed, 143 insertions, 29 deletions
diff --git a/src/ai/ai_instance.cpp b/src/ai/ai_instance.cpp index 3e5f6f21f..834ad40f3 100644 --- a/src/ai/ai_instance.cpp +++ b/src/ai/ai_instance.cpp @@ -173,6 +173,8 @@ void AIInstance::RegisterAPI() SQAIEventCompanyMerger_Register(this->engine); SQAIEventCompanyNew_Register(this->engine); SQAIEventController_Register(this->engine); + SQAIEventDisasterZeppelinerCleared_Register(this->engine); + SQAIEventDisasterZeppelinerCrashed_Register(this->engine); SQAIEventEngineAvailable_Register(this->engine); SQAIEventEnginePreview_Register(this->engine); SQAIEventIndustryClose_Register(this->engine); diff --git a/src/ai/api/ai_event.hpp b/src/ai/api/ai_event.hpp index a1304ec33..2c053d33d 100644 --- a/src/ai/api/ai_event.hpp +++ b/src/ai/api/ai_event.hpp @@ -39,6 +39,8 @@ public: AI_ET_INDUSTRY_CLOSE, AI_ET_ENGINE_AVAILABLE, AI_ET_STATION_FIRST_VEHICLE, + AI_ET_DISASTER_ZEPPELINER_CRASHED, + AI_ET_DISASTER_ZEPPELINER_CLEARED, }; /** diff --git a/src/ai/api/ai_event.hpp.sq b/src/ai/api/ai_event.hpp.sq index f5ac02203..aa01563e0 100644 --- a/src/ai/api/ai_event.hpp.sq +++ b/src/ai/api/ai_event.hpp.sq @@ -21,25 +21,27 @@ void SQAIEvent_Register(Squirrel *engine) { SQAIEvent.PreRegister(engine); SQAIEvent.AddConstructor<void (AIEvent::*)(AIEvent::AIEventType type), 2>(engine, "xi"); - SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_INVALID, "AI_ET_INVALID"); - SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_TEST, "AI_ET_TEST"); - SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_SUBSIDY_OFFER, "AI_ET_SUBSIDY_OFFER"); - SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_SUBSIDY_OFFER_EXPIRED, "AI_ET_SUBSIDY_OFFER_EXPIRED"); - SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_SUBSIDY_AWARDED, "AI_ET_SUBSIDY_AWARDED"); - SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_SUBSIDY_EXPIRED, "AI_ET_SUBSIDY_EXPIRED"); - SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_ENGINE_PREVIEW, "AI_ET_ENGINE_PREVIEW"); - SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_COMPANY_NEW, "AI_ET_COMPANY_NEW"); - SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_COMPANY_IN_TROUBLE, "AI_ET_COMPANY_IN_TROUBLE"); - SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_COMPANY_MERGER, "AI_ET_COMPANY_MERGER"); - SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_COMPANY_BANKRUPT, "AI_ET_COMPANY_BANKRUPT"); - SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_VEHICLE_CRASHED, "AI_ET_VEHICLE_CRASHED"); - SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_VEHICLE_LOST, "AI_ET_VEHICLE_LOST"); - SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_VEHICLE_WAITING_IN_DEPOT, "AI_ET_VEHICLE_WAITING_IN_DEPOT"); - 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.DefSQConst(engine, AIEvent::AI_ET_INVALID, "AI_ET_INVALID"); + SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_TEST, "AI_ET_TEST"); + SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_SUBSIDY_OFFER, "AI_ET_SUBSIDY_OFFER"); + SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_SUBSIDY_OFFER_EXPIRED, "AI_ET_SUBSIDY_OFFER_EXPIRED"); + SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_SUBSIDY_AWARDED, "AI_ET_SUBSIDY_AWARDED"); + SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_SUBSIDY_EXPIRED, "AI_ET_SUBSIDY_EXPIRED"); + SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_ENGINE_PREVIEW, "AI_ET_ENGINE_PREVIEW"); + SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_COMPANY_NEW, "AI_ET_COMPANY_NEW"); + SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_COMPANY_IN_TROUBLE, "AI_ET_COMPANY_IN_TROUBLE"); + SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_COMPANY_MERGER, "AI_ET_COMPANY_MERGER"); + SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_COMPANY_BANKRUPT, "AI_ET_COMPANY_BANKRUPT"); + SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_VEHICLE_CRASHED, "AI_ET_VEHICLE_CRASHED"); + SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_VEHICLE_LOST, "AI_ET_VEHICLE_LOST"); + SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_VEHICLE_WAITING_IN_DEPOT, "AI_ET_VEHICLE_WAITING_IN_DEPOT"); + 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.DefSQConst(engine, AIEvent::AI_ET_DISASTER_ZEPPELINER_CRASHED, "AI_ET_DISASTER_ZEPPELINER_CRASHED"); + SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_DISASTER_ZEPPELINER_CLEARED, "AI_ET_DISASTER_ZEPPELINER_CLEARED"); SQAIEvent.DefSQStaticMethod(engine, &AIEvent::GetClassName, "GetClassName", 1, "x"); diff --git a/src/ai/api/ai_event_types.hpp b/src/ai/api/ai_event_types.hpp index da1b6989e..c828410ad 100644 --- a/src/ai/api/ai_event_types.hpp +++ b/src/ai/api/ai_event_types.hpp @@ -29,6 +29,7 @@ public: enum CrashReason { CRASH_TRAIN, ///< Two trains collided CRASH_RV_LEVEL_CROSSING, ///< Road vehicle got under a train + CRASH_RV_UFO, ///< Road vehicle got under a landing ufo CRASH_PLANE_LANDING, ///< Plane crashed on landing CRASH_AIRCRAFT_NO_AIRPORT, ///< Aircraft crashed after it found not a single airport for landing }; @@ -668,4 +669,68 @@ private: VehicleID vehicle; }; +/** + * Event Disaster Zeppeliner Crashed, indicating a zeppeliner has crashed on an airport and is blocking the runway. + */ +class AIEventDisasterZeppelinerCrashed : public AIEvent { +public: + static const char *GetClassName() { return "AIEventDisasterZeppelinerCrashed"; } + + /** + * @param station The station containing the affected airport + */ + AIEventDisasterZeppelinerCrashed(StationID station) : + AIEvent(AI_ET_DISASTER_ZEPPELINER_CRASHED), + station(station) + {} + + /** + * Convert an AIEvent to the real instance. + * @param instance The instance to convert. + * @return The converted instance. + */ + static AIEventDisasterZeppelinerCrashed *Convert(AIEvent *instance) { return (AIEventDisasterZeppelinerCrashed *)instance; } + + /** + * Get the StationID of the station containing the affected airport. + * @return The StationID of the station containing the affected airport. + */ + StationID GetStationID() { return station; } + +private: + StationID station; +}; + +/** + * Event Disaster Zeppeliner Cleared, indicating a previously crashed zeppeliner has been remvoed, and the airport is operating again. + */ +class AIEventDisasterZeppelinerCleared : public AIEvent { +public: + static const char *GetClassName() { return "AIEventDisasterZeppelinerCleared"; } + + /** + * @param station The station containing the affected airport + */ + AIEventDisasterZeppelinerCleared(StationID station) : + AIEvent(AI_ET_DISASTER_ZEPPELINER_CLEARED), + station(station) + {} + + /** + * Convert an AIEvent to the real instance. + * @param instance The instance to convert. + * @return The converted instance. + */ + static AIEventDisasterZeppelinerCleared *Convert(AIEvent *instance) { return (AIEventDisasterZeppelinerCleared *)instance; } + + /** + * Get the StationID of the station containing the affected airport. + * @return The StationID of the station containing the affected airport. + */ + StationID GetStationID() { return station; } + +private: + StationID station; +}; + #endif /* AI_EVENT_TYPES_HPP */ diff --git a/src/ai/api/ai_event_types.hpp.sq b/src/ai/api/ai_event_types.hpp.sq index 0eb23376a..3645fb6d2 100644 --- a/src/ai/api/ai_event_types.hpp.sq +++ b/src/ai/api/ai_event_types.hpp.sq @@ -22,6 +22,7 @@ void SQAIEventVehicleCrashed_Register(Squirrel *engine) { SQAIEventVehicleCrashed.DefSQConst(engine, AIEventVehicleCrashed::CRASH_TRAIN, "CRASH_TRAIN"); SQAIEventVehicleCrashed.DefSQConst(engine, AIEventVehicleCrashed::CRASH_RV_LEVEL_CROSSING, "CRASH_RV_LEVEL_CROSSING"); + SQAIEventVehicleCrashed.DefSQConst(engine, AIEventVehicleCrashed::CRASH_RV_UFO, "CRASH_RV_UFO"); SQAIEventVehicleCrashed.DefSQConst(engine, AIEventVehicleCrashed::CRASH_PLANE_LANDING, "CRASH_PLANE_LANDING"); SQAIEventVehicleCrashed.DefSQConst(engine, AIEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT, "CRASH_AIRCRAFT_NO_AIRPORT"); @@ -380,3 +381,45 @@ void SQAIEventStationFirstVehicle_Register(Squirrel *engine) { SQAIEventStationFirstVehicle.PostRegister(engine); } + +namespace SQConvert { + /* Allow AIEventDisasterZeppelinerCrashed to be used as Squirrel parameter */ + template <> AIEventDisasterZeppelinerCrashed *GetParam(ForceType<AIEventDisasterZeppelinerCrashed *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIEventDisasterZeppelinerCrashed *)instance; } + template <> AIEventDisasterZeppelinerCrashed &GetParam(ForceType<AIEventDisasterZeppelinerCrashed &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIEventDisasterZeppelinerCrashed *)instance; } + template <> const AIEventDisasterZeppelinerCrashed *GetParam(ForceType<const AIEventDisasterZeppelinerCrashed *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIEventDisasterZeppelinerCrashed *)instance; } + template <> const AIEventDisasterZeppelinerCrashed &GetParam(ForceType<const AIEventDisasterZeppelinerCrashed &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIEventDisasterZeppelinerCrashed *)instance; } + template <> int Return<AIEventDisasterZeppelinerCrashed *>(HSQUIRRELVM vm, AIEventDisasterZeppelinerCrashed *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "AIEventDisasterZeppelinerCrashed", res, NULL, DefSQDestructorCallback<AIEventDisasterZeppelinerCrashed>); return 1; } +}; // namespace SQConvert + +void SQAIEventDisasterZeppelinerCrashed_Register(Squirrel *engine) { + DefSQClass <AIEventDisasterZeppelinerCrashed> SQAIEventDisasterZeppelinerCrashed("AIEventDisasterZeppelinerCrashed"); + SQAIEventDisasterZeppelinerCrashed.PreRegister(engine, "AIEvent"); + + SQAIEventDisasterZeppelinerCrashed.DefSQStaticMethod(engine, &AIEventDisasterZeppelinerCrashed::GetClassName, "GetClassName", 1, "x"); + SQAIEventDisasterZeppelinerCrashed.DefSQStaticMethod(engine, &AIEventDisasterZeppelinerCrashed::Convert, "Convert", 2, "xx"); + + SQAIEventDisasterZeppelinerCrashed.DefSQMethod(engine, &AIEventDisasterZeppelinerCrashed::GetStationID, "GetStationID", 1, "x"); + + SQAIEventDisasterZeppelinerCrashed.PostRegister(engine); +} + +namespace SQConvert { + /* Allow AIEventDisasterZeppelinerCleared to be used as Squirrel parameter */ + template <> AIEventDisasterZeppelinerCleared *GetParam(ForceType<AIEventDisasterZeppelinerCleared *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIEventDisasterZeppelinerCleared *)instance; } + template <> AIEventDisasterZeppelinerCleared &GetParam(ForceType<AIEventDisasterZeppelinerCleared &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIEventDisasterZeppelinerCleared *)instance; } + template <> const AIEventDisasterZeppelinerCleared *GetParam(ForceType<const AIEventDisasterZeppelinerCleared *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIEventDisasterZeppelinerCleared *)instance; } + template <> const AIEventDisasterZeppelinerCleared &GetParam(ForceType<const AIEventDisasterZeppelinerCleared &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIEventDisasterZeppelinerCleared *)instance; } + template <> int Return<AIEventDisasterZeppelinerCleared *>(HSQUIRRELVM vm, AIEventDisasterZeppelinerCleared *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "AIEventDisasterZeppelinerCleared", res, NULL, DefSQDestructorCallback<AIEventDisasterZeppelinerCleared>); return 1; } +}; // namespace SQConvert + +void SQAIEventDisasterZeppelinerCleared_Register(Squirrel *engine) { + DefSQClass <AIEventDisasterZeppelinerCleared> SQAIEventDisasterZeppelinerCleared("AIEventDisasterZeppelinerCleared"); + SQAIEventDisasterZeppelinerCleared.PreRegister(engine, "AIEvent"); + + SQAIEventDisasterZeppelinerCleared.DefSQStaticMethod(engine, &AIEventDisasterZeppelinerCleared::GetClassName, "GetClassName", 1, "x"); + SQAIEventDisasterZeppelinerCleared.DefSQStaticMethod(engine, &AIEventDisasterZeppelinerCleared::Convert, "Convert", 2, "xx"); + + SQAIEventDisasterZeppelinerCleared.DefSQMethod(engine, &AIEventDisasterZeppelinerCleared::GetStationID, "GetStationID", 1, "x"); + + SQAIEventDisasterZeppelinerCleared.PostRegister(engine); +} diff --git a/src/disaster_cmd.cpp b/src/disaster_cmd.cpp index 709e73c71..5205aa076 100644 --- a/src/disaster_cmd.cpp +++ b/src/disaster_cmd.cpp @@ -33,6 +33,7 @@ #include "sound_func.h" #include "effectvehicle_func.h" #include "roadveh.h" +#include "ai/ai.hpp" #include "table/strings.h" #include "table/sprites.h" @@ -215,8 +216,7 @@ static void DisasterTick_Zeppeliner(Vehicle *v) if (IsValidTile(tile) && IsTileType(tile, MP_STATION) && - IsAirport(tile) && - IsHumanCompany(GetTileOwner(tile))) { + IsAirport(tile)) { v->current_order.SetDestination(1); v->age = 0; @@ -225,6 +225,7 @@ static void DisasterTick_Zeppeliner(Vehicle *v) NS_ACCIDENT_VEHICLE, v->index, 0); + AI::NewEvent(GetTileOwner(tile), new AIEventDisasterZeppelinerCrashed(GetStationIndex(tile))); } } @@ -239,10 +240,10 @@ static void DisasterTick_Zeppeliner(Vehicle *v) if (IsValidTile(tile) && IsTileType(tile, MP_STATION) && - IsAirport(tile) && - IsHumanCompany(GetTileOwner(tile))) { + IsAirport(tile)) { st = GetStationByTile(tile); CLRBITS(st->airport_flags, RUNWAY_IN_block); + AI::NewEvent(GetTileOwner(tile), new AIEventDisasterZeppelinerCleared(st->index)); } SetDisasterVehiclePos(v, v->x_pos, v->y_pos, v->z_pos); @@ -280,8 +281,7 @@ static void DisasterTick_Zeppeliner(Vehicle *v) tile = v->tile; if (IsValidTile(tile) && IsTileType(tile, MP_STATION) && - IsAirport(tile) && - IsHumanCompany(GetTileOwner(tile))) { + IsAirport(tile)) { st = GetStationByTile(tile); SETBITS(st->airport_flags, RUNWAY_IN_block); } @@ -318,7 +318,7 @@ static void DisasterTick_Ufo(Vehicle *v) v->current_order.SetDestination(1); FOR_ALL_VEHICLES(u) { - if (u->type == VEH_ROAD && IsRoadVehFront(u) && IsHumanCompany(u->owner)) { + if (u->type == VEH_ROAD && IsRoadVehFront(u)) { v->dest_tile = u->index; v->age = 0; return; @@ -358,6 +358,8 @@ static void DisasterTick_Ufo(Vehicle *v) u->index, 0); + AI::NewEvent(u->owner, new AIEventVehicleCrashed(u->index, u->tile, AIEventVehicleCrashed::CRASH_RV_UFO)); + for (Vehicle *w = u; w != NULL; w = w->Next()) { w->vehstatus |= VS_CRASHED; MarkSingleVehicleDirty(w); @@ -756,9 +758,7 @@ static void Disaster_Zeppeliner_Init() int x = TileX(Random()) * TILE_SIZE + TILE_SIZE / 2; FOR_ALL_STATIONS(st) { - if (st->airport_tile != INVALID_TILE && - st->airport_type <= 1 && - IsHumanCompany(st->owner)) { + if (st->airport_tile != INVALID_TILE && (st->airport_type == AT_SMALL || st->airport_type == AT_LARGE)) { x = (TileX(st->airport_tile) + 2) * TILE_SIZE; break; } |