MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / New

Method New

src/script/api/script_goal.cpp:53–68  ·  view source on GitHub ↗

static */

Source from the content-addressed store, hash-verified

51}
52
53/* static */ GoalID ScriptGoal::New(ScriptCompany::CompanyID company, Text *goal, GoalType type, SQInteger destination)
54{
55 ScriptObjectRef counter(goal);
56
57 EnforceDeityMode(GOAL_INVALID);
58 EnforcePrecondition(GOAL_INVALID, goal != nullptr);
59 EncodedString text = goal->GetEncodedText();
60 EnforcePreconditionEncodedText(GOAL_INVALID, text);
61 EnforcePrecondition(GOAL_INVALID, company == ScriptCompany::COMPANY_INVALID || ScriptCompany::ResolveCompanyID(company) != ScriptCompany::COMPANY_INVALID);
62 EnforcePrecondition(GOAL_INVALID, IsValidGoalDestination(company, type, destination));
63
64 if (!ScriptObject::Command<CMD_CREATE_GOAL>::Do(&ScriptInstance::DoCommandReturnGoalID, ScriptCompany::FromScriptCompanyID(company), (::GoalType)type, destination, text)) return GOAL_INVALID;
65
66 /* In case of test-mode, we return GoalID 0 */
67 return GoalID::Begin();
68}
69
70/* static */ bool ScriptGoal::Remove(GoalID goal_id)
71{

Callers

nothing calls this directly

Calls 2

BeginFunction · 0.85
GetEncodedTextMethod · 0.80

Tested by

no test coverage detected