(svn r26012) -Add: new goal type that show a story page when clicked
This commit is contained in:
		@@ -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;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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.
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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");
 | 
			
		||||
 
 | 
			
		||||
@@ -21,6 +21,7 @@
 | 
			
		||||
 *
 | 
			
		||||
 * API additions:
 | 
			
		||||
 * \li GSCompany::ChangeBankBalance
 | 
			
		||||
 * \li GSGoal::GT_STORY_PAGE
 | 
			
		||||
 * \li GSGoal::IsCompleted
 | 
			
		||||
 * \li GSGoal::SetCompleted
 | 
			
		||||
 * \li GSGoal::SetProgress
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user