diff options
author | zuu <zuu@openttd.org> | 2014-02-06 19:48:19 +0000 |
---|---|---|
committer | zuu <zuu@openttd.org> | 2014-02-06 19:48:19 +0000 |
commit | 1dbd59e6ab9a917214d98c53a8ab8ca5b0d47223 (patch) | |
tree | 374556ba750817bdd6899dab980bd46ea6d37110 /src/script/api | |
parent | 57a88c9de2c68496c36c5646207541a28a3e31cc (diff) | |
download | openttd-1dbd59e6ab9a917214d98c53a8ab8ca5b0d47223.tar.xz |
(svn r26306) -Add: [nogo] More story APIs: RemovePageElement, GetCompany, GetDate, SetDate
Diffstat (limited to 'src/script/api')
-rw-r--r-- | src/script/api/game/game_story_page.hpp.sq | 8 | ||||
-rw-r--r-- | src/script/api/script_story_page.cpp | 38 | ||||
-rw-r--r-- | src/script/api/script_story_page.hpp | 40 |
3 files changed, 80 insertions, 6 deletions
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 */ |