Merge branch 'master' into jgrpp

# Conflicts:
#	src/debug.cpp
#	src/saveload/afterload.cpp
#	src/saveload/saveload.cpp
#	src/settings_type.h
#	src/town_cmd.cpp
#	src/window.cpp
This commit is contained in:
Jonathan G Rennison
2018-05-03 23:54:51 +01:00
161 changed files with 1702 additions and 1304 deletions

View File

@@ -51,15 +51,16 @@ void SQGSGoal_Register(Squirrel *engine)
SQGSGoal.DefSQConst(engine, ScriptGoal::BUTTON_SURRENDER, "BUTTON_SURRENDER");
SQGSGoal.DefSQConst(engine, ScriptGoal::BUTTON_CLOSE, "BUTTON_CLOSE");
SQGSGoal.DefSQStaticMethod(engine, &ScriptGoal::IsValidGoal, "IsValidGoal", 2, ".i");
SQGSGoal.DefSQStaticMethod(engine, &ScriptGoal::New, "New", 5, ".i.ii");
SQGSGoal.DefSQStaticMethod(engine, &ScriptGoal::Remove, "Remove", 2, ".i");
SQGSGoal.DefSQStaticMethod(engine, &ScriptGoal::SetText, "SetText", 3, ".i.");
SQGSGoal.DefSQStaticMethod(engine, &ScriptGoal::SetProgress, "SetProgress", 3, ".i.");
SQGSGoal.DefSQStaticMethod(engine, &ScriptGoal::SetCompleted, "SetCompleted", 3, ".ib");
SQGSGoal.DefSQStaticMethod(engine, &ScriptGoal::IsCompleted, "IsCompleted", 2, ".i");
SQGSGoal.DefSQStaticMethod(engine, &ScriptGoal::Question, "Question", 6, ".ii.ii");
SQGSGoal.DefSQStaticMethod(engine, &ScriptGoal::CloseQuestion, "CloseQuestion", 2, ".i");
SQGSGoal.DefSQStaticMethod(engine, &ScriptGoal::IsValidGoal, "IsValidGoal", 2, ".i");
SQGSGoal.DefSQStaticMethod(engine, &ScriptGoal::New, "New", 5, ".i.ii");
SQGSGoal.DefSQStaticMethod(engine, &ScriptGoal::Remove, "Remove", 2, ".i");
SQGSGoal.DefSQStaticMethod(engine, &ScriptGoal::SetText, "SetText", 3, ".i.");
SQGSGoal.DefSQStaticMethod(engine, &ScriptGoal::SetProgress, "SetProgress", 3, ".i.");
SQGSGoal.DefSQStaticMethod(engine, &ScriptGoal::SetCompleted, "SetCompleted", 3, ".ib");
SQGSGoal.DefSQStaticMethod(engine, &ScriptGoal::IsCompleted, "IsCompleted", 2, ".i");
SQGSGoal.DefSQStaticMethod(engine, &ScriptGoal::Question, "Question", 6, ".ii.ii");
SQGSGoal.DefSQStaticMethod(engine, &ScriptGoal::QuestionClient, "QuestionClient", 6, ".ii.ii");
SQGSGoal.DefSQStaticMethod(engine, &ScriptGoal::CloseQuestion, "CloseQuestion", 2, ".i");
SQGSGoal.PostRegister(engine);
}

View File

@@ -553,6 +553,7 @@ void SQGSWindow_Register(Squirrel *engine)
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GL_DELETE_GROUP, "WID_GL_DELETE_GROUP");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GL_RENAME_GROUP, "WID_GL_RENAME_GROUP");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GL_REPLACE_PROTECTION, "WID_GL_REPLACE_PROTECTION");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GL_INFO, "WID_GL_INFO");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_H_BACKGROUND, "WID_H_BACKGROUND");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_DPI_MATRIX_WIDGET, "WID_DPI_MATRIX_WIDGET");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_DPI_SCROLLBAR, "WID_DPI_SCROLLBAR");
@@ -628,9 +629,11 @@ void SQGSWindow_Register(Squirrel *engine)
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TF_BACKGROUND, "WID_TF_BACKGROUND");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TF_VSCROLLBAR, "WID_TF_VSCROLLBAR");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TF_HSCROLLBAR, "WID_TF_HSCROLLBAR");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_MTS_CAPTION, "WID_MTS_CAPTION");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_MTS_LIST_LEFT, "WID_MTS_LIST_LEFT");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_MTS_PLAYLIST, "WID_MTS_PLAYLIST");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_MTS_LIST_RIGHT, "WID_MTS_LIST_RIGHT");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_MTS_MUSICSET, "WID_MTS_MUSICSET");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_MTS_ALL, "WID_MTS_ALL");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_MTS_OLD, "WID_MTS_OLD");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_MTS_NEW, "WID_MTS_NEW");
@@ -1184,7 +1187,7 @@ void SQGSWindow_Register(Squirrel *engine)
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TN_TRAINS, "WID_TN_TRAINS");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TN_ROADVEHS, "WID_TN_ROADVEHS");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TN_SHIPS, "WID_TN_SHIPS");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TN_AIRCRAFTS, "WID_TN_AIRCRAFTS");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TN_AIRCRAFT, "WID_TN_AIRCRAFT");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TN_ZOOM_IN, "WID_TN_ZOOM_IN");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TN_ZOOM_OUT, "WID_TN_ZOOM_OUT");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TN_BUILDING_TOOLS_START, "WID_TN_BUILDING_TOOLS_START");

