summaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorzuu <zuu@openttd.org>2013-11-16 17:41:57 +0000
committerzuu <zuu@openttd.org>2013-11-16 17:41:57 +0000
commit6fc653d2d729d8a5c0efeba9f588e6523c3ea13d (patch)
tree76a9ebd0678eee9121a811696a8de6e1f6cb5681 /src/script
parentf10d2417d8922f7243bcd7e4582bb1a329f6b86c (diff)
downloadopenttd-6fc653d2d729d8a5c0efeba9f588e6523c3ea13d.tar.xz
(svn r26012) -Add: new goal type that show a story page when clicked
Diffstat (limited to 'src/script')
-rw-r--r--src/script/api/game/game_goal.hpp.sq1
-rw-r--r--src/script/api/game_changelog.hpp1
-rw-r--r--src/script/api/script_goal.cpp11
-rw-r--r--src/script/api/script_goal.hpp4
4 files changed, 16 insertions, 1 deletions
diff --git a/src/script/api/game/game_goal.hpp.sq b/src/script/api/game/game_goal.hpp.sq
index 1833bb182..7d8a3bf5e 100644
--- a/src/script/api/game/game_goal.hpp.sq
+++ b/src/script/api/game/game_goal.hpp.sq
@@ -27,6 +27,7 @@ void SQGSGoal_Register(Squirrel *engine)
SQGSGoal.DefSQConst(engine, ScriptGoal::GT_INDUSTRY, "GT_INDUSTRY");
SQGSGoal.DefSQConst(engine, ScriptGoal::GT_TOWN, "GT_TOWN");
SQGSGoal.DefSQConst(engine, ScriptGoal::GT_COMPANY, "GT_COMPANY");
+ SQGSGoal.DefSQConst(engine, ScriptGoal::GT_STORY_PAGE, "GT_STORY_PAGE");
SQGSGoal.DefSQConst(engine, ScriptGoal::QT_QUESTION, "QT_QUESTION");
SQGSGoal.DefSQConst(engine, ScriptGoal::QT_INFORMATION, "QT_INFORMATION");
SQGSGoal.DefSQConst(engine, ScriptGoal::QT_WARNING, "QT_WARNING");
diff --git a/src/script/api/game_changelog.hpp b/src/script/api/game_changelog.hpp
index 4d8a2b7d9..cf5d44573 100644
--- a/src/script/api/game_changelog.hpp
+++ b/src/script/api/game_changelog.hpp
@@ -21,6 +21,7 @@
*
* API additions:
* \li GSCompany::ChangeBankBalance
+ * \li GSGoal::GT_STORY_PAGE
* \li GSGoal::IsCompleted
* \li GSGoal::SetCompleted
* \li GSGoal::SetProgress
diff --git a/src/script/api/script_goal.cpp b/src/script/api/script_goal.cpp
index 56f3628d0..535450973 100644
--- a/src/script/api/script_goal.cpp
+++ b/src/script/api/script_goal.cpp
@@ -15,6 +15,7 @@
#include "script_industry.hpp"
#include "script_map.hpp"
#include "script_town.hpp"
+#include "script_story_page.hpp"
#include "../script_instance.hpp"
#include "../../goal_base.h"
#include "../../string_func.h"
@@ -33,10 +34,18 @@
const char *text = goal->GetEncodedText();
EnforcePreconditionEncodedText(GOAL_INVALID, text);
EnforcePrecondition(GOAL_INVALID, company == ScriptCompany::COMPANY_INVALID || ScriptCompany::ResolveCompanyID(company) != ScriptCompany::COMPANY_INVALID);
- EnforcePrecondition(GOAL_INVALID, (type == GT_NONE && destination == 0) || (type == GT_TILE && ScriptMap::IsValidTile(destination)) || (type == GT_INDUSTRY && ScriptIndustry::IsValidIndustry(destination)) || (type == GT_TOWN && ScriptTown::IsValidTown(destination)) || (type == GT_COMPANY && ScriptCompany::ResolveCompanyID((ScriptCompany::CompanyID)destination) != ScriptCompany::COMPANY_INVALID));
uint8 c = company;
if (company == ScriptCompany::COMPANY_INVALID) c = INVALID_COMPANY;
+ StoryPage *story_page = NULL;
+ if (type == GT_STORY_PAGE && ScriptStoryPage::IsValidStoryPage((ScriptStoryPage::StoryPageID)destination)) story_page = ::StoryPage::Get((ScriptStoryPage::StoryPageID)destination);
+
+ EnforcePrecondition(GOAL_INVALID, (type == GT_NONE && destination == 0) ||
+ (type == GT_TILE && ScriptMap::IsValidTile(destination)) ||
+ (type == GT_INDUSTRY && ScriptIndustry::IsValidIndustry(destination)) ||
+ (type == GT_TOWN && ScriptTown::IsValidTown(destination)) ||
+ (type == GT_COMPANY && ScriptCompany::ResolveCompanyID((ScriptCompany::CompanyID)destination) != ScriptCompany::COMPANY_INVALID) ||
+ (type == GT_STORY_PAGE && story_page != NULL && (c == INVALID_COMPANY ? story_page->company == INVALID_COMPANY : story_page->company == INVALID_COMPANY || story_page->company == c)));
if (!ScriptObject::DoCommand(0, type | (c << 8), destination, CMD_CREATE_GOAL, text, &ScriptInstance::DoCommandReturnGoalID)) return GOAL_INVALID;
diff --git a/src/script/api/script_goal.hpp b/src/script/api/script_goal.hpp
index d47dbeb42..a9c7b239d 100644
--- a/src/script/api/script_goal.hpp
+++ b/src/script/api/script_goal.hpp
@@ -44,6 +44,7 @@ public:
GT_INDUSTRY = ::GT_INDUSTRY, ///< Destination is an industry.
GT_TOWN = ::GT_TOWN, ///< Destination is a town.
GT_COMPANY = ::GT_COMPANY, ///< Destination is a company.
+ GT_STORY_PAGE = ::GT_STORY_PAGE ///< Destination is a story page.
};
/**
@@ -99,6 +100,9 @@ public:
* @pre No ScriptCompanyMode may be in scope.
* @pre goal != NULL && len(goal) != 0.
* @pre company == COMPANY_INVALID || ResolveCompanyID(company) != COMPANY_INVALID.
+ * @pre if type is GT_STORY_PAGE, the company of the goal and the company of the story page need to match:
+ * \li Global goals can only reference global story pages.
+ * \li Company specific goals can reference global story pages and story pages of the same company.
*/
static GoalID New(ScriptCompany::CompanyID company, Text *goal, GoalType type, uint32 destination);