Merge branch 'template_train_replacement-sx' into jgrpp

Remove a duplicated declaration.

# Conflicts:
#	projects/openttd_vs100.vcxproj
#	projects/openttd_vs100.vcxproj.filters
#	projects/openttd_vs140.vcxproj
#	projects/openttd_vs140.vcxproj.filters
#	projects/openttd_vs80.vcproj
#	projects/openttd_vs90.vcproj
#	source.list
#	src/group_gui.cpp
#	src/lang/english.txt
#	src/network/network_command.cpp
#	src/saveload/extended_ver_sl.cpp
#	src/saveload/extended_ver_sl.h
#	src/saveload/saveload.cpp
#	src/train_cmd.cpp
#	src/vehicle.cpp
#	src/vehicle_gui.cpp
#	src/vehicle_gui_base.h
#	src/window_type.h
This commit is contained in:
Jonathan G Rennison
2016-02-14 17:55:51 +00:00
54 changed files with 4946 additions and 72 deletions

View File

@@ -54,6 +54,7 @@
#include "linkgraph/linkgraph.h"
#include "linkgraph/refresh.h"
#include "blitter/factory.hpp"
#include "tbtr_template_vehicle_func.h"
#include "table/strings.h"
@@ -703,6 +704,13 @@ void ResetVehicleColourMap()
typedef SmallMap<Vehicle *, bool, 4> AutoreplaceMap;
static AutoreplaceMap _vehicles_to_autoreplace;
/**
* List of vehicles that are issued for template replacement this tick.
* Mapping is {vehicle : leave depot after replacement}
*/
typedef SmallMap<Train *, bool, 4> TemplateReplacementMap;
static TemplateReplacementMap _vehicles_to_templatereplace;
void InitializeVehicles()
{
_vehicles_to_autoreplace.Reset();
@@ -905,8 +913,18 @@ Vehicle::~Vehicle()
*/
void VehicleEnteredDepotThisTick(Vehicle *v)
{
/* Vehicle should stop in the depot if it was in 'stopping' state */
_vehicles_to_autoreplace[v] = !(v->vehstatus & VS_STOPPED);
/* Template Replacement Setup stuff */
bool stayInDepot = v->current_order.GetDepotActionType();
TemplateReplacement *tr = GetTemplateReplacementByGroupID(v->group_id);
if (tr != NULL) {
_vehicles_to_templatereplace[(Train*) v] = stayInDepot;
} else {
/* Moved the assignment for auto replacement here to prevent auto replacement
* from happening if template replacement is also scheduled */
/* Vehicle should stop in the depot if it was in 'stopping' state */
_vehicles_to_autoreplace[v] = !(v->vehstatus & VS_STOPPED);
}
/* We ALWAYS set the stopped state. Even when the vehicle does not plan on
* stopping in the depot, so we stop it to ensure that it will not reserve
@@ -951,9 +969,29 @@ static void RunVehicleDayProc()
}
}
static void ShowAutoReplaceAdviceMessage(const CommandCost &res, const Vehicle *v)
{
StringID error_message = res.GetErrorMessage();
if (error_message == STR_ERROR_AUTOREPLACE_NOTHING_TO_DO || error_message == INVALID_STRING_ID) return;
if (error_message == STR_ERROR_NOT_ENOUGH_CASH_REQUIRES_CURRENCY) error_message = STR_ERROR_AUTOREPLACE_MONEY_LIMIT;
StringID message;
if (error_message == STR_ERROR_TRAIN_TOO_LONG_AFTER_REPLACEMENT) {
message = error_message;
} else {
message = STR_NEWS_VEHICLE_AUTORENEW_FAILED;
}
SetDParam(0, v->index);
SetDParam(1, error_message);
AddVehicleAdviceNewsItem(message, v->index);
}
void CallVehicleTicks()
{
_vehicles_to_autoreplace.Clear();
_vehicles_to_templatereplace.Clear();
if (_tick_skip_counter == 0) RunVehicleDayProc();
@@ -1039,6 +1077,7 @@ void CallVehicleTicks()
}
}
/* do Auto Replacement */
Backup<CompanyByte> cur_company(_current_company, FILE_LINE);
for (AutoreplaceMap::iterator it = _vehicles_to_autoreplace.Begin(); it != _vehicles_to_autoreplace.End(); it++) {
v = it->first;
@@ -1067,24 +1106,39 @@ void CallVehicleTicks()
continue;
}
StringID error_message = res.GetErrorMessage();
if (error_message == STR_ERROR_AUTOREPLACE_NOTHING_TO_DO || error_message == INVALID_STRING_ID) continue;
ShowAutoReplaceAdviceMessage(res, v);
}
cur_company.Restore();
if (error_message == STR_ERROR_NOT_ENOUGH_CASH_REQUIRES_CURRENCY) error_message = STR_ERROR_AUTOREPLACE_MONEY_LIMIT;
/* do Template Replacement */
Backup<CompanyByte> tmpl_cur_company(_current_company, FILE_LINE);
for (TemplateReplacementMap::iterator it = _vehicles_to_templatereplace.Begin(); it != _vehicles_to_templatereplace.End(); it++) {
Train *t = it->first;
StringID message;
if (error_message == STR_ERROR_TRAIN_TOO_LONG_AFTER_REPLACEMENT) {
message = error_message;
} else {
message = STR_NEWS_VEHICLE_AUTORENEW_FAILED;
/* Store the position of the effect as the vehicle pointer will become invalid later */
int x = t->x_pos;
int y = t->y_pos;
int z = t->z_pos;
tmpl_cur_company.Change(t->owner);
bool stayInDepot = it->second;
it->first->vehstatus |= VS_STOPPED;
CommandCost res = DoCommand(t->tile, t->index, stayInDepot ? 1 : 0, DC_EXEC, CMD_TEMPLATE_REPLACE_VEHICLE);
if (!IsLocalCompany()) continue;
if (res.Succeeded()) {
if (res.GetCost() != 0) {
ShowCostOrIncomeAnimation(x, y, z, res.GetCost());
}
continue;
}
SetDParam(0, v->index);
SetDParam(1, error_message);
AddVehicleAdviceNewsItem(message, v->index);
ShowAutoReplaceAdviceMessage(res, t);
}
cur_company.Restore();
tmpl_cur_company.Restore();
}
/**