mirror of https://github.com/OpenTTD/OpenTTD
(svn r21987) -Fix: Make news items, engine previews and AI preview events deal with no longer existing Engine items after resetting the pool.
parent
faa2a26ae1
commit
ef3ec0f8c8
|
@ -19,8 +19,15 @@
|
||||||
#include "../../articulated_vehicles.h"
|
#include "../../articulated_vehicles.h"
|
||||||
#include "table/strings.h"
|
#include "table/strings.h"
|
||||||
|
|
||||||
|
bool AIEventEnginePreview::IsEngineValid() const
|
||||||
|
{
|
||||||
|
const Engine *e = ::Engine::GetIfValid(this->engine);
|
||||||
|
return e != NULL && e->IsEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
char *AIEventEnginePreview::GetName()
|
char *AIEventEnginePreview::GetName()
|
||||||
{
|
{
|
||||||
|
if (!this->IsEngineValid()) return NULL;
|
||||||
static const int len = 64;
|
static const int len = 64;
|
||||||
char *engine_name = MallocT<char>(len);
|
char *engine_name = MallocT<char>(len);
|
||||||
|
|
||||||
|
@ -31,6 +38,7 @@ char *AIEventEnginePreview::GetName()
|
||||||
|
|
||||||
CargoID AIEventEnginePreview::GetCargoType()
|
CargoID AIEventEnginePreview::GetCargoType()
|
||||||
{
|
{
|
||||||
|
if (!this->IsEngineValid()) return CT_INVALID;
|
||||||
CargoArray cap = ::GetCapacityOfArticulatedParts(this->engine);
|
CargoArray cap = ::GetCapacityOfArticulatedParts(this->engine);
|
||||||
|
|
||||||
CargoID most_cargo = CT_INVALID;
|
CargoID most_cargo = CT_INVALID;
|
||||||
|
@ -47,6 +55,7 @@ CargoID AIEventEnginePreview::GetCargoType()
|
||||||
|
|
||||||
int32 AIEventEnginePreview::GetCapacity()
|
int32 AIEventEnginePreview::GetCapacity()
|
||||||
{
|
{
|
||||||
|
if (!this->IsEngineValid()) return -1;
|
||||||
const Engine *e = ::Engine::Get(this->engine);
|
const Engine *e = ::Engine::Get(this->engine);
|
||||||
switch (e->type) {
|
switch (e->type) {
|
||||||
case VEH_ROAD:
|
case VEH_ROAD:
|
||||||
|
@ -69,6 +78,7 @@ int32 AIEventEnginePreview::GetCapacity()
|
||||||
|
|
||||||
int32 AIEventEnginePreview::GetMaxSpeed()
|
int32 AIEventEnginePreview::GetMaxSpeed()
|
||||||
{
|
{
|
||||||
|
if (!this->IsEngineValid()) return -1;
|
||||||
const Engine *e = ::Engine::Get(this->engine);
|
const Engine *e = ::Engine::Get(this->engine);
|
||||||
int32 max_speed = e->GetDisplayMaxSpeed(); // km-ish/h
|
int32 max_speed = e->GetDisplayMaxSpeed(); // km-ish/h
|
||||||
if (e->type == VEH_AIRCRAFT) max_speed /= _settings_game.vehicle.plane_speed;
|
if (e->type == VEH_AIRCRAFT) max_speed /= _settings_game.vehicle.plane_speed;
|
||||||
|
@ -77,16 +87,19 @@ int32 AIEventEnginePreview::GetMaxSpeed()
|
||||||
|
|
||||||
Money AIEventEnginePreview::GetPrice()
|
Money AIEventEnginePreview::GetPrice()
|
||||||
{
|
{
|
||||||
|
if (!this->IsEngineValid()) return -1;
|
||||||
return ::Engine::Get(this->engine)->GetCost();
|
return ::Engine::Get(this->engine)->GetCost();
|
||||||
}
|
}
|
||||||
|
|
||||||
Money AIEventEnginePreview::GetRunningCost()
|
Money AIEventEnginePreview::GetRunningCost()
|
||||||
{
|
{
|
||||||
|
if (!this->IsEngineValid()) return -1;
|
||||||
return ::Engine::Get(this->engine)->GetRunningCost();
|
return ::Engine::Get(this->engine)->GetRunningCost();
|
||||||
}
|
}
|
||||||
|
|
||||||
int32 AIEventEnginePreview::GetVehicleType()
|
int32 AIEventEnginePreview::GetVehicleType()
|
||||||
{
|
{
|
||||||
|
if (!this->IsEngineValid()) return AIVehicle::VT_INVALID;
|
||||||
switch (::Engine::Get(this->engine)->type) {
|
switch (::Engine::Get(this->engine)->type) {
|
||||||
case VEH_ROAD: return AIVehicle::VT_ROAD;
|
case VEH_ROAD: return AIVehicle::VT_ROAD;
|
||||||
case VEH_TRAIN: return AIVehicle::VT_RAIL;
|
case VEH_TRAIN: return AIVehicle::VT_RAIL;
|
||||||
|
@ -98,6 +111,7 @@ int32 AIEventEnginePreview::GetVehicleType()
|
||||||
|
|
||||||
bool AIEventEnginePreview::AcceptPreview()
|
bool AIEventEnginePreview::AcceptPreview()
|
||||||
{
|
{
|
||||||
|
if (!this->IsEngineValid()) return false;
|
||||||
return AIObject::DoCommand(0, this->engine, 0, CMD_WANT_ENGINE_PREVIEW);
|
return AIObject::DoCommand(0, this->engine, 0, CMD_WANT_ENGINE_PREVIEW);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -296,6 +296,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EngineID engine;
|
EngineID engine;
|
||||||
|
bool IsEngineValid() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -499,6 +499,7 @@ void SetCachedEngineCounts()
|
||||||
|
|
||||||
void SetupEngines()
|
void SetupEngines()
|
||||||
{
|
{
|
||||||
|
DeleteWindowByClass(WC_ENGINE_PREVIEW);
|
||||||
_engine_pool.CleanPool();
|
_engine_pool.CleanPool();
|
||||||
|
|
||||||
assert(_engine_mngr.Length() >= _engine_mngr.NUM_DEFAULT_ENGINES);
|
assert(_engine_mngr.Length() >= _engine_mngr.NUM_DEFAULT_ENGINES);
|
||||||
|
@ -859,6 +860,9 @@ void EnginesMonthlyLoop()
|
||||||
CalcEngineReliability(e);
|
CalcEngineReliability(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Do not introduce invalid engines */
|
||||||
|
if (!e->IsEnabled()) continue;
|
||||||
|
|
||||||
if (!(e->flags & ENGINE_AVAILABLE) && _date >= (e->intro_date + DAYS_IN_YEAR)) {
|
if (!(e->flags & ENGINE_AVAILABLE) && _date >= (e->intro_date + DAYS_IN_YEAR)) {
|
||||||
/* Introduce it to all companies */
|
/* Introduce it to all companies */
|
||||||
NewVehicleAvailable(e);
|
NewVehicleAvailable(e);
|
||||||
|
|
|
@ -51,6 +51,7 @@ extern bool _news_ticker_sound;
|
||||||
|
|
||||||
extern NewsTypeData _news_type_data[];
|
extern NewsTypeData _news_type_data[];
|
||||||
|
|
||||||
|
void DeleteInvalidEngineNews();
|
||||||
void DeleteVehicleNews(VehicleID vid, StringID news);
|
void DeleteVehicleNews(VehicleID vid, StringID news);
|
||||||
void DeleteStationNews(StationID sid);
|
void DeleteStationNews(StationID sid);
|
||||||
void DeleteIndustryNews(IndustryID iid);
|
void DeleteIndustryNews(IndustryID iid);
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include "statusbar_gui.h"
|
#include "statusbar_gui.h"
|
||||||
#include "company_manager_face.h"
|
#include "company_manager_face.h"
|
||||||
#include "company_func.h"
|
#include "company_func.h"
|
||||||
|
#include "engine_base.h"
|
||||||
#include "engine_gui.h"
|
#include "engine_gui.h"
|
||||||
#include "core/geometry_func.hpp"
|
#include "core/geometry_func.hpp"
|
||||||
|
|
||||||
|
@ -809,6 +810,23 @@ void DeleteIndustryNews(IndustryID iid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove engine announcements for invalid engines.
|
||||||
|
*/
|
||||||
|
void DeleteInvalidEngineNews()
|
||||||
|
{
|
||||||
|
NewsItem *ni = _oldest_news;
|
||||||
|
|
||||||
|
while (ni != NULL) {
|
||||||
|
NewsItem *next = ni->next;
|
||||||
|
if ((ni->reftype1 == NR_ENGINE && (!Engine::IsValidID(ni->ref1) || !Engine::Get(ni->ref1)->IsEnabled())) ||
|
||||||
|
(ni->reftype2 == NR_ENGINE && (!Engine::IsValidID(ni->ref2) || !Engine::Get(ni->ref2)->IsEnabled()))) {
|
||||||
|
DeleteNewsItem(ni);
|
||||||
|
}
|
||||||
|
ni = next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void RemoveOldNewsItems()
|
static void RemoveOldNewsItems()
|
||||||
{
|
{
|
||||||
NewsItem *next;
|
NewsItem *next;
|
||||||
|
|
|
@ -51,6 +51,7 @@
|
||||||
#include "../rail_gui.h"
|
#include "../rail_gui.h"
|
||||||
#include "../core/backup_type.hpp"
|
#include "../core/backup_type.hpp"
|
||||||
#include "../smallmap_gui.h"
|
#include "../smallmap_gui.h"
|
||||||
|
#include "../news_func.h"
|
||||||
|
|
||||||
#include "table/strings.h"
|
#include "table/strings.h"
|
||||||
|
|
||||||
|
@ -2604,6 +2605,8 @@ void ReloadNewGRFData()
|
||||||
AfterLoadStations();
|
AfterLoadStations();
|
||||||
/* Check and update house and town values */
|
/* Check and update house and town values */
|
||||||
UpdateHousesAndTowns();
|
UpdateHousesAndTowns();
|
||||||
|
/* Delete news referring to no longer existing entities */
|
||||||
|
DeleteInvalidEngineNews();
|
||||||
/* Update livery selection windows */
|
/* Update livery selection windows */
|
||||||
for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) InvalidateWindowData(WC_COMPANY_COLOUR, i);
|
for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) InvalidateWindowData(WC_COMPANY_COLOUR, i);
|
||||||
/* redraw the whole screen */
|
/* redraw the whole screen */
|
||||||
|
|
Loading…
Reference in New Issue