|
|
|
@ -32,63 +32,69 @@ GoalID _new_goal_id;
|
|
|
|
|
GoalPool _goal_pool("Goal");
|
|
|
|
|
INSTANTIATE_POOL_METHODS(Goal)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new goal.
|
|
|
|
|
* @param tile unused.
|
|
|
|
|
* @param flags type of operation
|
|
|
|
|
* @param p1 various bitstuffed elements
|
|
|
|
|
* - p1 = (bit 0 - 7) - GoalType of destination.
|
|
|
|
|
* - p1 = (bit 8 - 15) - Company for which this goal is.
|
|
|
|
|
* @param p2 GoalTypeID of destination.
|
|
|
|
|
* @param text Text of the goal.
|
|
|
|
|
* @return the cost of this operation or an error
|
|
|
|
|
*/
|
|
|
|
|
CommandCost CmdCreateGoal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
|
|
|
|
/* static */ bool Goal::IsValidGoalDestination(CompanyID company, GoalType type, GoalTypeID dest)
|
|
|
|
|
{
|
|
|
|
|
if (!Goal::CanAllocateItem()) return CMD_ERROR;
|
|
|
|
|
|
|
|
|
|
GoalType type = (GoalType)GB(p1, 0, 8);
|
|
|
|
|
CompanyID company = (CompanyID)GB(p1, 8, 8);
|
|
|
|
|
|
|
|
|
|
if (_current_company != OWNER_DEITY) return CMD_ERROR;
|
|
|
|
|
if (StrEmpty(text)) return CMD_ERROR;
|
|
|
|
|
if (company != INVALID_COMPANY && !Company::IsValidID(company)) return CMD_ERROR;
|
|
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
|
case GT_NONE:
|
|
|
|
|
if (p2 != 0) return CMD_ERROR;
|
|
|
|
|
if (dest != 0) return false;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GT_TILE:
|
|
|
|
|
if (!IsValidTile(p2)) return CMD_ERROR;
|
|
|
|
|
if (!IsValidTile(dest)) return false;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GT_INDUSTRY:
|
|
|
|
|
if (!Industry::IsValidID(p2)) return CMD_ERROR;
|
|
|
|
|
if (!Industry::IsValidID(dest)) return false;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GT_TOWN:
|
|
|
|
|
if (!Town::IsValidID(p2)) return CMD_ERROR;
|
|
|
|
|
if (!Town::IsValidID(dest)) return false;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GT_COMPANY:
|
|
|
|
|
if (!Company::IsValidID(p2)) return CMD_ERROR;
|
|
|
|
|
if (!Company::IsValidID(dest)) return false;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GT_STORY_PAGE: {
|
|
|
|
|
if (!StoryPage::IsValidID(p2)) return CMD_ERROR;
|
|
|
|
|
CompanyID story_company = StoryPage::Get(p2)->company;
|
|
|
|
|
if (company == INVALID_COMPANY ? story_company != INVALID_COMPANY : story_company != INVALID_COMPANY && story_company != company) return CMD_ERROR;
|
|
|
|
|
if (!StoryPage::IsValidID(dest)) return false;
|
|
|
|
|
CompanyID story_company = StoryPage::Get(dest)->company;
|
|
|
|
|
if (company == INVALID_COMPANY ? story_company != INVALID_COMPANY : story_company != INVALID_COMPANY && story_company != company) return false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default: return CMD_ERROR;
|
|
|
|
|
default: return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new goal.
|
|
|
|
|
* @param tile unused.
|
|
|
|
|
* @param flags type of operation
|
|
|
|
|
* @param p1 various bitstuffed elements
|
|
|
|
|
* - p1 = (bit 0 - 7) - GoalType of destination.
|
|
|
|
|
* - p1 = (bit 8 - 15) - Company for which this goal is.
|
|
|
|
|
* @param p2 GoalTypeID of destination.
|
|
|
|
|
* @param text Text of the goal.
|
|
|
|
|
* @return the cost of this operation or an error
|
|
|
|
|
*/
|
|
|
|
|
CommandCost CmdCreateGoal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
|
|
|
|
{
|
|
|
|
|
if (!Goal::CanAllocateItem()) return CMD_ERROR;
|
|
|
|
|
|
|
|
|
|
GoalType type = (GoalType)GB(p1, 0, 8);
|
|
|
|
|
CompanyID company = (CompanyID)GB(p1, 8, 8);
|
|
|
|
|
GoalTypeID dest = p2;
|
|
|
|
|
|
|
|
|
|
if (_current_company != OWNER_DEITY) return CMD_ERROR;
|
|
|
|
|
if (StrEmpty(text)) return CMD_ERROR;
|
|
|
|
|
if (company != INVALID_COMPANY && !Company::IsValidID(company)) return CMD_ERROR;
|
|
|
|
|
if (!Goal::IsValidGoalDestination(company, type, dest)) return CMD_ERROR;
|
|
|
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
|
Goal *g = new Goal();
|
|
|
|
|
g->type = type;
|
|
|
|
|
g->dst = p2;
|
|
|
|
|
g->dst = dest;
|
|
|
|
|
g->company = company;
|
|
|
|
|
if (StrEmpty(text)) {
|
|
|
|
|
g->text.clear();
|
|
|
|
@ -140,6 +146,36 @@ CommandCost CmdRemoveGoal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
|
|
|
|
return CommandCost();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update goal destination of a goal.
|
|
|
|
|
* @param tile unused.
|
|
|
|
|
* @param flags type of operation
|
|
|
|
|
* @param p1 GoalID to update.
|
|
|
|
|
* @param p2 GoalTypeID of destination.
|
|
|
|
|
* @param p3 various bitstuffed elements
|
|
|
|
|
* - p3 = (bit 0 - 7) - GoalType of destination.
|
|
|
|
|
* @param p2 GoalTypeID of destination.
|
|
|
|
|
* @param text unused.
|
|
|
|
|
*/
|
|
|
|
|
CommandCost CmdSetGoalDestination(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, uint64 p3, const char *text, const CommandAuxiliaryBase *aux_data)
|
|
|
|
|
{
|
|
|
|
|
GoalID goal = p1;
|
|
|
|
|
GoalTypeID dest = p2;
|
|
|
|
|
GoalType type = (GoalType)GB(p3, 0, 8);
|
|
|
|
|
|
|
|
|
|
if (_current_company != OWNER_DEITY) return CMD_ERROR;
|
|
|
|
|
if (!Goal::IsValidID(goal)) return CMD_ERROR;
|
|
|
|
|
Goal *g = Goal::Get(goal);
|
|
|
|
|
if (!Goal::IsValidGoalDestination(g->company, type, dest)) return CMD_ERROR;
|
|
|
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
|
g->type = type;
|
|
|
|
|
g->dst = dest;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return CommandCost();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update goal text of a goal.
|
|
|
|
|
* @param tile unused.
|
|
|
|
|