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 */