View File

@@ -25,6 +25,7 @@
* \li GSViewport::ScrollEveryoneTo
* \li GSViewport::ScrollCompanyClientsTo
* \li GSViewport::ScrollClientTo
* \li GSGoal::QuestionClient
*
* \b 1.8.0
*

View File

@@ -55,12 +55,12 @@ public:
EXPENSES_NEW_VEHICLES = ::EXPENSES_NEW_VEHICLES, ///< New vehicles.
EXPENSES_TRAIN_RUN = ::EXPENSES_TRAIN_RUN, ///< Running costs trains.
EXPENSES_ROADVEH_RUN = ::EXPENSES_ROADVEH_RUN, ///< Running costs road vehicles.
EXPENSES_AIRCRAFT_RUN = ::EXPENSES_AIRCRAFT_RUN, ///< Running costs aircrafts.
EXPENSES_AIRCRAFT_RUN = ::EXPENSES_AIRCRAFT_RUN, ///< Running costs aircraft.
EXPENSES_SHIP_RUN = ::EXPENSES_SHIP_RUN, ///< Running costs ships.
EXPENSES_PROPERTY = ::EXPENSES_PROPERTY, ///< Property costs.
EXPENSES_TRAIN_INC = ::EXPENSES_TRAIN_INC, ///< Income from trains.
EXPENSES_ROADVEH_INC = ::EXPENSES_ROADVEH_INC, ///< Income from road vehicles.
EXPENSES_AIRCRAFT_INC = ::EXPENSES_AIRCRAFT_INC, ///< Income from aircrafts.
EXPENSES_AIRCRAFT_INC = ::EXPENSES_AIRCRAFT_INC, ///< Income from aircraft.
EXPENSES_SHIP_INC = ::EXPENSES_SHIP_INC, ///< Income from ships.
EXPENSES_LOAN_INT = ::EXPENSES_LOAN_INT, ///< Interest payments over the loan.
EXPENSES_OTHER = ::EXPENSES_OTHER, ///< Other expenses.

View File

@@ -10,6 +10,7 @@
/** @file script_goal.cpp Implementation of ScriptGoal. */
#include "../../stdafx.h"
#include "script_game.hpp"
#include "script_goal.hpp"
#include "script_error.hpp"
#include "script_industry.hpp"
@@ -19,6 +20,7 @@
#include "../script_instance.hpp"
#include "../../goal_base.h"
#include "../../string_func.h"
#include "../../network/network_base.h"
#include "../../safeguards.h"
@@ -107,7 +109,7 @@
return g != NULL && g->completed;
}
/* static */ bool ScriptGoal::Question(uint16 uniqueid, ScriptCompany::CompanyID company, Text *question, QuestionType type, int buttons)
/* static */ bool ScriptGoal::DoQuestion(uint16 uniqueid, uint8 target, bool is_client, Text *question, QuestionType type, int buttons)
{
CCountedPtr<Text> counter(question);
@@ -115,15 +117,32 @@
EnforcePrecondition(false, question != NULL);
const char *text = question->GetEncodedText();
EnforcePreconditionEncodedText(false, text);
EnforcePrecondition(false, company == ScriptCompany::COMPANY_INVALID || ScriptCompany::ResolveCompanyID(company) != ScriptCompany::COMPANY_INVALID);
EnforcePrecondition(false, CountBits(buttons) >= 1 && CountBits(buttons) <= 3);
EnforcePrecondition(false, buttons < (1 << ::GOAL_QUESTION_BUTTON_COUNT));
EnforcePrecondition(false, (int)type < ::GOAL_QUESTION_TYPE_COUNT);
return ScriptObject::DoCommand(0, uniqueid | (target << 16) | (type << 24) | (is_client ? (1 << 31) : 0), buttons, CMD_GOAL_QUESTION, text);
}
/* static */ bool ScriptGoal::Question(uint16 uniqueid, ScriptCompany::CompanyID company, Text *question, QuestionType type, int buttons)
{
EnforcePrecondition(false, company == ScriptCompany::COMPANY_INVALID || ScriptCompany::ResolveCompanyID(company) != ScriptCompany::COMPANY_INVALID);
uint8 c = company;
if (company == ScriptCompany::COMPANY_INVALID) c = INVALID_COMPANY;
return ScriptObject::DoCommand(0, uniqueid | (c << 16) | (type << 24), buttons, CMD_GOAL_QUESTION, text);
return DoQuestion(uniqueid, c, false, question, type, buttons);
}
/* static */ bool ScriptGoal::QuestionClient(uint16 uniqueid, ScriptClient::ClientID client, Text *question, QuestionType type, int buttons)
{
EnforcePrecondition(false, ScriptGame::IsMultiplayer());
EnforcePrecondition(false, ScriptClient::ResolveClientID(client) != ScriptClient::CLIENT_INVALID);
#ifdef ENABLE_NETWORK
ClientIndex c = NetworkClientInfo::GetByClientID((::ClientID)client)->index;
return DoQuestion(uniqueid, c, true, question, type, buttons);
#else
return false;
#endif
}
/* static */ bool ScriptGoal::CloseQuestion(uint16 uniqueid)

