OpenTTD
cargomonitor.h
Go to the documentation of this file.
1 /* $Id: cargomonitor.h 26685 2014-07-12 17:04:14Z alberth $ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8  */
9 
12 #ifndef CARGOMONITOR_H
13 #define CARGOMONITOR_H
14 
15 #include "cargo_type.h"
16 #include "company_func.h"
17 #include "industry.h"
18 #include "town.h"
20 #include <map>
21 
22 struct Station;
23 
32 typedef uint32 CargoMonitorID;
33 
35 typedef std::map<CargoMonitorID, OverflowSafeInt32> CargoMonitorMap;
36 
39 
40 
51 };
52 
53 
61 static inline CargoMonitorID EncodeCargoIndustryMonitor(CompanyID company, CargoID ctype, IndustryID ind)
62 {
63  assert(ctype < (1 << CCB_CARGO_TYPE_LENGTH));
64 
65  uint32 ret = 0;
69  SB(ret, CCB_COMPANY_START, CCB_COMPANY_LENGTH, company);
70  return ret;
71 }
72 
80 static inline CargoMonitorID EncodeCargoTownMonitor(CompanyID company, CargoID ctype, TownID town)
81 {
82  assert(ctype < (1 << CCB_CARGO_TYPE_LENGTH));
83 
84  uint32 ret = 0;
87  SB(ret, CCB_COMPANY_START, CCB_COMPANY_LENGTH, company);
88  return ret;
89 }
90 
97 {
98  return static_cast<CompanyID>(GB(num, CCB_COMPANY_START, CCB_COMPANY_LENGTH));
99 }
100 
107 {
109 }
110 
117 {
118  return HasBit(num, CCB_IS_INDUSTRY_BIT);
119 }
120 
126 static inline IndustryID DecodeMonitorIndustry(CargoMonitorID num)
127 {
128  if (!MonitorMonitorsIndustry(num)) return INVALID_INDUSTRY;
130 }
131 
137 static inline TownID DecodeMonitorTown(CargoMonitorID num)
138 {
139  if (MonitorMonitorsIndustry(num)) return INVALID_TOWN;
141 }
142 
145 int32 GetDeliveryAmount(CargoMonitorID monitor, bool keep_monitoring);
146 int32 GetPickupAmount(CargoMonitorID monitor, bool keep_monitoring);
147 void AddCargoDelivery(CargoID cargo_type, CompanyID company, uint32 amount, SourceType src_type, SourceID src, const Station *st);
148 
149 #endif /* CARGOMONITOR_H */
void AddCargoDelivery(CargoID cargo_type, CompanyID company, uint32 amount, SourceType src_type, SourceID src, const Station *st)
Cargo was delivered to its final destination, update the pickup and delivery maps.
Start bit of the cargo type field.
Definition: cargomonitor.h:47
CargoMonitorMap _cargo_pickups
Map of monitored pick-ups to the amount since last query/activation.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
static bool MonitorMonitorsIndustry(CargoMonitorID num)
Does the cargo number monitor an industry or a town?
Definition: cargomonitor.h:116
Start bit of the company field.
Definition: cargomonitor.h:49
An overflow safe integer-like type.
static CargoID DecodeMonitorCargoType(CargoMonitorID num)
Extract the cargo type from the cargo monitor.
Definition: cargomonitor.h:106
Town * town
The town this station is associated with.
Types related to cargoes...
static T SB(T &x, const uint8 s, const uint8 n, const U d)
Set n bits in x starting at bit s to d.
Bit indicating the town/industry number is an industry.
Definition: cargomonitor.h:45
Value of the CCB_IS_INDUSTRY_BIT bit.
Definition: cargomonitor.h:46
CargoCompanyBits
Constants for encoding and extracting cargo monitors.
Definition: cargomonitor.h:42
std::map< CargoMonitorID, OverflowSafeInt32 > CargoMonitorMap
Map type for storing and updating active cargo monitor numbers and their amounts. ...
Definition: cargomonitor.h:35
static CargoMonitorID EncodeCargoIndustryMonitor(CompanyID company, CargoID ctype, IndustryID ind)
Encode a cargo monitor for pickup or delivery at an industry.
Definition: cargomonitor.h:61
CargoMonitorMap _cargo_deliveries
Map of monitored deliveries to the amount since last query/activation.
Number of bits of the cargo type field.
Definition: cargomonitor.h:48
void ClearCargoDeliveryMonitoring(CompanyID company=INVALID_OWNER)
Clear all delivery cargo monitors.
int32 GetPickupAmount(CargoMonitorID monitor, bool keep_monitoring)
Get the amount of cargo picked up for the given cargo monitor since activation or last query...
uint32 CargoMonitorID
Unique number for a company / cargo type / (town or industry).
Definition: cargomonitor.h:22
SourceType
Types of cargo source and destination.
Definition: cargo_type.h:139
static CargoMonitorID EncodeCargoTownMonitor(CompanyID company, CargoID ctype, TownID town)
Encode a cargo monitoring number for pickup or delivery at a town.
Definition: cargomonitor.h:80
Start bit of the town or industry number.
Definition: cargomonitor.h:43
Functions related to companies.
static IndustryID DecodeMonitorIndustry(CargoMonitorID num)
Extract the industry number from the cargo monitor.
Definition: cargomonitor.h:126
uint16 SourceID
Contains either industry ID, town ID or company ID (or INVALID_SOURCE)
Definition: cargo_type.h:146
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Number of bits of the town or industry number.
Definition: cargomonitor.h:44
static CompanyID DecodeMonitorCompany(CargoMonitorID num)
Extract the company from the cargo monitor.
Definition: cargomonitor.h:96
Number of bits of the company field.
Definition: cargomonitor.h:50
Base of all industries.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Base of the town class.
int32 GetDeliveryAmount(CargoMonitorID monitor, bool keep_monitoring)
Get the amount of cargo delivered for the given cargo monitor since activation or last query...
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:22
Owner
Enum for all companies/owners.
Definition: company_type.h:20
static TownID DecodeMonitorTown(CargoMonitorID num)
Extract the town number from the cargo monitor.
Definition: cargomonitor.h:137
Station data structure.
Definition: station_base.h:446
An invalid owner.
Definition: company_type.h:31
void ClearCargoPickupMonitoring(CompanyID company=INVALID_OWNER)
Clear all pick-up cargo monitors.