(svn r23628) -Add: ScriptSubsidy::Create, to create subsidies (GameScript only)
This commit is contained in:
@@ -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.
|
||||
|
Reference in New Issue
Block a user