summaryrefslogtreecommitdiff
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
parentf10d2417d8922f7243bcd7e4582bb1a329f6b86c (diff)
downloadopenttd-6fc653d2d729d8a5c0efeba9f588e6523c3ea13d.tar.xz
(svn r26012) -Add: new goal type that show a story page when clicked
-rw-r--r--src/goal.cpp8
-rw-r--r--src/goal_gui.cpp16
-rw-r--r--src/goal_type.h1
-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
7 files changed, 41 insertions, 1 deletions
diff --git a/src/goal.cpp b/src/goal.cpp
index 2bd74b9c8..1bc87ad82 100644
--- a/src/goal.cpp
+++ b/src/goal.cpp
@@ -19,6 +19,7 @@
#include "game/game.hpp"
#include "command_func.h"
#include "company_base.h"
+#include "story_base.h"
#include "string_func.h"
#include "gui.h"
#include "network/network.h"
@@ -72,6 +73,13 @@ CommandCost CmdCreateGoal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
if (!Company::IsValidID(p2)) return CMD_ERROR;
break;
+ case GT_STORY_PAGE: {
+ if (!StoryPage::IsValidID(p2)) return CMD_ERROR;
+ CompanyByte story_company = StoryPage::Get(p2)->company;
+ if (company == INVALID_COMPANY ? story_company != INVALID_COMPANY : story_company != INVALID_COMPANY && story_company != company) return CMD_ERROR;
+ break;
+ }
+
default: return CMD_ERROR;
}
diff --git a/src/goal_gui.cpp b/src/goal_gui.cpp
index e7112ba20..caa04e544 100644
--- a/src/goal_gui.cpp
+++ b/src/goal_gui.cpp
@@ -21,6 +21,7 @@
#include "core/geometry_func.hpp"
#include "company_func.h"
#include "company_base.h"
+#include "story_base.h"
#include "command_func.h"
#include "widgets/goal_widget.h"
@@ -122,6 +123,21 @@ struct GoalListWindow : public Window {
xy = Town::Get(s->dst)->xy;
break;
+ case GT_STORY_PAGE: {
+ if (!StoryPage::IsValidID(s->dst)) return;
+
+ /* Verify that:
+ * - if global goal: story page must be global.
+ * - if company goal: story page must be global or of the same company.
+ */
+ CompanyID goal_company = s->company;
+ CompanyID story_company = StoryPage::Get(s->dst)->company;
+ if (goal_company == INVALID_COMPANY ? story_company != INVALID_COMPANY : story_company != INVALID_COMPANY && story_company != goal_company) return;
+
+ ShowStoryBook((CompanyID)this->window_number, s->dst);
+ return;
+ }
+
default: NOT_REACHED();
}
diff --git a/src/goal_type.h b/src/goal_type.h
index 75b4c13f6..aa9dee349 100644
--- a/src/goal_type.h
+++ b/src/goal_type.h
@@ -24,6 +24,7 @@ enum GoalType {
GT_INDUSTRY, ///< Destination is an industry
GT_TOWN, ///< Destination is a town
GT_COMPANY, ///< Destination is a company
+ GT_STORY_PAGE, ///< Destination is a story page
};
typedef SimpleTinyEnumT<GoalType, byte> GoalTypeByte; ///< The GoalType packed into a byte for savegame purposes.
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);