summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/command.cpp4
-rw-r--r--src/command_type.h2
-rw-r--r--src/script/api/game/game_story_page.hpp.sq8
-rw-r--r--src/script/api/script_story_page.cpp38
-rw-r--r--src/script/api/script_story_page.hpp40
-rw-r--r--src/story.cpp53
6 files changed, 139 insertions, 6 deletions
diff --git a/src/command.cpp b/src/command.cpp
index 6058c9735..7afd82185 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -160,8 +160,10 @@ CommandProc CmdCreateStoryPage;
CommandProc CmdCreateStoryPageElement;
CommandProc CmdUpdateStoryPageElement;
CommandProc CmdSetStoryPageTitle;
+CommandProc CmdSetStoryPageDate;
CommandProc CmdShowStoryPage;
CommandProc CmdRemoveStoryPage;
+CommandProc CmdRemoveStoryPageElement;
CommandProc CmdLevelLand;
@@ -312,8 +314,10 @@ static const Command _command_proc_table[] = {
DEF_CMD(CmdCreateStoryPageElement, CMD_STR_CTRL | CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_CREATE_STORY_PAGE_ELEMENT
DEF_CMD(CmdUpdateStoryPageElement, CMD_STR_CTRL | CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_UPDATE_STORY_PAGE_ELEMENT
DEF_CMD(CmdSetStoryPageTitle, CMD_STR_CTRL | CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_SET_STORY_PAGE_TITLE
+ DEF_CMD(CmdSetStoryPageDate, CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_SET_STORY_PAGE_DATE
DEF_CMD(CmdShowStoryPage, CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_SHOW_STORY_PAGE
DEF_CMD(CmdRemoveStoryPage, CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_REMOVE_STORY_PAGE
+ DEF_CMD(CmdRemoveStoryPageElement, CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_REMOVE_STORY_ELEMENT_PAGE
DEF_CMD(CmdLevelLand, CMD_ALL_TILES | CMD_NO_TEST | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_LEVEL_LAND; test run might clear tiles multiple times, in execution that only happens once
diff --git a/src/command_type.h b/src/command_type.h
index d1c328e4c..b4a49bd9f 100644
--- a/src/command_type.h
+++ b/src/command_type.h
@@ -288,8 +288,10 @@ enum Commands {
CMD_CREATE_STORY_PAGE_ELEMENT, ///< create a new story page element
CMD_UPDATE_STORY_PAGE_ELEMENT, ///< update a story page element
CMD_SET_STORY_PAGE_TITLE, ///< update title of a story page
+ CMD_SET_STORY_PAGE_DATE, ///< update date of a story page
CMD_SHOW_STORY_PAGE, ///< show a story page
CMD_REMOVE_STORY_PAGE, ///< remove a story page
+ CMD_REMOVE_STORY_PAGE_ELEMENT, ///< remove a story page element
CMD_LEVEL_LAND, ///< level land
CMD_BUILD_LOCK, ///< build a lock
diff --git a/src/script/api/game/game_story_page.hpp.sq b/src/script/api/game/game_story_page.hpp.sq
index 7fc45f2fe..621399bb0 100644
--- a/src/script/api/game/game_story_page.hpp.sq
+++ b/src/script/api/game/game_story_page.hpp.sq
@@ -32,11 +32,15 @@ void SQGSStoryPage_Register(Squirrel *engine)
SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::New, "New", 3, ".i.");
SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::NewElement, "NewElement", 5, ".iii.");
SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::UpdateElement, "UpdateElement", 4, ".ii.");
- SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::GetPageSort, "GetPageSort", 2, ".i");
- SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::GetPageElementSort, "GetPageElementSort", 2, ".i");
+ SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::GetPageSortValue, "GetPageSortValue", 2, ".i");
+ SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::GetPageElementSortValue, "GetPageElementSortValue", 2, ".i");
+ SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::GetCompany, "GetCompany", 2, ".i");
+ SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::GetDate, "GetDate", 2, ".i");
+ SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::SetDate, "SetDate", 3, ".ii");
SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::SetTitle, "SetTitle", 3, ".i.");
SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::Show, "Show", 2, ".i");
SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::Remove, "Remove", 2, ".i");
+ SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::RemoveElement, "RemoveElement", 2, ".i");
SQGSStoryPage.PostRegister(engine);
}
diff --git a/src/script/api/script_story_page.cpp b/src/script/api/script_story_page.cpp
index c443d67d4..034cfdf2a 100644
--- a/src/script/api/script_story_page.cpp
+++ b/src/script/api/script_story_page.cpp
@@ -98,14 +98,14 @@
type == ::SPET_TEXT || type == ::SPET_LOCATION ? text->GetEncodedText() : NULL);
}
-/* static */ uint32 ScriptStoryPage::GetPageSort(StoryPageID story_page_id)
+/* static */ uint32 ScriptStoryPage::GetPageSortValue(StoryPageID story_page_id)
{
EnforcePrecondition(false, IsValidStoryPage(story_page_id));
return StoryPage::Get(story_page_id)->sort_value;
}
-/* static */ uint32 ScriptStoryPage::GetPageElementSort(StoryPageElementID story_page_element_id)
+/* static */ uint32 ScriptStoryPage::GetPageElementSortValue(StoryPageElementID story_page_element_id)
{
EnforcePrecondition(false, IsValidStoryPageElement(story_page_element_id));
@@ -122,6 +122,32 @@
return ScriptObject::DoCommand(0, story_page_id, 0, CMD_SET_STORY_PAGE_TITLE, title != NULL? title->GetEncodedText() : NULL);
}
+/* static */ ScriptCompany::CompanyID ScriptStoryPage::GetCompany(StoryPageID story_page_id)
+{
+ EnforcePrecondition(ScriptCompany::COMPANY_INVALID, IsValidStoryPage(story_page_id));
+
+ CompanyID c = StoryPage::Get(story_page_id)->company;
+ ScriptCompany::CompanyID company = c == INVALID_COMPANY ? ScriptCompany::COMPANY_INVALID : (ScriptCompany::CompanyID)c;
+
+ return company;
+}
+
+/* static */ int32 ScriptStoryPage::GetDate(StoryPageID story_page_id)
+{
+ EnforcePrecondition(-1, IsValidStoryPage(story_page_id));
+
+ return StoryPage::Get(story_page_id)->date;
+}
+
+/* static */ bool ScriptStoryPage::SetDate(StoryPageID story_page_id, int32 date)
+{
+ EnforcePrecondition(false, IsValidStoryPage(story_page_id));
+ EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
+
+ return ScriptObject::DoCommand(0, story_page_id, date, CMD_SET_STORY_PAGE_DATE, NULL);
+}
+
+
/* static */ bool ScriptStoryPage::Show(StoryPageID story_page_id)
{
EnforcePrecondition(false, IsValidStoryPage(story_page_id));
@@ -138,3 +164,11 @@
return ScriptObject::DoCommand(0, story_page_id, 0, CMD_REMOVE_STORY_PAGE);
}
+/* static */ bool ScriptStoryPage::RemoveElement(StoryPageElementID story_page_element_id)
+{
+ EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
+ EnforcePrecondition(false, IsValidStoryPageElement(story_page_element_id));
+
+ return ScriptObject::DoCommand(0, story_page_element_id, 0, CMD_REMOVE_STORY_PAGE_ELEMENT);
+}
+
diff --git a/src/script/api/script_story_page.hpp b/src/script/api/script_story_page.hpp
index 315cb2104..49d4a639a 100644
--- a/src/script/api/script_story_page.hpp
+++ b/src/script/api/script_story_page.hpp
@@ -126,7 +126,7 @@ public:
* @param story_page_id The story page to get the sort value of.
* @return Page sort value.
*/
- static uint32 GetPageSort(StoryPageID story_page_id);
+ static uint32 GetPageSortValue(StoryPageID story_page_id);
/**
* Get story page element sort value. Each page element has a sort value that is internally
@@ -137,7 +137,34 @@ public:
* @param story_page_element_id The story page element to get the sort value of.
* @return Page element sort value.
*/
- static uint32 GetPageElementSort(StoryPageElementID story_page_element_id);
+ static uint32 GetPageElementSortValue(StoryPageElementID story_page_element_id);
+
+ /**
+ * Get the company which the page belongs to. If the page is global,
+ * ScriptCompany::COMPANY_INVALID is returned.
+ * @param story_page_id The story page to get the company for.
+ * @return owner company or ScriptCompany::COMPANY_INVALID
+ * @pre IsValidStoryPage(story_page_id).
+ */
+ static ScriptCompany::CompanyID GetCompany(StoryPageID story_page_id);
+
+ /**
+ * Get the page date which is displayed at the top of each page.
+ * @param story_page_id The story page to get the date of.
+ * @return The date
+ * @pre IsValidStoryPage(story_page_id).
+ */
+ static int32 GetDate(StoryPageID story_page_id);
+
+ /**
+ * Update date of a story page. The date is shown in the top left of the page
+ * @param story_page_id The story page to set the date for.
+ * @param date Page date (@see ScriptDate)
+ * @return True if the action succeeded.
+ * @pre No ScriptCompanyMode may be in scope.
+ * @pre IsValidStoryPage(story_page_id).
+ */
+ static bool SetDate(StoryPageID story_page_id, int32 date);
/**
* Update title of a story page. The title is shown in the page selector drop down.
@@ -169,6 +196,15 @@ public:
* @pre IsValidStoryPage(story_page_id).
*/
static bool Remove(StoryPageID story_page_id);
+
+ /**
+ * Removes a story page element.
+ * @param story_page_element_id The story page element to remove.
+ * @return True if the action succeeded.
+ * @pre No ScriptCompanyMode may be in scope.
+ * @pre IsValidStoryPageElement(story_page_element_id).
+ */
+ static bool RemoveElement(StoryPageElementID story_page_element_id);
};
#endif /* SCRIPT_STORY_HPP */
diff --git a/src/story.cpp b/src/story.cpp
index e60eaadec..da44c2743 100644
--- a/src/story.cpp
+++ b/src/story.cpp
@@ -251,6 +251,32 @@ CommandCost CmdSetStoryPageTitle(TileIndex tile, DoCommandFlag flags, uint32 p1,
}
/**
+ * Update date of a story page.
+ * @param tile unused.
+ * @param flags type of operation
+ * @param p1 = (bit 0 - 15) - StoryPageID to update.
+ * @param p2 = (bit 0 - 31) - date
+ * @param text unused
+ * @return the cost of this operation or an error
+ */
+CommandCost CmdSetStoryPageDate(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
+{
+ if (_current_company != OWNER_DEITY) return CMD_ERROR;
+ StoryPageID page_id = (StoryPageID)GB(p1, 0, 16);
+ if (!StoryPage::IsValidID(page_id)) return CMD_ERROR;
+ Date date = (Date)p2;
+
+ if (flags & DC_EXEC) {
+ StoryPage *p = StoryPage::Get(page_id);
+ p->date = date;
+
+ InvalidateWindowClassesData(WC_STORY_BOOK, page_id);
+ }
+
+ return CommandCost();
+}
+
+/**
* Display a story page for all clients that are allowed to
* view the story page.
* @param tile unused.
@@ -307,3 +333,30 @@ CommandCost CmdRemoveStoryPage(TileIndex tile, DoCommandFlag flags, uint32 p1, u
return CommandCost();
}
+/**
+ * Remove a story page element
+ * @param tile unused.
+ * @param flags type of operation
+ * @param p1 = (bit 0 - 15) - StoryPageElementID to remove.
+ * @param p2 unused.
+ * @param text unused.
+ * @return the cost of this operation or an error
+ */
+CommandCost CmdRemoveStoryPageElement(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
+{
+ if (_current_company != OWNER_DEITY) return CMD_ERROR;
+ StoryPageElementID page_element_id = (StoryPageElementID)p1;
+ if (!StoryPageElement::IsValidID(page_element_id)) return CMD_ERROR;
+
+ if (flags & DC_EXEC) {
+ StoryPageElement *pe = StoryPageElement::Get(page_element_id);
+ StoryPageID page_id = pe->page;
+
+ delete pe;
+
+ InvalidateWindowClassesData(WC_STORY_BOOK, page_id);
+ }
+
+ return CommandCost();
+}
+