diff options
author | truebrain <truebrain@openttd.org> | 2011-12-19 21:01:12 +0000 |
---|---|---|
committer | truebrain <truebrain@openttd.org> | 2011-12-19 21:01:12 +0000 |
commit | 5858c534202ef45039293e3a6020993621cc55a8 (patch) | |
tree | 1d85a0b818eeed481a6a2e18a88dedc74ea40495 /src/subsidy.cpp | |
parent | e0ffe4faf268298f3a20427cd87462c70e3d9bc2 (diff) | |
download | openttd-5858c534202ef45039293e3a6020993621cc55a8.tar.xz |
(svn r23628) -Add: ScriptSubsidy::Create, to create subsidies (GameScript only)
Diffstat (limited to 'src/subsidy.cpp')
-rw-r--r-- | src/subsidy.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/subsidy.cpp b/src/subsidy.cpp index 6e4ee0694..5183b1d2e 100644 --- a/src/subsidy.cpp +++ b/src/subsidy.cpp @@ -24,6 +24,7 @@ #include "core/pool_func.hpp" #include "core/random_func.hpp" #include "game/game.hpp" +#include "command_func.h" #include "table/strings.h" @@ -205,8 +206,65 @@ void CreateSubsidy(CargoID cid, SourceType src_type, SourceID src, SourceType ds SetPartOfSubsidyFlag(s->dst_type, s->dst, POS_DST); AI::BroadcastNewEvent(new ScriptEventSubsidyOffer(s->index)); Game::NewEvent(new ScriptEventSubsidyOffer(s->index)); + + InvalidateWindowData(WC_SUBSIDIES_LIST, 0); } +/** + * Create a new subsidy. + * @param tile unused. + * @param flags type of operation + * @param p1 various bitstuffed elements + * - p1 = (bit 0 - 7) - SourceType of source. + * - p1 = (bit 8 - 23) - SourceID of source. + * - p1 = (bit 24 - 31) - CargoID of subsidy. + * @param p2 various bitstuffed elements + * - p2 = (bit 0 - 7) - SourceType of destination. + * - p2 = (bit 8 - 23) - SourceID of destionation. + * @param text unused. + * @return the cost of this operation or an error + */ +CommandCost CmdCreateSubsidy(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) +{ + if (!Subsidy::CanAllocateItem()) return CMD_ERROR; + + CargoID cid = GB(p1, 24, 8); + SourceType src_type = (SourceType)GB(p1, 0, 8); + SourceID src = GB(p1, 8, 16); + SourceType dst_type = (SourceType)GB(p2, 0, 8); + SourceID dst = GB(p2, 8, 16); + + if (_current_company != OWNER_DEITY) return CMD_ERROR; + + if (cid >= NUM_CARGO || !::CargoSpec::Get(cid)->IsValid()) return CMD_ERROR; + + switch (src_type) { + case ST_TOWN: + if (!Town::IsValidID(src)) return CMD_ERROR; + break; + case ST_INDUSTRY: + if (!Industry::IsValidID(src)) return CMD_ERROR; + break; + default: + return CMD_ERROR; + } + switch (dst_type) { + case ST_TOWN: + if (!Town::IsValidID(dst)) return CMD_ERROR; + break; + case ST_INDUSTRY: + if (!Industry::IsValidID(dst)) return CMD_ERROR; + break; + default: + return CMD_ERROR; + } + + if (flags & DC_EXEC) { + CreateSubsidy(cid, src_type, src, dst_type, dst); + } + + return CommandCost(); +} /** Tries to create a passenger subsidy between two towns. * @return True iff the subsidy was created. |