89 { |
89 { |
90 DeleteName(this->string_id); |
90 DeleteName(this->string_id); |
91 free(this->speclist); |
91 free(this->speclist); |
92 } |
92 } |
93 |
93 |
94 void *Station::operator new(size_t size) |
|
95 { |
|
96 Station *st = AllocateRaw(); |
|
97 return st; |
|
98 } |
|
99 |
|
100 void *Station::operator new(size_t size, int st_idx) |
|
101 { |
|
102 if (!AddBlockIfNeeded(&_Station_pool, st_idx)) |
|
103 error("Stations: failed loading savegame: too many stations"); |
|
104 |
|
105 Station *st = GetStation(st_idx); |
|
106 return st; |
|
107 } |
|
108 |
|
109 void Station::operator delete(void *p) |
|
110 { |
|
111 } |
|
112 |
|
113 void Station::operator delete(void *p, int st_idx) |
|
114 { |
|
115 } |
|
116 |
|
117 /** Called when new facility is built on the station. If it is the first facility |
94 /** Called when new facility is built on the station. If it is the first facility |
118 * it initializes also 'xy' and 'random_bits' members */ |
95 * it initializes also 'xy' and 'random_bits' members */ |
119 void Station::AddFacility(byte new_facility_bit, TileIndex facil_xy) |
96 void Station::AddFacility(byte new_facility_bit, TileIndex facil_xy) |
120 { |
97 { |
121 if (facilities == 0) { |
98 if (facilities == 0) { |
173 |
150 |
174 bool Station::TileBelongsToRailStation(TileIndex tile) const |
151 bool Station::TileBelongsToRailStation(TileIndex tile) const |
175 { |
152 { |
176 return IsTileType(tile, MP_STATION) && GetStationIndex(tile) == index && IsRailwayStation(tile); |
153 return IsTileType(tile, MP_STATION) && GetStationIndex(tile) == index && IsRailwayStation(tile); |
177 } |
154 } |
178 |
|
179 /*static*/ Station *Station::AllocateRaw() |
|
180 { |
|
181 Station *st = NULL; |
|
182 |
|
183 /* We don't use FOR_ALL here, because FOR_ALL skips invalid items. |
|
184 * TODO - This is just a temporary stage, this will be removed. */ |
|
185 for (st = GetStation(0); st != NULL; st = (st->index + 1U < GetStationPoolSize()) ? GetStation(st->index + 1U) : NULL) { |
|
186 if (!st->IsValid()) { |
|
187 StationID index = st->index; |
|
188 |
|
189 memset(st, 0, sizeof(Station)); |
|
190 st->index = index; |
|
191 return st; |
|
192 } |
|
193 } |
|
194 |
|
195 /* Check if we can add a block to the pool */ |
|
196 if (AddBlockToPool(&_Station_pool)) return AllocateRaw(); |
|
197 |
|
198 _error_message = STR_3008_TOO_MANY_STATIONS_LOADING; |
|
199 return NULL; |
|
200 } |
|
201 |
|
202 |
155 |
203 /** Obtain the length of a platform |
156 /** Obtain the length of a platform |
204 * @pre tile must be a railway station tile |
157 * @pre tile must be a railway station tile |
205 * @param tile A tile that contains the platform in question |
158 * @param tile A tile that contains the platform in question |
206 * @return The length of the platform |
159 * @return The length of the platform |
424 |
377 |
425 /************************************************************************/ |
378 /************************************************************************/ |
426 /* RoadStop implementation */ |
379 /* RoadStop implementation */ |
427 /************************************************************************/ |
380 /************************************************************************/ |
428 |
381 |
429 /** Allocates a new RoadStop onto the pool, or recycles an unsed one |
|
430 * @return a pointer to the new roadstop |
|
431 */ |
|
432 void *RoadStop::operator new(size_t size) |
|
433 { |
|
434 RoadStop *rs = AllocateRaw(); |
|
435 return rs; |
|
436 } |
|
437 |
|
438 /** Gets a RoadStop with a given index and allocates it when needed |
|
439 * @return a pointer to the roadstop |
|
440 */ |
|
441 void *RoadStop::operator new(size_t size, int index) |
|
442 { |
|
443 if (!AddBlockIfNeeded(&_RoadStop_pool, index)) { |
|
444 error("RoadStops: failed loading savegame: too many RoadStops"); |
|
445 } |
|
446 |
|
447 RoadStop *rs = GetRoadStop(index); |
|
448 return rs; |
|
449 } |
|
450 |
|
451 void RoadStop::operator delete(void *p) |
|
452 { |
|
453 } |
|
454 |
|
455 void RoadStop::operator delete(void *p, int index) |
|
456 { |
|
457 } |
|
458 |
|
459 /** Initializes a RoadStop */ |
382 /** Initializes a RoadStop */ |
460 RoadStop::RoadStop(TileIndex tile) : |
383 RoadStop::RoadStop(TileIndex tile) : |
461 xy(tile), |
384 xy(tile), |
462 status(3), // stop is free |
385 status(3), // stop is free |
463 num_vehicles(0), |
386 num_vehicles(0), |
481 } |
404 } |
482 assert(num_vehicles == 0); |
405 assert(num_vehicles == 0); |
483 |
406 |
484 DEBUG(ms, cDebugCtorLevel , "I- at %d[0x%x]", xy, xy); |
407 DEBUG(ms, cDebugCtorLevel , "I- at %d[0x%x]", xy, xy); |
485 |
408 |
486 xy = INVALID_TILE; |
409 xy = 0; |
487 } |
|
488 |
|
489 /** Low-level function for allocating a RoadStop on the pool */ |
|
490 RoadStop *RoadStop::AllocateRaw() |
|
491 { |
|
492 RoadStop *rs; |
|
493 |
|
494 /* We don't use FOR_ALL here, because FOR_ALL skips invalid items. |
|
495 * TODO - This is just a temporary stage, this will be removed. */ |
|
496 for (rs = GetRoadStop(0); rs != NULL; rs = (rs->index + 1U < GetRoadStopPoolSize()) ? GetRoadStop(rs->index + 1U) : NULL) { |
|
497 if (!rs->IsValid()) { |
|
498 RoadStopID index = rs->index; |
|
499 |
|
500 memset(rs, 0, sizeof(*rs)); |
|
501 rs->index = index; |
|
502 |
|
503 return rs; |
|
504 } |
|
505 } |
|
506 |
|
507 /* Check if we can add a block to the pool */ |
|
508 if (AddBlockToPool(&_RoadStop_pool)) return AllocateRaw(); |
|
509 |
|
510 return NULL; |
|
511 } |
410 } |
512 |
411 |
513 /** Determines whether a RoadStop is a valid (i.e. existing) one */ |
412 /** Determines whether a RoadStop is a valid (i.e. existing) one */ |
514 bool RoadStop::IsValid() const |
413 bool RoadStop::IsValid() const |
515 { |
414 { |
516 return xy != INVALID_TILE; |
415 return xy != 0; |
517 } |
416 } |
518 |
417 |
519 /** Checks whether there is a free bay in this road stop */ |
418 /** Checks whether there is a free bay in this road stop */ |
520 bool RoadStop::HasFreeBay() const |
419 bool RoadStop::HasFreeBay() const |
521 { |
420 { |