Merge remote-tracking branch 'upstream/master'
Conflicts: src/os/unix/unix.cpp src/widgets/dropdown.cpp
This commit is contained in:
@@ -22,6 +22,14 @@
|
||||
* API additions:
|
||||
* \li AIStation::GetCargoWaitingFromVia
|
||||
*
|
||||
* \b 1.4.2
|
||||
*
|
||||
* No changes
|
||||
*
|
||||
* \b 1.4.1
|
||||
*
|
||||
* No changes
|
||||
*
|
||||
* \b 1.4.0
|
||||
*
|
||||
* API additions:
|
||||
|
||||
@@ -22,6 +22,16 @@
|
||||
* API additions:
|
||||
* \li GSStation::GetCargoWaitingFromVia
|
||||
*
|
||||
* \b 1.4.2
|
||||
*
|
||||
* Other changes:
|
||||
* \li GSCargoMonitor delivery and pickup monitor functions have improved boundary checking for
|
||||
* their parameters, and return \c -1 if they are found out of bounds.
|
||||
*
|
||||
* \b 1.4.1
|
||||
*
|
||||
* No changes
|
||||
*
|
||||
* \b 1.4.0
|
||||
*
|
||||
* API additions:
|
||||
|
||||
@@ -10,31 +10,54 @@
|
||||
/** @file script_cargomonitor.cpp Code to monitor cargo pickup and deliveries by companies. */
|
||||
|
||||
#include "../../stdafx.h"
|
||||
#include "script_cargo.hpp"
|
||||
#include "script_cargomonitor.hpp"
|
||||
#include "../../town.h"
|
||||
#include "../../industry.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ uint32 ScriptCargoMonitor::GetTownDeliveryAmount(ScriptCompany::CompanyID company, CargoID cargo, TownID town_id, bool keep_monitoring)
|
||||
/* static */ int32 ScriptCargoMonitor::GetTownDeliveryAmount(ScriptCompany::CompanyID company, CargoID cargo, TownID town_id, bool keep_monitoring)
|
||||
{
|
||||
CargoMonitorID monitor = EncodeCargoTownMonitor(static_cast<CompanyID>(company), cargo, town_id);
|
||||
CompanyID cid = static_cast<CompanyID>(company);
|
||||
if (cid < OWNER_BEGIN || cid >= MAX_COMPANIES) return -1;
|
||||
if (!ScriptCargo::IsValidCargo(cargo)) return -1;
|
||||
if (!::Town::IsValidID(town_id)) return -1;
|
||||
|
||||
CargoMonitorID monitor = EncodeCargoTownMonitor(cid, cargo, town_id);
|
||||
return GetDeliveryAmount(monitor, keep_monitoring);
|
||||
}
|
||||
|
||||
/* static */ uint32 ScriptCargoMonitor::GetIndustryDeliveryAmount(ScriptCompany::CompanyID company, CargoID cargo, IndustryID industry_id, bool keep_monitoring)
|
||||
/* static */ int32 ScriptCargoMonitor::GetIndustryDeliveryAmount(ScriptCompany::CompanyID company, CargoID cargo, IndustryID industry_id, bool keep_monitoring)
|
||||
{
|
||||
CargoMonitorID monitor = EncodeCargoIndustryMonitor(static_cast<CompanyID>(company), cargo, industry_id);
|
||||
CompanyID cid = static_cast<CompanyID>(company);
|
||||
if (cid < OWNER_BEGIN || cid >= MAX_COMPANIES) return -1;
|
||||
if (!ScriptCargo::IsValidCargo(cargo)) return -1;
|
||||
if (!::Industry::IsValidID(industry_id)) return -1;
|
||||
|
||||
CargoMonitorID monitor = EncodeCargoIndustryMonitor(cid, cargo, industry_id);
|
||||
return GetDeliveryAmount(monitor, keep_monitoring);
|
||||
}
|
||||
|
||||
/* static */ uint32 ScriptCargoMonitor::GetTownPickupAmount(ScriptCompany::CompanyID company, CargoID cargo, TownID town_id, bool keep_monitoring)
|
||||
/* static */ int32 ScriptCargoMonitor::GetTownPickupAmount(ScriptCompany::CompanyID company, CargoID cargo, TownID town_id, bool keep_monitoring)
|
||||
{
|
||||
CargoMonitorID monitor = EncodeCargoTownMonitor(static_cast<CompanyID>(company), cargo, town_id);
|
||||
CompanyID cid = static_cast<CompanyID>(company);
|
||||
if (cid < OWNER_BEGIN || cid >= MAX_COMPANIES) return -1;
|
||||
if (!ScriptCargo::IsValidCargo(cargo)) return -1;
|
||||
if (!::Town::IsValidID(town_id)) return -1;
|
||||
|
||||
CargoMonitorID monitor = EncodeCargoTownMonitor(cid, cargo, town_id);
|
||||
return GetPickupAmount(monitor, keep_monitoring);
|
||||
}
|
||||
|
||||
/* static */ uint32 ScriptCargoMonitor::GetIndustryPickupAmount(ScriptCompany::CompanyID company, CargoID cargo, IndustryID industry_id, bool keep_monitoring)
|
||||
/* static */ int32 ScriptCargoMonitor::GetIndustryPickupAmount(ScriptCompany::CompanyID company, CargoID cargo, IndustryID industry_id, bool keep_monitoring)
|
||||
{
|
||||
CargoMonitorID monitor = EncodeCargoIndustryMonitor(static_cast<CompanyID>(company), cargo, industry_id);
|
||||
CompanyID cid = static_cast<CompanyID>(company);
|
||||
if (cid < OWNER_BEGIN || cid >= MAX_COMPANIES) return -1;
|
||||
if (!ScriptCargo::IsValidCargo(cargo)) return -1;
|
||||
if (!::Industry::IsValidID(industry_id)) return -1;
|
||||
|
||||
CargoMonitorID monitor = EncodeCargoIndustryMonitor(cid, cargo, industry_id);
|
||||
return GetPickupAmount(monitor, keep_monitoring);
|
||||
}
|
||||
|
||||
|
||||
@@ -50,9 +50,10 @@ public:
|
||||
* @param cargo Cargo type to query.
|
||||
* @param town_id %Town to query.
|
||||
* @param keep_monitoring If \c true, the given combination continues to be monitored for the next call. If \c false, monitoring ends.
|
||||
* @return Amount of delivered cargo of the given cargo type to the given town by the given company since the last call.
|
||||
* @return Amount of delivered cargo of the given cargo type to the given town by the given company since the last call, or
|
||||
* \c -1 if a parameter is out-of-bound.
|
||||
*/
|
||||
static uint32 GetTownDeliveryAmount(ScriptCompany::CompanyID company, CargoID cargo, TownID town_id, bool keep_monitoring);
|
||||
static int32 GetTownDeliveryAmount(ScriptCompany::CompanyID company, CargoID cargo, TownID town_id, bool keep_monitoring);
|
||||
|
||||
/**
|
||||
* Get the amount of cargo delivered to an industry by a company since the last query, and update the monitoring state.
|
||||
@@ -60,9 +61,10 @@ public:
|
||||
* @param cargo Cargo type to query.
|
||||
* @param industry_id %Industry to query.
|
||||
* @param keep_monitoring If \c true, the given combination continues to be monitored for the next call. If \c false, monitoring ends.
|
||||
* @return Amount of delivered cargo of the given cargo type to the given industry by the given company since the last call.
|
||||
* @return Amount of delivered cargo of the given cargo type to the given industry by the given company since the last call, or
|
||||
* \c -1 if a parameter is out-of-bound.
|
||||
*/
|
||||
static uint32 GetIndustryDeliveryAmount(ScriptCompany::CompanyID company, CargoID cargo, IndustryID industry_id, bool keep_monitoring);
|
||||
static int32 GetIndustryDeliveryAmount(ScriptCompany::CompanyID company, CargoID cargo, IndustryID industry_id, bool keep_monitoring);
|
||||
|
||||
/**
|
||||
* Get the amount of cargo picked up (and delivered) from a town by a company since the last query, and update the monitoring state.
|
||||
@@ -70,10 +72,11 @@ public:
|
||||
* @param cargo Cargo type to query.
|
||||
* @param town_id %Town to query.
|
||||
* @param keep_monitoring If \c true, the given combination continues to be monitored for the next call. If \c false, monitoring ends.
|
||||
* @return Amount of picked up cargo of the given cargo type to the given town by the given company since the last call.
|
||||
* @return Amount of picked up cargo of the given cargo type to the given town by the given company since the last call, or
|
||||
* \c -1 if a parameter is out-of-bound.
|
||||
* @note Amounts of picked-up cargo are added during final delivery of it, to prevent users from getting credit for picking up without delivering it.
|
||||
*/
|
||||
static uint32 GetTownPickupAmount(ScriptCompany::CompanyID company, CargoID cargo, TownID town_id, bool keep_monitoring);
|
||||
static int32 GetTownPickupAmount(ScriptCompany::CompanyID company, CargoID cargo, TownID town_id, bool keep_monitoring);
|
||||
|
||||
/**
|
||||
* Get the amount of cargo picked up (and delivered) from an industry by a company since the last query, and update the monitoring state.
|
||||
@@ -81,10 +84,11 @@ public:
|
||||
* @param cargo Cargo type to query.
|
||||
* @param industry_id %Industry to query.
|
||||
* @param keep_monitoring If \c true, the given combination continues to be monitored for the next call. If \c false, monitoring ends.
|
||||
* @return Amount of picked up cargo of the given cargo type to the given industry by the given company since the last call.
|
||||
* @return Amount of picked up cargo of the given cargo type to the given industry by the given company since the last call, or
|
||||
* \c -1 if a parameter is out-of-bound.
|
||||
* @note Amounts of picked-up cargo are added during final delivery of it, to prevent users from getting credit for picking up without delivering it.
|
||||
*/
|
||||
static uint32 GetIndustryPickupAmount(ScriptCompany::CompanyID company, CargoID cargo, IndustryID industry_id, bool keep_monitoring);
|
||||
static int32 GetIndustryPickupAmount(ScriptCompany::CompanyID company, CargoID cargo, IndustryID industry_id, bool keep_monitoring);
|
||||
|
||||
/** Stop monitoring everything. */
|
||||
static void StopAllMonitoring();
|
||||
|
||||
@@ -151,6 +151,9 @@ public:
|
||||
*/
|
||||
class ScriptListSorterValueDescending : public ScriptListSorter {
|
||||
private:
|
||||
/* Note: We cannot use reverse_iterator.
|
||||
* The iterators must only be invalidated when the element they are pointing to is removed.
|
||||
* This only holds for forward iterators. */
|
||||
ScriptList::ScriptListBucket::iterator bucket_iter; ///< The iterator over the list to find the buckets.
|
||||
ScriptList::ScriptItemList *bucket_list; ///< The current bucket list we're iterator over.
|
||||
ScriptList::ScriptItemList::iterator bucket_list_iter; ///< The iterator over the bucket list.
|
||||
@@ -172,13 +175,13 @@ public:
|
||||
this->has_no_more_items = false;
|
||||
|
||||
/* Go to the end of the bucket-list */
|
||||
this->bucket_iter = this->list->buckets.begin();
|
||||
for (size_t i = this->list->buckets.size(); i > 1; i--) this->bucket_iter++;
|
||||
this->bucket_iter = this->list->buckets.end();
|
||||
--this->bucket_iter;
|
||||
this->bucket_list = &(*this->bucket_iter).second;
|
||||
|
||||
/* Go to the end of the items in the bucket */
|
||||
this->bucket_list_iter = this->bucket_list->begin();
|
||||
for (size_t i = this->bucket_list->size(); i > 1; i--) this->bucket_list_iter++;
|
||||
this->bucket_list_iter = this->bucket_list->end();
|
||||
--this->bucket_list_iter;
|
||||
this->item_next = *this->bucket_list_iter;
|
||||
|
||||
int32 item_current = this->item_next;
|
||||
@@ -211,8 +214,8 @@ public:
|
||||
this->bucket_iter--;
|
||||
this->bucket_list = &(*this->bucket_iter).second;
|
||||
/* Go to the end of the items in the bucket */
|
||||
this->bucket_list_iter = this->bucket_list->begin();
|
||||
for (size_t i = this->bucket_list->size(); i > 1; i--) this->bucket_list_iter++;
|
||||
this->bucket_list_iter = this->bucket_list->end();
|
||||
--this->bucket_list_iter;
|
||||
} else {
|
||||
this->bucket_list_iter--;
|
||||
}
|
||||
@@ -315,6 +318,9 @@ public:
|
||||
*/
|
||||
class ScriptListSorterItemDescending : public ScriptListSorter {
|
||||
private:
|
||||
/* Note: We cannot use reverse_iterator.
|
||||
* The iterators must only be invalidated when the element they are pointing to is removed.
|
||||
* This only holds for forward iterators. */
|
||||
ScriptList::ScriptListMap::iterator item_iter; ///< The iterator over the items in the map.
|
||||
|
||||
public:
|
||||
@@ -333,8 +339,8 @@ public:
|
||||
if (this->list->items.empty()) return 0;
|
||||
this->has_no_more_items = false;
|
||||
|
||||
this->item_iter = this->list->items.begin();
|
||||
for (size_t i = this->list->items.size(); i > 1; i--) this->item_iter++;
|
||||
this->item_iter = this->list->items.end();
|
||||
--this->item_iter;
|
||||
this->item_next = (*this->item_iter).first;
|
||||
|
||||
int32 item_current = this->item_next;
|
||||
@@ -356,7 +362,12 @@ public:
|
||||
this->has_no_more_items = true;
|
||||
return;
|
||||
}
|
||||
this->item_iter--;
|
||||
if (this->item_iter == this->list->items.begin()) {
|
||||
/* Use 'end' as marker for 'beyond begin' */
|
||||
this->item_iter = this->list->items.end();
|
||||
} else {
|
||||
this->item_iter--;
|
||||
}
|
||||
if (this->item_iter != this->list->items.end()) item_next = (*this->item_iter).first;
|
||||
}
|
||||
|
||||
|
||||
@@ -84,15 +84,15 @@ public:
|
||||
bool HasItem(int32 item);
|
||||
|
||||
/**
|
||||
* Go to the beginning of the list.
|
||||
* @return the item value of the first item.
|
||||
* Go to the beginning of the list and return the item. To get the value use list.GetValue(list.Begin()).
|
||||
* @return the first item.
|
||||
* @note returns 0 if beyond end-of-list. Use IsEnd() to check for end-of-list.
|
||||
*/
|
||||
int32 Begin();
|
||||
|
||||
/**
|
||||
* Go to the next item in the list.
|
||||
* @return the item value of the next item.
|
||||
* Go to the next item in the list and return the item. To get the value use list.GetValue(list.Next()).
|
||||
* @return the next item.
|
||||
* @note returns 0 if beyond end-of-list. Use IsEnd() to check for end-of-list.
|
||||
*/
|
||||
int32 Next();
|
||||
|
||||
Reference in New Issue
Block a user