Old revision #pquqqwb5q | New revision #pzdjy2zkb | ||
---|---|---|---|
77 | Window *w = ShowBuildRailToolbar(_last_built_railtype); | 77 | Window *w = ShowBuildRailToolbar(_last_built_railtype); |
78 | if (w == NULL) return ES_NOT_HANDLED; | 78 | if (w == NULL) return ES_NOT_HANDLED; |
79 | diff --git a/src/road.cpp b/src/road.cpp | 79 | diff --git a/src/road.cpp b/src/road.cpp |
80 | index b891bb5.. | 80 | index b891bb5..8cb4859 100644 |
81 | --- a/src/road.cpp | 81 | --- a/src/road.cpp |
82 | +++ b/src/road.cpp | 82 | +++ b/src/road.cpp |
83 | @@ -257,10 +257,11 @@ bool RoadTypeIdentifier::UnpackIfValid(uint32 data) | 83 | @@ -257,10 +257,11 @@ bool RoadTypeIdentifier::UnpackIfValid(uint32 data) | … | … |
85 | RoadSubTypes ExistingRoadSubTypesForRoadType(RoadType rt, CompanyID c, bool any_date) | 85 | RoadSubTypes ExistingRoadSubTypesForRoadType(RoadType rt, CompanyID c, bool any_date) |
86 | { | 86 | { |
87 | - if (c != INVALID_COMPANY) { | 87 | - if (c != INVALID_COMPANY) { |
88 | + if (c != INVALID_OWNER) { | 88 | + /* Check only players which can actually own vehicles, editor and gamescripts are considered deities */ |
89 | + if (c < OWNER_END) { | ||
89 | const Company *company = Company::GetIfValid(c); | 90 | const Company *company = Company::GetIfValid(c); |
90 | 91 | ||
91 | - return company->avail_roadtypes[rt]; | 92 | - return company->avail_roadtypes[rt]; |
92 | + if (company != NULL) | 92 | + if (company != NULL) return company->avail_roadtypes[rt]; |
93 | + return company->avail_roadtypes[rt]; | ||
94 | } | 94 | } |
95 | 95 | ||
96 | RoadSubTypes known_roadsubtypes = ROADSUBTYPES_NONE; | 96 | RoadSubTypes known_roadsubtypes = ROADSUBTYPES_NONE; |
97 | diff --git a/src/road_gui.cpp b/src/road_gui.cpp | 97 | diff --git a/src/road_gui.cpp b/src/road_gui.cpp |
98 | index 1b9a32f.. | 98 | index 1b9a32f..12c4f73 100644 |
99 | --- a/src/road_gui.cpp | 99 | --- a/src/road_gui.cpp |
100 | +++ b/src/road_gui.cpp | 100 | +++ b/src/road_gui.cpp |
101 | @@ -300,7 +300,7 @@ struct BuildRoadToolbarWindow : Window { | 101 | @@ -300,7 +300,7 @@ struct BuildRoadToolbarWindow : Window { | … | … |
143 | 143 | ||
144 | Window *w = NULL; | 144 | Window *w = NULL; |
145 | switch (_game_mode) { | 145 | switch (_game_mode) { |
146 | @@ -1316,7 +1316,7 @@ DropDownList *GetScenRoadTypeDropDownList(RoadTypes roadtypes) | ||
147 | for (RoadType rt = ROADTYPE_BEGIN; rt < ROADTYPE_END; rt++) { | ||
148 | if (!HasBit(roadtypes, rt)) continue; | ||
149 | |||
150 | - used_roadtypes = ExistingRoadSubTypesForRoadType(rt, INVALID_COMPANY, true); | ||
151 | + used_roadtypes = ExistingRoadSubTypesForRoadType(rt, OWNER_DEITY, true); | ||
152 | |||
153 | /* If it's not used ever, don't show it to the user. */ | ||
154 | RoadTypeIdentifier rtid; | ||
146 | diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp | 155 | diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp |
147 | index 4fe7d03..4180218 100644 | 156 | index 4fe7d03..4180218 100644 |
148 | --- a/src/toolbar_gui.cpp | 157 | --- a/src/toolbar_gui.cpp | … | … |
176 | case MTHK_MUSIC: ShowMusicWindow(); break; | 185 | case MTHK_MUSIC: ShowMusicWindow(); break; |
177 | case MTHK_AI_DEBUG: ShowAIDebugWindow(); break; | 186 | case MTHK_AI_DEBUG: ShowAIDebugWindow(); break; |
178 | diff --git a/src/vehicle.cpp b/src/vehicle.cpp | 187 | diff --git a/src/vehicle.cpp b/src/vehicle.cpp |
179 | index 86e3dbc.. | 179 | index 86e3dbc..687bfc3 100644 |
180 | --- a/src/vehicle.cpp | 189 | --- a/src/vehicle.cpp |
181 | +++ b/src/vehicle.cpp | 190 | +++ b/src/vehicle.cpp |
182 | @@ -1714,1 | 182 | @@ -1714,12 +1714,12 @@ UnitID GetFreeUnitNumber(VehicleType type) |
183 | * vehicle type. This to disable building stations etc. when | 192 | * vehicle type. This to disable building stations etc. when |
184 | * you are not allowed/able to have the vehicle type yet. | 193 | * you are not allowed/able to have the vehicle type yet. |
185 | * @param type the vehicle type to check this for | 194 | * @param type the vehicle type to check this for | … | … |
190 | -bool CanBuildVehicleInfrastructure(VehicleType type, uint subtype) | 199 | -bool CanBuildVehicleInfrastructure(VehicleType type, uint subtype) |
191 | +bool CanBuildVehicleInfrastructure(VehicleType type) | 200 | +bool CanBuildVehicleInfrastructure(VehicleType type) |
192 | { | 201 | { |
202 | + assert(type != VEH_ROAD); | ||
193 | assert(IsCompanyBuildableVehicleType(type)); | 203 | assert(IsCompanyBuildableVehicleType(type)); |
194 | 204 | ||
205 | if (!Company::IsValidID(_local_company)) return false; | ||
206 | @@ -1728,7 +1728,6 @@ bool CanBuildVehicleInfrastructure(VehicleType type, uint subtype) | ||
207 | UnitID max; | ||
208 | switch (type) { | ||
209 | case VEH_TRAIN: max = _settings_game.vehicle.max_trains; break; | ||
210 | - case VEH_ROAD: max = _settings_game.vehicle.max_roadveh; break; | ||
211 | case VEH_SHIP: max = _settings_game.vehicle.max_ships; break; | ||
212 | case VEH_AIRCRAFT: max = _settings_game.vehicle.max_aircraft; break; | ||
213 | default: NOT_REACHED(); | ||
195 | @@ -1739,8 +1738,7 @@ bool CanBuildVehicleInfrastructure(VehicleType type, uint subtype) | 214 | @@ -1739,8 +1738,7 @@ bool CanBuildVehicleInfrastructure(VehicleType type, uint subtype) |
196 | /* Can we actually build the vehicle type? */ | 215 | /* Can we actually build the vehicle type? */ |
197 | const Engine *e; | 216 | const Engine *e; | … | … |
202 | } | 221 | } |
203 | return false; | 222 | return false; |
204 | } | 223 | } |
205 | @@ -1748,14 +1746, | 205 | @@ -1748,14 +1746,47 @@ bool CanBuildVehicleInfrastructure(VehicleType type, uint subtype) |
206 | /* We should be able to build infrastructure when we have the actual vehicle type */ | 225 | /* We should be able to build infrastructure when we have the actual vehicle type */ |
207 | const Vehicle *v; | 226 | const Vehicle *v; |
208 | FOR_ALL_VEHICLES(v) { | 227 | FOR_ALL_VEHICLES(v) { | … | … |
216 | } | 235 | } |
217 | 236 | ||
218 | +/** | 237 | +/** |
219 | + * Check whether we can build infrastructure for the given | 219 | + * Check whether we can build infrastructure for the given RoadType. This to disable building stations etc. when |
220 | + * RoadType. This to disable building stations etc. when | ||
221 | + * you are not allowed/able to have the RoadType yet. | 239 | + * you are not allowed/able to have the RoadType yet. |
222 | + * @param rtid the roadtype to check this for | 240 | + * @param rtid the roadtype to check this for |
223 | + * @param company the company id to check this for | 241 | + * @param company the company id to check this for |
224 | + * @param any_date to check only existing vehicles or | 224 | + * @param any_date to check only existing vehicles or if it is possible to build them in the future |
225 | + if it is possible to build them in the future | 225 | + * @return true if there is any reason why you may build the infrastructure for the given roadtype |
226 | + * @return true if there is any reason why you may build | ||
227 | + * the infrastructure for the given roadtype | ||
228 | + */ | 244 | + */ |
229 | +bool CanBuildVehicleInfrastructure(RoadTypeIdentifier rtid, CompanyID company, bool any_date) | 245 | +bool CanBuildVehicleInfrastructure(RoadTypeIdentifier rtid, CompanyID company, bool any_date) |
230 | +{ | 246 | +{ | … | … |
233 | + | 249 | + |
234 | + RoadSubTypes roadsubtypes = ExistingRoadSubTypesForRoadType(rtid.basetype, company, any_date); | 250 | + RoadSubTypes roadsubtypes = ExistingRoadSubTypesForRoadType(rtid.basetype, company, any_date); |
235 | + | 251 | + |
236 | + | 236 | + /* Check if the filtered subtypes does have the subtype we are checking for |
237 | + | 237 | + * and if we can build new ones */ |
238 | + if ( | 238 | + if (_settings_game.vehicle.max_roadveh > 0 && HasBit(roadsubtypes, rtid.subtype)) { |
239 | + /* Can we actually build the vehicle type? */ | 255 | + /* Can we actually build the vehicle type? */ |
240 | + const Engine *e; | 256 | + const Engine *e; |
241 | + FOR_ALL_ENGINES_OF_TYPE(e, VEH_ROAD) { | 257 | + FOR_ALL_ENGINES_OF_TYPE(e, VEH_ROAD) { |
242 | + if ( | 242 | + if (e->GetRoadType() == rtid) return true; |
243 | + } | 259 | + } |
244 | + return false; | 260 | + return false; |
245 | + } | 261 | + } | … | … |
247 | + /* We should be able to build infrastructure when we have the actual vehicle type */ | 263 | + /* We should be able to build infrastructure when we have the actual vehicle type */ |
248 | + const Vehicle *v; | 264 | + const Vehicle *v; |
249 | + FOR_ALL_VEHICLES(v) { | 265 | + FOR_ALL_VEHICLES(v) { |
250 | + if (v->type == VEH_ROAD && | 250 | + if (v->type == VEH_ROAD && (company == OWNER_DEITY || v->owner == company) && |
251 | + HasBit(roadsubtypes, RoadVehicle::From(v)->rtid.subtype) && RoadVehicle::From(v)->rtid.subtype == rtid.subtype | 251 | + HasBit(roadsubtypes, RoadVehicle::From(v)->rtid.subtype) && RoadVehicle::From(v)->rtid == rtid) return true; |
252 | + && (company == OWNER_NONE || v->owner == company)) return true; | ||
253 | + } | 268 | + } |
254 | + | 269 | + |
255 | + return false; | 270 | + return false; |