diff options
author | zuu <zuu@openttd.org> | 2013-05-26 19:54:43 +0000 |
---|---|---|
committer | zuu <zuu@openttd.org> | 2013-05-26 19:54:43 +0000 |
commit | a4cddc3e082e2bba80644792b2f6623979328e65 (patch) | |
tree | 803c694f123792d7b54f45fdd2d3f83dc3bcc8a5 /src/script/api/script_goal.cpp | |
parent | 05c472f08afdfc6d56fa45f941c17657358d0733 (diff) | |
download | openttd-a4cddc3e082e2bba80644792b2f6623979328e65.tar.xz |
(svn r25296) -Feature: Goals can now have a progress text and/or be marked as completed.
Diffstat (limited to 'src/script/api/script_goal.cpp')
-rw-r--r-- | src/script/api/script_goal.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/script/api/script_goal.cpp b/src/script/api/script_goal.cpp index 2b9afc5ee..b5d6112fc 100644 --- a/src/script/api/script_goal.cpp +++ b/src/script/api/script_goal.cpp @@ -52,6 +52,50 @@ return ScriptObject::DoCommand(0, goal_id, 0, CMD_REMOVE_GOAL); } +/* static */ bool ScriptGoal::SetText(GoalID goal_id, Text *goal) +{ + CCountedPtr<Text> counter(goal); + + EnforcePrecondition(false, IsValidGoal(goal_id)); + EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY); + EnforcePrecondition(false, goal != NULL); + EnforcePrecondition(false, !StrEmpty(goal->GetEncodedText())); + + return ScriptObject::DoCommand(0, goal_id, 0, CMD_SET_GOAL_TEXT, goal->GetEncodedText()); +} + +/* static */ bool ScriptGoal::SetProgress(GoalID goal_id, Text *progress) +{ + CCountedPtr<Text> counter(progress); + + EnforcePrecondition(false, IsValidGoal(goal_id)); + EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY); + + /* Ensure null as used for emtpy string. */ + if (progress != NULL && StrEmpty(progress->GetEncodedText())) { + progress = NULL; + } + + return ScriptObject::DoCommand(0, goal_id, 0, CMD_SET_GOAL_PROGRESS, progress != NULL ? progress->GetEncodedText() : NULL); +} + +/* static */ bool ScriptGoal::SetCompleted(GoalID goal_id, bool completed) +{ + EnforcePrecondition(false, IsValidGoal(goal_id)); + EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY); + + return ScriptObject::DoCommand(0, goal_id, completed ? 1 : 0, CMD_SET_GOAL_COMPLETED); +} + +/* static */ bool ScriptGoal::IsCompleted(GoalID goal_id) +{ + EnforcePrecondition(false, IsValidGoal(goal_id)); + EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY); + + Goal *g = Goal::Get(goal_id); + return g != NULL && g->completed; +} + /* static */ bool ScriptGoal::Question(uint16 uniqueid, ScriptCompany::CompanyID company, Text *question, QuestionType type, int buttons) { CCountedPtr<Text> counter(question); |