forked from aburch/simutrans
-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathsimconvoi.h
1543 lines (1243 loc) · 43.1 KB
/
simconvoi.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* This file is part of the Simutrans-Extended project under the Artistic License.
* (see LICENSE.txt)
*/
#ifndef SIMCONVOI_H
#define SIMCONVOI_H
#include "simtypes.h"
#include "simunits.h"
#include "simcolor.h"
#include "linehandle_t.h"
#include "ifc/sync_steppable.h"
#include "dataobj/route.h"
#include "dataobj/schedule.h"
#include "bauer/goods_manager.h"
#include "vehicle/overtaker.h"
#include "tpl/array_tpl.h"
#include "tpl/fixed_list_tpl.h"
#include "tpl/koordhashtable_tpl.h"
#include "tpl/inthashtable_tpl.h"
#include "tpl/minivec_tpl.h"
#include "convoihandle_t.h"
#include "halthandle_t.h"
#include "simconst.h"
#include "obj/simobj.h"
#include "convoy.h"
/*
* Waiting time for infinite loading (ms)
*/
#define WAIT_INFINITE 9223372036854775807ll
#define MAX_MONTHS 12 // Max history
class weg_t;
class depot_t;
class karte_ptr_t;
class player_t;
class vehicle_t;
class vehicle_desc_t;
class schedule_t;
class cbuffer_t;
class ware_t;
class replace_data_t;
class departure_point_t;
/**
* The table of point-to-point average journey times.
* @author jamespetts
*/
typedef koordhashtable_tpl<id_pair, average_tpl<uint32>, N_BAGS_SMALL> journey_times_map;
#ifdef MULTI_THREAD
struct route_range_specification
{
uint32 start;
uint32 end;
};
#endif
/**
* Base class for all vehicle consists. Convoys can be referenced by handles, see halthandle_t.
*/
class convoi_t : public sync_steppable, public overtaker_t, public lazy_convoy_t
{
public:
enum convoi_cost_t { // Ext|Std|Description
CONVOI_CAPACITY = 0, // 0 | | the distance (km) travelled by vacant seats
CONVOI_PAX_DISTANCE, // 1 | | the distance (km) travelled by passengers
CONVOI_AVERAGE_SPEED, // 2 | | the average speed of the convoy per rolling month
CONVOI_COMFORT, // 3 | | the aggregate comfort rating of this convoy
CONVOI_REVENUE, // 4 | 2 | the income this CONVOI generated
CONVOI_OPERATIONS, // 5 | 3 | the cost of operations this CONVOI generated
CONVOI_PROFIT, // 6 | 4 | total profit of this convoi
CONVOI_DISTANCE, // 7 | 5 | total distance traveled this month
CONVOI_REFUNDS, // 8 | | the refunds passengers waiting for this convoy (only when not attached to a line) have received.
// CONVOI_MAXSPEED, // | 6 | average max. possible speed
CONVOI_WAYTOLL, // 9 | 7 |
CONVOI_MAIL_DISTANCE, // 10 | | the distance (km) travelled by mail
CONVOI_PAYLOAD_DISTANCE, // 11 | | moving 1 ton of cargo a distance of 1 km
MAX_CONVOI_COST // 12 | 8 |
};
/** Constants */
enum { max_vehicle=8, max_rail_vehicle = 64 };
enum states {
INITIAL,
EDIT_SCHEDULE,
ROUTING_1,
ROUTING_2,
DUMMY5,
NO_ROUTE,
DRIVING,
LOADING,
WAITING_FOR_CLEARANCE,
WAITING_FOR_CLEARANCE_ONE_MONTH,
CAN_START,
CAN_START_ONE_MONTH,
SELF_DESTRUCT,
WAITING_FOR_CLEARANCE_TWO_MONTHS,
CAN_START_TWO_MONTHS,
LEAVING_DEPOT,
ENTERING_DEPOT,
REVERSING,
OUT_OF_RANGE,
EMERGENCY_STOP,
ROUTE_JUST_FOUND,
NO_ROUTE_TOO_COMPLEX,
WAITING_FOR_LOADING_THREE_MONTHS,
WAITING_FOR_LOADING_FOUR_MONTHS,
MAX_STATES
};
enum terminal_shunt_mode {
wye = 0,
rearrange = 1,
shunting_loco = 2,
change_direction = 3
};
enum { free = 0, head_and_tail = 1, half_intermediate = 2, INTERMEDIATE = 64, both_intermediate = 65, one_sided_partner = 66, unique_partner = 67, COUPLING_FIXED = 128, unconnectable = 255 };
/**
* time, when a convoi waiting for full load will drive on
* @author prissi
*/
sint64 go_on_ticks;
struct departure_data_t
{
public:
/**
* Departure time in internal ticks
*/
sint64 departure_time;
/**
* Accumulated distance since the convoy departed from
* this stop, indexed by the player number of the way
* over which the convoy has passed. If the way is
* ownerless, it is recorded as belonging as being
* MAX_PLAYER_COUNT + 1.
*
* accumulated_distance_since_departure[MAX_PLAYER_COUNT]
* is a special value for overall distance, demoninated
* in a different unit to the others, which others are
* demoninated in steps
*/
private:
uint32 accumulated_distance_since_departure[MAX_PLAYER_COUNT + 2];
public:
departure_data_t()
{
departure_time = 0ll;
init_distances();
}
/**
* Method for adding the total distance at intermediate halts
*/
void add_overall_distance(uint32 distance)
{
accumulated_distance_since_departure[MAX_PLAYER_COUNT] += distance;
}
/**
* Method to get the overall distance. This should be the basis
* for measuring the total revenue.
*/
uint32 get_overall_distance() const
{
return accumulated_distance_since_departure[MAX_PLAYER_COUNT];
}
uint32 get_way_distance(uint8 index) const
{
return accumulated_distance_since_departure[index];
}
/**
* Method to increment by one the distance recorded as
* travelled by a vehicle over a particular way, indexed
* by the player ID of the way. This is used for revenue
* apportionment.
*/
void increment_way_distance(uint8 player, uint32 steps)
{
accumulated_distance_since_departure[player] += steps;
}
/**
* Method for setting values in the array ab initio.
* Used when loading from a saved game only.
*/
void set_distance(uint8 index, uint32 value)
{
accumulated_distance_since_departure[index] = value;
}
/**
* Method for initialising the value of the overall
* distances to zero
*/
void init_distances()
{
for(int i = 0; i < MAX_PLAYER_COUNT + 2; i ++)
{
accumulated_distance_since_departure[i] = 0;
}
}
};
// BG, 31.12.2012: virtual methods of lazy_convoy_t:
private:
weight_summary_t weight;
static const sint32 timings_reduction_point = 6;
bool re_ordered; // Whether this convoy's vehicles are currently arranged in reverse order.
protected:
virtual void update_vehicle_summary(vehicle_summary_t &vehicle) OVERRIDE;
virtual void update_freight_summary(freight_summary_t &freight) OVERRIDE;
virtual void update_weight_summary(weight_summary_t &weight);
virtual float32e8_t get_brake_summary(/*const float32e8_t &speed*/ /* in m/s */) OVERRIDE;
virtual float32e8_t get_power_summary(const float32e8_t &speed /* in m/s */) OVERRIDE;
public:
virtual void update_adverse_summary(adverse_summary_t &adverse) OVERRIDE;
virtual float32e8_t get_force_summary(const float32e8_t &speed /* in m/s */) OVERRIDE;
virtual sint16 get_current_friction() OVERRIDE;
// weight_summary becomes invalid, when vehicle_summary or envirion_summary
// becomes invalid.
inline void invalidate_weight_summary()
{
is_valid &= ~cd_weight_summary;
}
// weight_summary is valid if (is_valid & cd_weight_summary != 0)
inline void validate_weight_summary() {
if (!(is_valid & cd_weight_summary))
{
is_valid |= cd_weight_summary;
update_weight_summary(weight);
}
}
// weight_summary needs recaching only, if it is going to be used.
inline const weight_summary_t &get_weight_summary() {
validate_weight_summary();
return weight;
}
inline void calc_move(const settings_t &settings, long delta_t, sint32 akt_speed_soll, sint32 next_speed_limit, sint32 steps_til_limit, sint32 steps_til_brake, sint32 &akt_speed, sint32 &sp_soll, float32e8_t &akt_v)
{
validate_weight_summary();
convoy_t::calc_move(settings, delta_t, weight, akt_speed_soll, next_speed_limit, steps_til_limit, steps_til_brake, akt_speed, sp_soll, akt_v);
}
// BG, 31.12.2012: end of virtual methods of lazy_convoy_t.
private:
/**
* Route of this convoi - a sequence of coordinates. Actually
* the path of the first vehicle
*/
route_t route;
/**
* assigned line
*/
linehandle_t line;
/**
* holds id of line with pending update
* -1 if no pending update
*/
linehandle_t line_update_pending;
/**
* Name of the convoi.
* @see set_name
*/
uint8 name_offset;
char name_and_id[128];
/**
* All vehicle-schedule pointers point here
*/
schedule_t *schedule;
// Added by : Knightly
// Purpose : To hold the original schedule before opening schedule window
schedule_t *old_schedule;
koord3d schedule_target;
/**
* loading_level was minimum_loading before. Actual percentage loaded for loadable vehicles (station length!).
* needed as int, since used by the gui
*/
sint32 loading_level;
/**
* At which loading level is the train allowed to start? 0 during driving.
* needed as int, since used by the gui
*/
sint32 loading_limit;
/**
* Free seats for passengers, calculated in convoi_t::calc_loading
* @author Inkelyad
*/
sint32 free_seats;
/**
* The vehicles of this convoi
*/
array_tpl<vehicle_t*> vehicle;
/*
* a list of all catg_index, which can be transported by this convoy.
*/
minivec_tpl<uint8> goods_catg_index;
/**
* Convoi owner
*/
player_t *owner;
/**
* Current map
*/
static karte_ptr_t welt;
/**
* the convoi is being withdrawn from service
*/
bool withdraw;
/**
* nothing will be loaded onto this convoi
*/
bool no_load;
/**
* If the convoy is marked for automatic replacing,
* this will point to the dataset for it; otherwise,
* it is NULL.
* @author: jamespetts, March 2010
*/
replace_data_t *replace;
/**
* send to depot when empty
* @author isidoro
*/
bool depot_when_empty;
/**
* the convoi traverses its schedule in reverse order
* @author yobbobandana
*/
bool reverse_schedule;
/**
* the convoi caches its freight info; it is only recalculation after loading or resorting
*/
// TODO: Not currently used but could be used for another flag. Delete if not used.
bool freight_info_resort;
// true, if at least one vehicle of a convoi is obsolete
bool has_obsolete;
// true, if there is at least one engine that requires catenary
bool is_electric;
// True if this is on token block working and the route has been
// renewed during the journey.
bool needs_full_route_flush;
/**
* Number of vehicles in this convoi.
*/
uint8 vehicle_count;
/* Number of steps the current convoi did already
* (only needed for leaving/entering depot)
*/
sint16 steps_driven;
/**
* this give the index of the next signal or the end of the route
* convois will slow down before it, if this is not a waypoint or the cannot pass
* The slowdown is done by the vehicle routines
*/
uint16 next_stop_index;
/**
* this give the index until which the route has been reserved. It is used for
* restoring reservations after loading a game.
*/
uint16 next_reservation_index;
/**
* The convoi is not processed every sync step for various actions
* (like waiting before signals, loading etc.) Such action will only
* continue after a waiting time larger than wait_lock
*/
sint32 wait_lock;
/**
* threaded_step needs to be able to set wait_lock indirectly, because
* it can run after an indeterminate number of sync_steps.
*/
sint32 wait_lock_next_step;
/**
* The flag whether this convoi is requested to change lane by the convoi behind this.
* @author THLeaderH
*/
bool requested_change_lane;
/**
* accumulated profit over a year
*/
sint64 jahresgewinn;
/* the odometer */
// (In *km*).
sint64 total_distance_traveled;
// The number of steps travelled since
// the odometer was last incremented.
// Used for converting tiles to km.
// @author: jamespetts
sint64 steps_since_last_odometer_increment;
/**
* Necessary for registering departure and waiting times.
* last_stop_pos cannot be used because sea-going ships do not
* stop on a halt tile.
*/
uint16 last_stop_id;
// needed for speed control/calculation
sint32 akt_speed; // current speed
sint32 akt_speed_soll; // Target speed
sint32 sp_soll; // steps to go
sint32 previous_delta_v; // Stores the previous delta_v value; otherwise these digits are lost during calculation and vehicle do not accelrate
float32e8_t v; // current speed in m/s.
uint32 next_wolke; // time to next smoke
states state;
ribi_t::ribi alte_direction; //"Old direction" (Google)
/**
* The index number of the livery scheme of the current convoy
* in the livery schemes vector in einstellungen_t.
* @author: jamespetts, April 2011
*/
uint16 livery_scheme_index;
/**
* Initialize all variables with default values.
* Each constructor must call this method first!
*/
void init(player_t *player);
/**
* Calculate route from Start to Target Coordinate
*/
bool drive_to();
/** This was formerly part of
* drive_to(), but is separated
* in order to allow multi-threading
* to work in network mode.
*/
bool prepare_for_routing();
/**
* Setup vehicles for moving in same direction than before
* if the direction is the same as before
*/
bool can_go_alte_direction();
/**
* Mark first and last vehicle.
*/
void set_erstes_letztes();
// returns the index of the vehicle at position length (16=1 tile)
int get_vehicle_at_length(uint16);
/**
* Recalculates loading level and limit.
* While driving loading_limit will be set to 0.
*/
void calc_loading();
/* Calculates (and sets) akt_speed
* needed for driving, entering and leaving a depot)
*/
void calc_acceleration(uint32 delta_t);
/**
* struct holds new financial history for convoi
*/
sint64 financial_history[MAX_MONTHS][MAX_CONVOI_COST];
/**
* initialize the financial history
*/
void init_financial_history();
/**
* the koordinate of the home depot of this convoi
* the last depot visited is considered being the home depot
*/
koord3d home_depot;
/*
* The position of the last signal passed by this convoy
*/
koord3d last_signal_pos;
// Helper function: used in init and replacing
void reset();
// Helper function: used in enter_depot and destructor.
void close_windows();
// Reverses the order of the convoy.
// @author: jamespetts
void reverse_order(bool rev);
public:
// Reorder the vehicle array
// Can be executed even with a vehicle array that does not belong to convoy for UI
static void execute_reverse_order(array_tpl<vehicle_t*> &vehicles, uint8 vehicle_count, bool rev);
private:
bool reversable;
bool reversed;
uint32 highest_axle_load;
uint32 longest_min_loading_time;
uint32 longest_max_loading_time;
uint32 current_loading_time;
uint16 min_range;
/**
* Time in ticks since this convoy last departed from
* any given stop, plus accumulated distance since the last
* stop, indexed here by timetable entry.
* @author: jamespetts, August 2011. Replaces the original
* "last_departure_time" member.
* Modified October 2011 to include accumulated distance.
*/
typedef koordhashtable_tpl<departure_point_t, departure_data_t, N_BAGS_SMALL> departure_map;
departure_map departures;
/*
* This is a table of the departures to each point in the schedule
* whose times have already been booked. This makes sure that only
* the shortest distance between each pair of points in a schedule
* is used. For example, on a schedule A>B>C>D with reversing, this
* system ensures that, when reaching C on the way back, the departure
* from A, already registered at C on the way out, is not again
* booked at C on the way back with the additional time since going
* via D has elapsed. The key is the ID for the pair of stops, and
* the value is the last departure time booked between those stops.
*/
typedef koordhashtable_tpl<id_pair, sint64, N_BAGS_SMALL> departure_time_map;
departure_time_map departures_already_booked;
/**
* This records the journey time from each point in the schedule to the
* next point in the schedule. This is used for predicting when each
* convoy will arrive at each stop in its schedule by concatenating
* strings of these and adding the waiting time for each stop.
*/
typedef koordhashtable_tpl<departure_point_t, average_tpl<uint16>, N_BAGS_SMALL> timings_map;
timings_map journey_times_between_schedule_points;
// @author: suitougreentea
times_history_map journey_times_history;
// When we arrived at current stop
// @author Inkelyad
sint64 arrival_time;
//When convoy was at first stop.
//Used in average round trip time calculations.
fixed_list_tpl<sint64, MAX_CONVOI_COST> arrival_to_first_stop;
// @author: jamespetts
uint32 rolling_average[MAX_CONVOI_COST];
uint16 rolling_average_count[MAX_CONVOI_COST];
/**To prevent repeat bookings of journey time
* and comfort when a vehicle is waiting for
* load at a stop.
*/
uint8 current_stop;
/**
* The number of times that this
* convoy has attempted to find
* a route to its destination
* and failed.
* @author: jamespetts, November 2011
*/
uint8 no_route_retry_count;
/**
* Get obsolescence from vehicle list.
* Extracted from new_month().
* Used to recalculate convoi_t::has_obsolete
*
* @author: Bernd Gabriel
*/
bool calc_obsolescence(uint16 timeline_year_month);
// matches two halts; if the pos is not identical, maybe the halt still is
bool matches_halt( const koord3d pos1, const koord3d pos2 );
/**
* Register the convoy with the stops in the schedule
*/
void register_stops();
uint32 move_to(uint16 start_index);
/**
* Advance the schedule cursor.
* Also toggles the reverse_schedule flag if necessary.
* @author yobbobandana
*/
void advance_schedule();
/**
* Measure and record the times that
* goods of all types have been waiting
* before boarding this convoy
* @author: jamespetts
*/
void book_waiting_times();
/**
* Measure and record the departure
* time of this convoy from the current
* stop (if the convoy is currently at
* a stop)
* @author: jamespetts
*/
void book_departure_time(sint64 time);
/**
* Whether this convoy is in the process
* of trying to reserve a path from a
* choose signal. Only relevant for rail
* convoys, as this is for the block
* reserver.
* @author: jamespetts
*/
bool is_choosing:1;
// This is true if this convoy has not stopped since it emerged
// from a depot. This is useful for ensuring that a stop's reversing
// status is not set incorrectly.
bool last_stop_was_depot:1;
// The maximum speed allowed by the current signalling system
sint32 max_signal_speed;
// The classes of passengers/mail carried by this line
// Cached to reduce recalculation times in the path
// explorer.
minivec_tpl<uint8> passenger_classes_carried;
minivec_tpl<uint8> mail_classes_carried;
/**
* the route index of the point to quit yielding lane
* == -1 means this convoi isn't yielding.
* @author teamhimeH
*/
sint32 yielding_quit_index;
// 0: not fixed, -1: fixed to traffic lane, 1: fixed to passing lane
sint8 lane_affinity;
uint32 lane_affinity_end_index = INVALID_INDEX;
// true, if this vehicle will cross lane and block other vehicles.
bool next_cross_lane;
// Flag to set to false during certain signalling operations to disable reservation clearing.
bool allow_clear_reservation = true;
// This obviates the need to call can_enter_tile
// more than once in a step on the same tile
koord3d checked_tile_this_step = koord3d::invalid;
public:
/**
* Some precalculated often used infos about a tile of the convoy's route.
* @author B. Gabriel
*/
class route_info_t
{
public:
sint32 speed_limit;
uint32 steps_from_start; // steps including this tile's length, which is VEHICLE_STEPS_PER_TILE for a straight way and diagonal_vehicle_steps_per_tile for a diagonal way.
ribi_t::ribi direction;
};
class route_infos_t : public vector_tpl<route_info_t>
{
// BG, 05.08.2012: pay attention to the aircrafts' holding pattern!
// It starts at route_index = touchdown - HOLDING_PATTERN_LENGTH - HOLDING_PATTERN_OFFSET
// and has a length of HOLDING_PATTERN_LENGTH.
sint32 hp_start_index; // -1: not an aircraft or aircraft has passed the start of the holding pattern.
sint32 hp_end_index; // -1: not an aircraft or aircraft has passed the start of the holding pattern.
sint32 hp_start_step; // -1: not an aircraft or aircraft has passed the start of the holding pattern.
sint32 hp_end_step; // -1: not an aircraft or aircraft has passed the start of the holding pattern.
public:
void set_holding_pattern_indexes(sint32 current_route_index, sint32 touchdown_route_index);
inline sint32 get_holding_pattern_start_index() const { return hp_start_index; }
inline sint32 get_holding_pattern_end_index() const { return hp_end_index; }
inline sint32 get_holding_pattern_start_step() const { return hp_start_step; }
inline sint32 get_holding_pattern_end_step() const { return hp_end_step; }
// BG 05.08.2012: calc number of steps. Ignores the holding pattern, if start_step starts before it and end_step ends after it.
// In any other case the holding pattern is part off the route or is irrelevant.
inline sint32 calc_steps(sint32 start_step, sint32 end_step)
{
if (hp_start_step >= 0 && start_step < hp_start_step && hp_end_step <= end_step)
{
// assume they will not send us into the holding pattern: skip it.
return (end_step - start_step) - (hp_end_step - hp_start_step);
}
return end_step - start_step;
}
// BG 05.08.2012: calc number of tiles. Ignores the holding pattern, if start_index starts before it and end_index ends after it.
// In any other case the holding pattern is part off the route or is irrelevant.
inline sint32 calc_tiles(sint32 start_index, sint32 end_index)
{
if (hp_start_index >= 0 && start_index < hp_start_index && hp_end_index <= end_index)
{
// assume they will not send us into the holding pattern: skip it.
return (end_index - start_index) - (hp_end_index - hp_start_index);
}
return end_index - start_index;
}
};
#ifdef DEBUG_PHYSICS
sint32 next_speed_limit;
sint32 steps_til_limit;
sint32 steps_til_brake;
#endif
private:
/**
* List of upcoming speed limits; for braking purposes.
* @author: jamespetts, September 2011
*/
route_infos_t route_infos;
public:
obj_t::typ get_depot_type() const;
/**
* Convoi haelt an Haltestelle und setzt quote fuer Fracht
*/
void hat_gehalten(halthandle_t halt);
#ifdef MULTI_THREAD
private:
static void unreserve_route_range(route_range_specification range);
friend void *unreserve_route_threaded(void* args);
static waytype_t current_waytype;
static uint16 current_unreserver;
public:
#endif
/**
* remove all track reservations (trains only)
*/
void unreserve_route();
route_t* get_route() { return &route; }
route_t* access_route() { return &route; }
route_t::route_result_t calc_route(koord3d start, koord3d ziel, sint32 max_speed);
void update_route(uint32 index, const route_t &replacement); // replace route with replacement starting at index.
void replace_route(const route_t &replacement); // Completely replace the route with that passed as a parameter.
const koord3d get_schedule_target() const { return schedule_target; }
void set_schedule_target( koord3d t ) { schedule_target = t; }
// Sorting purpose for GUI
// Additional numbers will be assigned if convoy is moving backwards from the end of the schedule
uint16 get_current_schedule_order() const;
/**
* get line
*/
inline linehandle_t get_line() const {return line;}
/* true, if electrification needed for this convoi */
inline bool needs_electrification() const { return is_electric; }
/**
* set line
*/
void set_line(linehandle_t );
/*
* Clears the average speed of this vehicle for this month and last.
* Used when re-assigning a line to avoid stale data being used in
* service frequency and other computations.
*/
void clear_average_speed();
// updates a line schedule and tries to find the best next station to go
void check_pending_updates();
// true if this is a waypoint
bool is_waypoint( koord3d ) const;
/* changes the state of a convoi via tool_t; mandatory for networkmode!
* for list of commands and parameter see tool_t::tool_change_convoi_t
*/
void call_convoi_tool( const char function, const char *extra = NULL );
/**
* set state: only use by tool_t::tool_change_convoi_t
*/
void set_state( uint16 new_state ) { assert(new_state<MAX_STATES); state = (states)new_state; }
/**
* get state
*/
int get_state() const { return state; }
// In any of these states, user interaction should not be possible.
bool is_locked() const { return state == EDIT_SCHEDULE || state == ROUTING_2 || state == ROUTE_JUST_FOUND; }
bool is_loading() const { return state == LOADING || state == WAITING_FOR_LOADING_THREE_MONTHS || state == WAITING_FOR_LOADING_FOUR_MONTHS; }
/**
* true if in waiting state (maybe also due to starting)
*/
bool is_waiting() const { return (state>=WAITING_FOR_CLEARANCE && state<=CAN_START_TWO_MONTHS) && state!=SELF_DESTRUCT; }
/**
* reset state to no error message
*/
inline void reset_waiting() { state=WAITING_FOR_CLEARANCE; }
/**
* The handle for ourselves. In Anlehnung an 'this' aber mit
* allen checks beim Zugriff.
*/
convoihandle_t self;
/**
* The profit in this year
*/
inline const sint64 & get_jahresgewinn() const {return jahresgewinn;}
const sint64 & get_total_distance_traveled() const { return total_distance_traveled; }
/**
* returns the total running cost for all vehicles in convoi
*/
sint32 get_running_cost() const;
// Gets the running cost per kilometre
// for GUI purposes.
// @author: jamespetts
sint32 get_per_kilometre_running_cost() const;
/**
* returns the total monthly fixed maintenance cost for all vehicles in convoi
* @author Bernd Gabriel
*/
uint32 get_fixed_cost() const;
/**
* returns the total new purchase cost for all vehicles in convoy
*/
sint64 get_purchase_cost() const;
/**
* Constructor for loading from file,
*/
convoi_t(loadsave_t *file);
convoi_t(player_t* player);
virtual ~convoi_t();
/**
* Load or save this convoi data
*/
void rdwr(loadsave_t *file);
/**
* method to load/save convoihandle_t
*/
static void rdwr_convoihandle_t(loadsave_t *file, convoihandle_t &cnv);
void finish_rd();
void rotate90( const sint16 y_size );
/**
* Called if a vehicle enters a depot
*/
void enter_depot(depot_t *dep);
/**
* Return the internal name of the convois
* @return Name of the convois
*/
inline const char *get_internal_name() const {return name_and_id+name_offset;}
/**
* Allows editing ...
* @return Name of the Convois
*/
inline char *access_internal_name() {return name_and_id+name_offset;}
/**
* Return the name of the convois
* @return Name of the convois
*/
inline const char *get_name() const {return name_and_id;}
/**
* Sets the name. Copies name into this->name and translates it.
*/
void set_name(const char *name, bool with_new_id = true);
/**
* Return the position of the convois.
* @return Position of the convois
*/
koord3d get_pos() const;
/**
* @return current speed, this might be different from topspeed
* actual currently set speed.
*/
inline sint32 get_akt_speed() const { return akt_speed; }
inline sint32 get_akt_speed_soll() const { return akt_speed_soll; }
/**
* @return total power of this convoi
*/
inline uint32 get_sum_power() { return get_continuous_power().to_sint32(); }
inline sint32 get_min_top_speed() {return get_vehicle_summary().max_sim_speed;}
inline sint32 get_max_power_speed() OVERRIDE {return get_min_top_speed();}
/// @returns weight of the convoy's vehicles (excluding freight)
inline sint64 get_sum_weight() {return get_vehicle_summary().weight;}
/// @returns weight of convoy including freight
//inline const sint64 & get_sum_gesamtweight() const {return sum_gesamtweight;}
/** Get power index in kW multiplied by gear.
* Get effective power in kW by dividing by GEAR_FACTOR, which is 64.
* @author Bernd Gabriel, Nov, 14 2009
*/
//inline const sint32 & get_power_index() { return sum_gear_and_power; }
uint32 get_length() const;
/**
* @return length of convoi in the correct units for movement
*/
uint32 get_length_in_steps() const { return get_length() * VEHICLE_STEPS_PER_CARUNIT; }
/**
* Add the costs for travelling one tile
*/
void add_running_cost(sint64 cost, const weg_t *weg);