View File

@@ -12,6 +12,7 @@
#ifndef SCRIPT_GOAL_HPP
#define SCRIPT_GOAL_HPP
#include "script_client.hpp"
#include "script_company.hpp"
#include "../../goal_type.h"
@@ -160,7 +161,7 @@ public:
static bool IsCompleted(GoalID goal_id);
/**
* Ask a question.
* Ask a question of all players in a company.
* @param uniqueid Your unique id to distinguish results of multiple questions in the returning event.
* @param company The company to ask the question, or ScriptCompany::COMPANY_INVALID for all.
* @param question The question to ask (can be either a raw string, or a ScriptText object).
@@ -176,6 +177,24 @@ public:
*/
static bool Question(uint16 uniqueid, ScriptCompany::CompanyID company, Text *question, QuestionType type, int buttons);
/**
* Ask client a question.
* @param uniqueid Your unique id to distinguish results of multiple questions in the returning event.
* @param client The client to ask the question.
* @param question The question to ask (can be either a raw string, or a ScriptText object).
* @param type The type of question that is being asked.
* @param buttons Any combinations (at least 1, up to 3) of buttons defined in QuestionButton. Like BUTTON_YES + BUTTON_NO.
* @return True if the action succeeded.
* @pre No ScriptCompanyMode may be in scope.
* @pre ScriptGame::IsMultiplayer()
* @pre question != NULL && len(question) != 0.
* @pre ResolveClientID(client) != CLIENT_INVALID.
* @pre CountBits(buttons) >= 1 && CountBits(buttons) <= 3.
* @note Replies to the question are given by you via the event ScriptEvent_GoalQuestionAnswer.
* @note There is no guarantee you ever get a reply on your question.
*/
static bool QuestionClient(uint16 uniqueid, ScriptClient::ClientID client, Text *question, QuestionType type, int buttons);
/**
* Close the question on all clients.
* @param uniqueid The uniqueid of the question you want to close.
@@ -187,6 +206,12 @@ public:
* companies, but you are only interested in the reply of the first.
*/
static bool CloseQuestion(uint16 uniqueid);
protected:
/**
* Does common checks and asks the question.
*/
static bool DoQuestion(uint16 uniqueid, uint8 target, bool is_client, Text *question, QuestionType type, int buttons);
};
#endif /* SCRIPT_GOAL_HPP */

View File

