(svn r23628) -Add: ScriptSubsidy::Create, to create subsidies (GameScript only)

This commit is contained in:
truebrain
2011-12-19 21:01:12 +00:00
parent 09ef12ab03
commit 2fc120d4d1
6 changed files with 96 additions and 0 deletions

View File

@@ -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.