@@ -151,13 +151,13 @@ void CargoCollector::Update(StationID from, StationID via, uint amount)
switch (Tselector) {
case ScriptStationList_Cargo::CS_VIA_BY_FROM:
if (via != this->other_station) return;
/* fall through */
FALLTHROUGH;
case ScriptStationList_Cargo::CS_BY_FROM:
key = from;
break;
case ScriptStationList_Cargo::CS_FROM_BY_VIA:
if (from != this->other_station) return;
/* fall through */
FALLTHROUGH;
case ScriptStationList_Cargo::CS_BY_VIA:
key = via;
break;

View File

@@ -159,24 +159,24 @@
/* static */ bool ScriptTown::SetGrowthRate(TownID town_id, uint32 days_between_town_growth)
{
EnforcePrecondition(false, IsValidTown(town_id));
uint16 growth_rate;
switch (days_between_town_growth) {
case TOWN_GROWTH_NORMAL:
days_between_town_growth = 0;
growth_rate = 0;
break;
case TOWN_GROWTH_NONE:
days_between_town_growth = TOWN_GROW_RATE_CUSTOM_NONE;
growth_rate = TOWN_GROWTH_RATE_NONE;
break;
default:
days_between_town_growth = days_between_town_growth * DAY_TICKS / TOWN_GROWTH_TICKS;
EnforcePrecondition(false, days_between_town_growth < TOWN_GROW_RATE_CUSTOM);
if (days_between_town_growth == 0) days_between_town_growth = 1; // as fast as possible
EnforcePrecondition(false, days_between_town_growth <= MAX_TOWN_GROWTH_TICKS);
/* Don't use growth_rate 0 as it means GROWTH_NORMAL */
growth_rate = max(days_between_town_growth * DAY_TICKS, 2u) - 1;
break;
}
return ScriptObject::DoCommand(::Town::Get(town_id)->xy, town_id, days_between_town_growth, CMD_TOWN_GROWTH_RATE);
return ScriptObject::DoCommand(::Town::Get(town_id)->xy, town_id, growth_rate, CMD_TOWN_GROWTH_RATE);
}
/* static */ int32 ScriptTown::GetGrowthRate(TownID town_id)
@@ -185,9 +185,9 @@
const Town *t = ::Town::Get(town_id);
if (t->growth_rate == TOWN_GROW_RATE_CUSTOM_NONE) return TOWN_GROWTH_NONE;
if (t->growth_rate == TOWN_GROWTH_RATE_NONE) return TOWN_GROWTH_NONE;
return ((t->growth_rate & ~TOWN_GROW_RATE_CUSTOM) * TOWN_GROWTH_TICKS + DAY_TICKS) / DAY_TICKS;
return RoundDivSU(t->growth_rate + 1, DAY_TICKS);
}
/* static */ int32 ScriptTown::GetDistanceManhattanToTile(TownID town_id, TileIndex tile)

View File

@@ -259,7 +259,7 @@ public:
* @param town_id The index of the town.
* @param days_between_town_growth The amount of days between town growth, TOWN_GROWTH_NONE or TOWN_GROWTH_NORMAL.
* @pre IsValidTown(town_id).
* @pre days_between_town_growth <= 30000 || days_between_town_growth == TOWN_GROWTH_NONE || days_between_town_growth == TOWN_GROWTH_NORMAL.
* @pre days_between_town_growth <= 880 || days_between_town_growth == TOWN_GROWTH_NONE || days_between_town_growth == TOWN_GROWTH_NORMAL.
* @return True if the action succeeded.
* @note Even when setting a growth rate, towns only grow when the conditions for growth (SetCargoCoal) are met,
* and the game settings (economy.town_growth_rate) allow town growth at all.

View File

@@ -1463,6 +1463,7 @@ public:
WID_GL_DELETE_GROUP = ::WID_GL_DELETE_GROUP, ///< Delete group button.
WID_GL_RENAME_GROUP = ::WID_GL_RENAME_GROUP, ///< Rename group button.
WID_GL_REPLACE_PROTECTION = ::WID_GL_REPLACE_PROTECTION, ///< Replace protection button.
WID_GL_INFO = ::WID_GL_INFO, ///< Group info.
};
/* automatically generated from ../../widgets/highscore_widget.h */
@@ -1605,9 +1606,11 @@ public:
/* automatically generated from ../../widgets/music_widget.h */
/** Widgets of the #MusicTrackSelectionWindow class. */
enum MusicTrackSelectionWidgets {
WID_MTS_CAPTION = ::WID_MTS_CAPTION, ///< Window caption.
WID_MTS_LIST_LEFT = ::WID_MTS_LIST_LEFT, ///< Left button.
WID_MTS_PLAYLIST = ::WID_MTS_PLAYLIST, ///< Playlist.
WID_MTS_LIST_RIGHT = ::WID_MTS_LIST_RIGHT, ///< Right button.
WID_MTS_MUSICSET = ::WID_MTS_MUSICSET, ///< Music set selection.
WID_MTS_ALL = ::WID_MTS_ALL, ///< All button.
WID_MTS_OLD = ::WID_MTS_OLD, ///< Old button.
WID_MTS_NEW = ::WID_MTS_NEW, ///< New button.
@@ -2423,7 +2426,7 @@ public:
WID_TN_TRAINS = ::WID_TN_TRAINS, ///< Train menu.
WID_TN_ROADVEHS = ::WID_TN_ROADVEHS, ///< Road vehicle menu.
WID_TN_SHIPS = ::WID_TN_SHIPS, ///< Ship menu.
WID_TN_AIRCRAFTS = ::WID_TN_AIRCRAFTS, ///< Aircraft menu.
WID_TN_AIRCRAFT = ::WID_TN_AIRCRAFT, ///< Aircraft menu.
WID_TN_ZOOM_IN = ::WID_TN_ZOOM_IN, ///< Zoom in the main viewport.
WID_TN_ZOOM_OUT = ::WID_TN_ZOOM_OUT, ///< Zoom out the main viewport.
WID_TN_BUILDING_TOOLS_START = ::WID_TN_BUILDING_TOOLS_START, ///< Helper for the offset of the building tools