This repository has been archived by the owner on May 27, 2019. It is now read-only.
/
destination_r8990.diff
2013 lines (1909 loc) · 72.3 KB
/
destination_r8990.diff
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
Index: src/settings.cpp
===================================================================
--- src/settings.cpp (revision 8990)
+++ src/settings.cpp (working copy)
@@ -1355,6 +1355,10 @@
SDT_VAR(Patches, ending_year, SLE_INT32,0,NC|NO,2051, MIN_YEAR, MAX_YEAR, 1, STR_CONFIG_PATCHES_ENDING_YEAR, NULL),
SDT_BOOL(Patches, smooth_economy, 0, 0, true, STR_CONFIG_PATCHES_SMOOTH_ECONOMY, NULL),
SDT_BOOL(Patches, allow_shares, 0, 0, true, STR_CONFIG_PATCHES_ALLOW_SHARES, NULL),
+ SDT_CONDBOOL(Patches, use_destinations, SL_DEST_VERSION, SL_MAX_VERSION, 0, 0, false, STR_CONFIG_PATCHES_DESTINATIONS, NULL),
+ SDT_CONDVAR(Patches, max_transfers_to_dest,SLE_UINT8, SL_DEST_VERSION, SL_MAX_VERSION, 0, 0, 2, 0, 15, 1, STR_CONFIG_PATCHES_DESTINATIONS_DEPTH, NULL),
+ SDT_CONDVAR(Patches, forget_connections_after,SLE_UINT8,SL_DEST_VERSION,SL_MAX_VERSION, 0, 0, 4, 1, 15, 1, STR_CONFIG_PATCHES_RESET_CONNECTION_TIME, NULL),
+ SDT_CONDVAR(Patches, reduce_passenger, SLE_UINT8, SL_DEST_VERSION, SL_MAX_VERSION, 0, 0, 2, 0, 8, 1, STR_CONFIG_PATCHES_REDUCE_PASSENGER, NULL),
/***************************************************************************/
/* AI section of the GUI-configure patches window */
Index: src/ship_gui.cpp
===================================================================
--- src/ship_gui.cpp (revision 8990)
+++ src/ship_gui.cpp (working copy)
@@ -275,7 +275,7 @@
ShowOrdersWindow(v);
break;
case 10: /* show details */
- ShowShipDetailsWindow(v);
+ ShowVehicleDetailsWindow(v);
break;
case 11: {
/* clone vehicle */
Index: src/newgrf_config.cpp
===================================================================
--- src/newgrf_config.cpp (revision 8990)
+++ src/newgrf_config.cpp (working copy)
@@ -367,7 +367,11 @@
typedef struct UnknownGRF UnknownGRF;
struct UnknownGRF : public GRFIdentifier {
UnknownGRF *next;
+#ifdef ENABLE_NETWORK
char name[NETWORK_GRF_NAME_LENGTH];
+#else
+ char name[80];
+#endif
};
/**
Index: src/vehicle_gui.h
===================================================================
--- src/vehicle_gui.h (revision 8990)
+++ src/vehicle_gui.h (working copy)
@@ -69,4 +69,7 @@
return (type == VEH_Train || type == VEH_Road) ? 14 : 24;
}
+// unified details on the vehicle/consist
+void ShowVehicleDetailsWindow(const Vehicle *v);
+
#endif /* VEHICLE_GUI_H */
Index: src/lang/english.txt
===================================================================
--- src/lang/english.txt (revision 8990)
+++ src/lang/english.txt (working copy)
@@ -1119,6 +1119,11 @@
STR_CONFIG_PATCHES_ENDING_YEAR :{LTBLUE}End game in: {ORANGE}{STRING1}
STR_CONFIG_PATCHES_SMOOTH_ECONOMY :{LTBLUE}Enable smooth economy (more, smaller changes)
STR_CONFIG_PATCHES_ALLOW_SHARES :{LTBLUE}Allow buying shares from other companies
+STR_CONFIG_PATCHES_DESTINATIONS :{LTBLUE}Use passenger destination
+STR_CONFIG_PATCHES_DESTINATIONS_DEPTH :{LTBLUE}Max. transfers: {ORANGE}{STRING1}
+STR_CONFIG_PATCHES_RESET_CONNECTION_TIME :{LTBLUE}Forget connection after {ORANGE}{STRING1} month(s)
+STR_CONFIG_PATCHES_REDUCE_PASSENGER :{LTBLUE}Reduce passenger number by {ORANGE}{STRING1}
+
STR_CONFIG_PATCHES_DRAG_SIGNALS_DENSITY :{LTBLUE}When dragging, place signals every: {ORANGE}{STRING1} tile(s)
STR_CONFIG_PATCHES_SEMAPHORE_BUILD_BEFORE_DATE :{LTBLUE}Automatically build semaphores before: {ORANGE}{STRING1}
STR_CONFIG_PATCHES_TOOLBAR_POS :{LTBLUE}Position of main toolbar: {ORANGE}{STRING1}
@@ -1792,6 +1797,14 @@
STR_STAT_CLASS_DFLT :Default station
STR_STAT_CLASS_WAYP :Waypoints
+STR_CONNECTION_NAME :{BLUE}{STATION} {STATIONFEATURES} ({COMMA} transfers)
+STR_CONNECTION_NAME_DIRECT :{BLUE}{STATION} {STATIONFEATURES}
+STR_CONNECTION_CARGO :{WHITE}{CARGO} to {STATION}
+STR_CONNECTION_BUTTON :{BLACK}Connection
+STR_CONNECTION_BUTTON_TIP :{BLACK}Show connected stations
+STR_CONNECTION_SCROLL_BAR_TIP :{BLACK}Scrolls the list of connected stations
+STR_CONNECTION_PASSENGERS_LAST_MONTH :{WHITE} (last month: {COMMA})
+
##id 0x3800
STR_3800_SHIP_DEPOT_ORIENTATION :{WHITE}Ship Depot Orientation
STR_3801_MUST_BE_BUILT_ON_WATER :{WHITE}...must be built on water
Index: src/settings_gui.cpp
===================================================================
--- src/settings_gui.cpp (revision 8990)
+++ src/settings_gui.cpp (working copy)
@@ -612,6 +612,10 @@
"ending_year",
"smooth_economy",
"allow_shares",
+ "use_destinations",
+ "max_transfers_to_dest",
+ "forget_connections_after",
+ "reduce_passenger",
};
static const char *_patches_ai[] = {
Index: src/economy.cpp
===================================================================
--- src/economy.cpp (revision 8990)
+++ src/economy.cpp (working copy)
@@ -1344,6 +1344,7 @@
uint count, cap;
PlayerID old_player;
bool completely_empty = true;
+ bool need_recalc = true;
byte load_amount;
bool anything_loaded = false;
@@ -1375,10 +1376,21 @@
if (v->cargo_cap == 0) continue;
+ if(v->cargo_type == CT_PASSENGERS && need_recalc) {
+ // recalc the routes if there is at least one vehicle that can do passengers
+ RecalcStationConnections(st,v);
+ v->cargo_paid_for = 0; // we do real transfers
+ need_recalc = false;
+ }
+
/* If the vehicle has just arrived, set it to unload. */
if (just_arrived) SETBIT(v->vehicle_flags, VF_CARGO_UNLOADING);
ge = &st->goods[v->cargo_type];
+ if(_patches.use_destinations && v->cargo_type==CT_PASSENGERS && v->packets==NULL) {
+ v->max_packets = 16;
+ v->packets = (CargoEntry *)calloc( sizeof(v->packets[0]), v->max_packets );
+ }
count = GB(ge->waiting_acceptance, 0, 12);
/* unload? */
@@ -1387,7 +1399,74 @@
CLRBIT(u->vehicle_flags, VF_LOADING_FINISHED);
- if (v->cargo_source != last_visited && ge->waiting_acceptance & 0x8000 && !(u->current_order.flags & OF_TRANSFER)) {
+ // handle passenger destinations specially
+ if(_patches.use_destinations && v->cargo_type==CT_PASSENGERS) {
+ int j;
+
+ v->num_packets = 0;
+ v->cargo_count = 0;
+ for(j=0; j<v->max_packets; j++) {
+
+ if(v->packets[j].amount==0) continue; // empty packet
+
+ if(st->index==v->packets[j].enroute_to) {
+ // deliver goods to the station
+ st->time_since_unload = 0;
+ unloading_time += v->packets[j].amount;
+ profit += DeliverGoods(v->packets[j].amount, CT_PASSENGERS, v->cargo_source, last_visited, v->cargo_source_xy, v->packets[j].day_count);
+ result |= 1;
+ v->packets[j].amount = 0;
+ }
+ else if(GetCargoForStation(st,v->packets+j)) {
+ result |= 2;
+ // use the real profit, because we have to pay when leaving the bus
+ profit += GetTransportedGoodsIncome(
+ v->packets[j].amount,
+ DistanceManhattan(GetStation(v->cargo_source)->xy, GetStation(last_visited)->xy),
+ v->packets[j].day_count,
+ CT_PASSENGERS) * 3 / 2;
+ unloading_time += v->packets[j].amount;
+ v->packets[j].amount = 0;
+ }
+ else if((v->packets[j].transfers_count>>4)>14) {
+ // to avoid packets traveling forever, we remore packets which are not touched even after 15 stations
+ // and deliver goods to this station
+ st->time_since_unload = 0;
+ unloading_time += v->cargo_count;
+ profit += DeliverGoods(v->packets[j].amount, v->cargo_type, v->cargo_source, last_visited, v->cargo_source_xy, v->packets[j].day_count);
+ result |= 1;
+ v->packets[j].amount = 0;
+ } else {
+ // count total and age packets
+ assert(v->cargo_count+v->packets[j].amount<=v->cargo_cap);
+ if(st->index!=v->cargo_source) {
+ v->packets[j].transfers_count += (1<<4); // age the packet
+ // use the real profit, because we have to pay when leaving the bus
+ profit += GetTransportedGoodsIncome(
+ v->packets[j].amount,
+ DistanceManhattan(GetStation(v->cargo_source)->xy, GetStation(last_visited)->xy),
+ v->packets[j].day_count,
+ CT_PASSENGERS) * 3 / 2;
+ }
+ v->cargo_count += v->packets[j].amount;
+ v->num_packets ++;
+ }
+ }
+ // can happen after switching on or off
+ if(v->cargo_count>0 && v->num_packets==0) {
+ // deliver goods to the station
+ st->time_since_unload = 0;
+ unloading_time += v->cargo_count;
+ profit += DeliverGoods(v->cargo_count, v->cargo_type, v->cargo_source, last_visited, v->cargo_source_xy, v->cargo_days);
+ result |= 1;
+ v->cargo_count = 0;
+ }
+ // since we pay per station for all passengers
+ // and to avoid confusion with waiting for full load
+ // we have to set the origin to this station
+ v->cargo_source = st->index;
+ }
+ else if (v->cargo_source != last_visited && ge->waiting_acceptance & 0x8000 && !(u->current_order.flags & OF_TRANSFER)) {
/* deliver goods to the station */
st->time_since_unload = 0;
@@ -1420,7 +1499,6 @@
DistanceManhattan(v->cargo_loaded_at_xy, GetStation(last_visited)->xy),
v->cargo_days,
v->cargo_type);
-
ge->feeder_profit += v->cargo_feeder_share; // transfer cargo transfer fees to station
total_cargo_feeder_share -= v->cargo_feeder_share; // accumulate deduction of feeder shares
v->cargo_feeder_share = 0; // clear transfer cost
@@ -1431,8 +1509,8 @@
virtual_profit_total += virtual_profit; // accumulate transfer profits for whole vehicle
v->cargo_paid_for = v->cargo_count; // record how much of the cargo has been paid for to eliminate double counting
}
+ unloading_time += v->cargo_count;
- unloading_time += v->cargo_count;
t = GB(ge->waiting_acceptance, 0, 12);
if (t == 0) {
/* No goods waiting at station */
@@ -1472,6 +1550,9 @@
* the UNLOADING bit is already clear in v->vehicle_flags. */
CLRBIT(v->vehicle_flags, VF_CARGO_UNLOADING);
+ /* don't pick up goods that we unloaded or we are already full */
+ if (u->current_order.flags & OF_UNLOAD || v->cargo_count>=v->cargo_cap) continue;
+
/* We cannot have paid for more cargo than there is on board. */
assert(v->cargo_paid_for <= v->cargo_count);
@@ -1490,6 +1571,54 @@
ge->last_speed = min(t, 255);
ge->last_age = _cur_year - v->build_year;
+ // handle passenger destinations specially
+ if(_patches.use_destinations && v->cargo_type==CT_PASSENGERS) {
+ uint16 max_load = v->cargo_cap-v->cargo_count;
+ CargoEntry ce;
+ while(v->cargo_count<v->cargo_cap && v->num_packets<240 && GetCargoForVehicle(st,v,max_load,&ce)) {
+ int i;
+ // something to load here!
+ if(v->num_packets==v->max_packets) {
+ CargoEntry *tmp = v->packets;
+ v->max_packets += 16;
+ v->packets = (CargoEntry *)calloc( sizeof(v->packets[0]), v->max_packets );
+ memcpy( v->packets, tmp, sizeof(v->packets[0])*(v->max_packets-16) );
+ free( tmp );
+ }
+ v->cargo_count += ce.amount;
+ assert(v->cargo_count<=v->cargo_cap);
+ v->cargo_source = st->index;
+ v->cargo_source_xy = st->xy;
+ max_load -= ce.amount;
+ for( i=0; i<v->max_packets; i++ ) {
+ // empty slot
+ if(v->packets[i].amount==0) {
+ v->packets[i] = ce;
+ v->num_packets ++;
+ result |= 2;
+ break;
+ }
+ else if(v->packets[i].enroute_to==ce.enroute_to) {
+ // to keep the enroute_from, we would have to add the package instead
+ v->packets[i].amount += ce.amount;
+ v->packets[i].transfers_count = ce.transfers_count;
+ result |= 2;
+ break;
+ }
+ }
+ }
+ st->last_vehicle_type = v->type;
+ // sanity check
+ max_load = 0;
+ int i,j;
+ for(i=j=0; j<v->max_packets; j++) {
+ if(v->packets[j].amount==0) continue; // empty packet
+ i++;
+ max_load += v->packets[j].amount;
+ }
+ assert(i==v->num_packets && max_load==v->cargo_count && max_load<=v->cargo_cap);
+ } else {
+// wrong indet, but otherwise I will have too many conflicts
/* If there's goods waiting at the station, and the vehicle
* has capacity for it, load it on the vehicle. */
if (count != 0 &&
@@ -1539,6 +1668,7 @@
result |= 2;
st->last_vehicle_type = v->type;
}
+ }
}
v = u;
Index: src/variables.h
===================================================================
--- src/variables.h (revision 8990)
+++ src/variables.h (working copy)
@@ -221,6 +221,10 @@
/** YAPF settings */
YapfSettings yapf;
+ bool use_destinations; // passenger are created for destinations
+ uint8 max_transfers_to_dest; // maximum transfers until a destination
+ uint8 forget_connections_after; // reset a connection after xxx months
+ uint8 reduce_passenger; // reduce amount of passengers Sensible value half the number of transfers
} Patches;
VARDEF Patches _patches;
Index: src/vehicle_gui.cpp
===================================================================
--- src/vehicle_gui.cpp (revision 8990)
+++ src/vehicle_gui.cpp (working copy)
@@ -1296,3 +1296,374 @@
}
ShowVehicleListWindowLocal(player, VLW_DEPOT_LIST, vehicle_type, depot_airport_index);
}
+
+/*********** From here one the unified vehicle info dialog ********************/
+
+static void VehicleDetailsCargoTab(const Vehicle *v, int x, int y)
+{
+ if (v->cargo_cap != 0) {
+ SetDParam(0, v->cargo_type); // {CARGO} #1
+ SetDParam(1, v->cargo_count); // {CARGO} #2
+ SetDParam(2, v->cargo_type); // {SHORTCARGO} #1
+ SetDParam(3, v->cargo_cap); // {SHORTCARGO} #2
+ DrawString(x, y, STR_013F_TOTAL_CAPACITY, 0);
+ }
+}
+
+static void VehicleDetailsInfoTab(const Vehicle *v, int x, int y)
+{
+ // Only show name and value for the 'real' part
+ if (
+ (v->type==VEH_Train && !IsArticulatedPart(v)) ||
+ (v->type==VEH_Aircraft && v->subtype<=2) ||
+ v->type==VEH_Road ||
+ v->type==VEH_Ship) {
+ SetDParam(0, GetCustomEngineName(v->engine_type));
+ SetDParam(1, v->build_year);
+ SetDParam(2, v->value);
+ DrawString(x, y, STR_882C_BUILT_VALUE, 0);
+ }
+}
+
+static int DrawVehicleSprite(const Vehicle *v, int x, int y)
+{
+ const Vehicle *u=v;
+ int dx = 0;
+ SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
+
+ switch(v->type) {
+
+ case VEH_Train:
+ do {
+ extern int WagonLengthToPixels(int len);
+ DrawSprite(GetTrainImage(u, DIR_W), pal, x + dx, y + (is_custom_sprite(RailVehInfo(u->engine_type)->image_index) ? _traininfo_vehicle_pitch : 0));
+ dx += WagonLengthToPixels(u->u.rail.cached_veh_length);
+ u = u->next;
+ } while (u != NULL && IsArticulatedPart(u) && u->cargo_cap == 0);
+ break;
+
+ case VEH_Road:
+ DrawSprite(GetRoadVehImage(v, DIR_W), pal, x, y);
+ dx = 31;
+ break;
+
+ case VEH_Aircraft:
+ if(v->subtype<=2) {
+ DrawSprite(GetAircraftImage(v, DIR_W), pal, x, y+6);
+ if (v->subtype == 0) {
+ SpriteID rotor_sprite = GetCustomRotorSprite(v, true);
+ if (rotor_sprite == 0) rotor_sprite = SPR_ROTOR_STOPPED;
+ DrawSprite(rotor_sprite, pal, x, y);
+ }
+ }
+ dx = 60;
+ break;
+
+ case VEH_Ship:
+ DrawSprite(GetShipImage(v, DIR_W), GetVehiclePalette(v), x+32, y+6);
+ dx = 66;
+ break;
+ }
+ return dx;
+}
+
+static void DrawVehicleDetailsWindow(Window *w)
+{
+ extern int WagonLengthToPixels(int len);
+
+ byte det_tab = WP(w, vehicledetails_d).tab;
+ const Vehicle* v;
+ const Vehicle* u;
+ AcceptedCargo act_cargo;
+ AcceptedCargo max_cargo;
+ CargoEntry pass_entries[1024]; // info for sum display
+ uint max_pass_entries=0;
+ uint i;
+ int num;
+ int x;
+ int y;
+ int sel;
+
+ num = 0;
+ u = v = GetVehicle(w->window_number);
+ if (det_tab == 2) { // Total cargo tab
+ for (i = 0; i < lengthof(act_cargo); i++) {
+ act_cargo[i] = 0;
+ max_cargo[i] = 0;
+ }
+
+ do {
+ act_cargo[u->cargo_type] += u->cargo_count;
+ max_cargo[u->cargo_type] += u->cargo_cap;
+ // has packets that needs to join with train
+ if(_patches.use_destinations && u->num_packets>0) {
+ uint entry, j;
+ // we print the total info, thus we must join packets and skip empty packets
+ for (j=0; j<u->max_packets; j++) {
+ // ignore empty packets
+ if(u->packets[j].amount==0) continue;
+
+ for (entry=0; entry<max_pass_entries; entry++) {
+ if(pass_entries[entry].enroute_to==u->packets[j].enroute_to && u->packets[j].amount>0) break;
+ }
+ if(entry>=max_pass_entries) {
+ // not yet there: new line to add
+ pass_entries[entry].amount = 0;
+ max_pass_entries ++;
+ num ++;
+ }
+ pass_entries[entry].enroute_to = u->packets[j].enroute_to;
+ pass_entries[entry].amount += u->packets[j].amount;
+ }
+ }
+ } while ((u = u->next) != NULL);
+
+ /* Set scroll-amount seperately from counting, as to not compute num double
+ * for more carriages of the same type
+ */
+ for (i = 0; i != NUM_CARGO; i++) {
+ if (max_cargo[i] > 0) num++; // only count carriages that the train has
+ }
+ num++; // needs one more because first line is description string
+ } else {
+ do {
+ if (!IsArticulatedPart(u) || u->cargo_cap != 0) num++;
+ } while ((u = u->next) != NULL);
+ }
+
+ SetVScrollCount(w, num);
+
+ SetWindowWidgetDisabledState(w, 8, v->owner != _local_player);
+
+ /* disable service-scroller when interval is set to disabled */
+ SetWindowWidgetDisabledState(w, 5, !_patches.servint_trains);
+ SetWindowWidgetDisabledState(w, 6, !_patches.servint_trains);
+
+ SetDParam(0, v->string_id);
+ SetDParam(1, v->unitnumber);
+ DrawWindowWidgets(w);
+
+ SetDParam(1, v->age / 366);
+
+ x = 2;
+
+ switch(v->type) {
+ case VEH_Train:
+ SetDParam(0, (v->age + 365 < v->max_age) ? STR_AGE : STR_AGE_RED);
+ SetDParam(2, v->max_age / 366);
+ SetDParam(3, GetTrainRunningCost(v) >> 8);
+ DrawString(x, 15, STR_885D_AGE_RUNNING_COST_YR, 0);
+
+ SetDParam(2, v->u.rail.cached_max_speed);
+ SetDParam(1, v->u.rail.cached_power);
+ SetDParam(0, v->u.rail.cached_weight);
+ DrawString(x, 25, STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED, 0);
+ break;
+
+ case VEH_Road:
+ SetDParam(0, (v->age + 365 < v->max_age) ? STR_AGE : STR_AGE_RED);
+ SetDParam(2, v->max_age / 366);
+ SetDParam(3, RoadVehInfo(v->engine_type)->running_cost * _price.roadveh_running >> 8);
+ DrawString(x, 15, STR_885D_AGE_RUNNING_COST_YR, 0);
+
+ SetDParam(0, v->max_speed / 2);
+ DrawString(x, 25, STR_900E_MAX_SPEED, 0);
+ break;
+
+ case VEH_Aircraft:
+ SetDParam(0, (v->age + 365 < v->max_age) ? STR_AGE : STR_AGE_RED);
+ SetDParam(2, v->max_age / 366);
+ SetDParam(3, _price.aircraft_running * AircraftVehInfo(v->engine_type)->running_cost >> 8);
+ DrawString(x, 15, STR_A00D_AGE_RUNNING_COST_YR, 0);
+
+ SetDParam(0, v->max_speed / 2);
+ DrawString(x, 25, STR_900E_MAX_SPEED, 0);
+ break;
+
+ case VEH_Ship:
+ SetDParam(0, (v->age + 365 < v->max_age) ? STR_AGE : STR_AGE_RED);
+ SetDParam(2, v->max_age / 366);
+ SetDParam(3, ShipVehInfo(v->engine_type)->running_cost * _price.ship_running >> 8);
+ DrawString(x, 15, STR_9812_AGE_RUNNING_COST_YR, 0);
+
+ SetDParam(0, v->max_speed / 2);
+ DrawString(2, 25, STR_9813_MAX_SPEED, 0);
+ break;
+ }
+
+ SetDParam(0, v->profit_this_year);
+ SetDParam(1, v->profit_last_year);
+ DrawString(x, 35, STR_885F_PROFIT_THIS_YEAR_LAST_YEAR, 0);
+
+ SetDParam(0, 100 * (v->reliability>>8) >> 8);
+ SetDParam(1, v->breakdowns_since_last_service);
+ DrawString(x, 47 + (w->vscroll.cap * 14), STR_8860_RELIABILITY_BREAKDOWNS, 0);
+
+ SetDParam(0, v->service_interval);
+ SetDParam(1, v->date_of_last_service);
+ DrawString(x + 11, 57 + (w->vscroll.cap * 14), _patches.servint_ispercent ? STR_SERVICING_INTERVAL_PERCENT : STR_883C_SERVICING_INTERVAL_DAYS, 0);
+
+ y = 46;
+ sel = w->vscroll.pos;
+
+ // draw the first 3 details tabs
+ if (det_tab != 2) {
+ x = 1;
+ for (;;) {
+ if (--sel < 0 && sel >= -w->vscroll.cap) {
+ int px=DrawVehicleSprite(v, x+14, y+6 );
+ switch (det_tab) {
+ default: NOT_REACHED();
+ case 0: VehicleDetailsCargoTab(v, x+14+px, y+2); break;
+ case 1: VehicleDetailsInfoTab(v, x+14+px, y+2); break;
+ }
+ y += 14;
+ v = v->next;
+ } else {
+ // Move to the next line
+ do {
+ v = v->next;
+ } while (v != NULL && IsArticulatedPart(v) && v->cargo_cap == 0);
+ }
+ if (v == NULL) return;
+ }
+ } else {
+ // draw total cargo tab
+ DrawString(x, y + 2, STR_013E_TOTAL_CARGO, 0);
+ for (i = 0; i != NUM_CARGO; i++) {
+ if (max_cargo[i] > 0 && --sel < 0 && sel > -w->vscroll.cap) {
+ y += 14;
+ SetDParam(0, i); // {CARGO} #1
+ SetDParam(1, act_cargo[i]); // {CARGO} #2
+ SetDParam(2, i); // {SHORTCARGO} #1
+ SetDParam(3, max_cargo[i]); // {SHORTCARGO} #2
+ DrawString(x, y + 2, STR_013F_TOTAL_CAPACITY, 0);
+ }
+ }
+ // destinations details
+ if(_patches.use_destinations && max_cargo[0]>0) {
+ for(i = 0; i<max_pass_entries; i++ ) {
+ if (--sel < 0 && sel > -w->vscroll.cap) {
+ y += 14;
+ SetDParam(0, CT_PASSENGERS);
+ SetDParam(1, pass_entries[i].amount );
+ SetDParam(2, pass_entries[i].enroute_to);
+ DrawString(x, y+2, STR_CONNECTION_CARGO, 0);
+ }
+ }
+ }
+ }
+}
+
+static void VehicleDetailsWndProc(Window *w, WindowEvent *e)
+{
+ switch (e->event) {
+ case WE_PAINT:
+ DrawVehicleDetailsWindow(w);
+ break;
+ case WE_CLICK: {
+ int mod;
+ const Vehicle *v;
+ switch (e->we.click.widget) {
+ case 5: /* inc serv interval */
+ mod = _ctrl_pressed? 5 : 10;
+ goto do_change_service_int;
+
+ case 6: /* dec serv interval */
+ mod = _ctrl_pressed? -5 : -10;
+do_change_service_int:
+ v = GetVehicle(w->window_number);
+
+ mod = GetServiceIntervalClamped(mod + v->service_interval);
+ if (mod == v->service_interval) return;
+
+ DoCommandP(v->tile, v->index, mod, NULL, CMD_CHANGE_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING));
+ break;
+
+ case 8: /* name train */
+ v = GetVehicle(w->window_number);
+ SetDParam(0, v->unitnumber);
+ ShowQueryString(v->string_id, STR_8865_NAME_TRAIN, 31, 150, w, CS_ALPHANUMERAL);
+ break;
+
+ /* details buttons*/
+ case 9: // Cargo
+ case 10: // Information
+ case 11: // Total cargo
+ SetWindowWidgetLoweredState(w, 9, e->we.click.widget==9);
+ SetWindowWidgetLoweredState(w, 10, e->we.click.widget==10);
+ SetWindowWidgetLoweredState(w, 11, e->we.click.widget==11);
+ WP(w,vehicledetails_d).tab = e->we.click.widget - 9;
+ SetWindowDirty(w);
+ break;
+ }
+ } break;
+
+ case WE_ON_EDIT_TEXT:
+ if (e->we.edittext.str[0] != '\0') {
+ _cmd_text = e->we.edittext.str;
+ DoCommandP(0, w->window_number, 0, NULL,
+ CMD_NAME_VEHICLE | CMD_MSG(STR_8866_CAN_T_NAME_TRAIN));
+ }
+ break;
+
+ case WE_RESIZE:
+ if (e->we.sizing.diff.y == 0) break;
+
+ w->vscroll.cap += e->we.sizing.diff.y / 14;
+ w->widget[3].data = (w->vscroll.cap << 8) + 1;
+ break;
+ }
+}
+
+static const Widget _vehicle_details_widgets[] = {
+{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
+{ WWT_CAPTION, RESIZE_NONE, 14, 11, 329, 0, 13, STR_8802_DETAILS, STR_018C_WINDOW_TITLE_DRAG_THIS},
+{ WWT_PANEL, RESIZE_NONE, 14, 0, 329, 14, 44, 0x0, STR_NULL},
+{ WWT_MATRIX, RESIZE_BOTTOM, 14, 0, 317, 45, 129, 0x601, STR_NULL},
+{ WWT_SCROLLBAR, RESIZE_BOTTOM, 14, 318, 329, 45, 129, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
+{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 10, 140, 145, STR_0188, STR_884D_INCREASE_SERVICING_INTERVAL},
+{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 10, 146, 151, STR_0189, STR_884E_DECREASE_SERVICING_INTERVAL},
+{ WWT_PANEL, RESIZE_TB, 14, 11, 329, 140, 151, 0x0, STR_NULL},
+{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 78, 152, 163, STR_01AA_NAME, STR_884F_SHOW_DETAILS_OF_CARGO_CARRIED},
+{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 79, 158, 152, 163, STR_013C_CARGO, STR_8850_SHOW_DETAILS_OF_TRAIN_VEHICLES},
+{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 159, 238, 152, 163, STR_013D_INFORMATION, STR_8851_SHOW_CAPACITIES_OF_EACH},
+{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 239, 318, 152, 163, STR_013E_TOTAL_CARGO, STR_8852_SHOW_TOTAL_CARGO},
+{ WWT_RESIZEBOX, RESIZE_TB, 14, 318, 329, 152, 163, 0x0, STR_RESIZE_BUTTON},
+{ WWT_PANEL, RESIZE_TB, 14, 0, 329, 130, 140, 0x0, STR_NULL},
+{ WIDGETS_END},
+};
+
+
+static const WindowDesc _vehicle_details_desc = {
+ -1,-1, 330, 164,
+ WC_VEHICLE_DETAILS,WC_VEHICLE_VIEW,
+ WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_RESIZABLE,
+ _vehicle_details_widgets,
+ VehicleDetailsWndProc
+};
+
+
+void ShowVehicleDetailsWindow(const Vehicle *v)
+{
+ Window *w;
+ VehicleID veh = v->index;
+
+ DeleteWindowById(WC_VEHICLE_ORDERS, veh);
+ DeleteWindowById(WC_VEHICLE_DETAILS, veh);
+
+// _alloc_wnd_parent_num = veh;
+ w = AllocateWindowDesc(&_vehicle_details_desc);
+
+ w->window_number = veh;
+ w->caption_color = v->owner;
+ w->vscroll.cap = 6;
+ w->widget[3].data = (w->vscroll.cap << 8) + 1;
+
+ w->resize.step_height = 14;
+ w->resize.height = w->height - 14 * 4; /* Minimum of 4 wagons in the display */
+
+ SetWindowWidgetLoweredState(w, 9, true);
+
+ WP(w,vehicledetails_d).tab = 0;
+}
Index: src/network/core/config.h
===================================================================
--- src/network/core/config.h (revision 8990)
+++ src/network/core/config.h (working copy)
@@ -7,6 +7,7 @@
#ifndef NETWORK_CORE_CONFIG_H
#define NETWORK_CORE_CONFIG_H
+
#ifdef ENABLE_NETWORK
/** DNS hostname of the masterserver */
Index: src/train_gui.cpp
===================================================================
--- src/train_gui.cpp (revision 8990)
+++ src/train_gui.cpp (working copy)
@@ -259,7 +259,7 @@
ShowOrdersWindow(v);
break;
case 11: /* show train details */
- ShowTrainDetailsWindow(v);
+ ShowVehicleDetailsWindow(v);
break;
case 12:
ShowVehicleRefitWindow(v, INVALID_VEH_ORDER_ID);
@@ -371,6 +371,8 @@
const Vehicle *u;
AcceptedCargo act_cargo;
AcceptedCargo max_cargo;
+ CargoEntry pass_entries[1024]; // info for sum display
+ uint max_pass_entries=0;
uint i;
int num;
int x;
@@ -388,6 +390,24 @@
do {
act_cargo[u->cargo_type] += u->cargo_count;
max_cargo[u->cargo_type] += u->cargo_cap;
+ // has packets that needs to join with train
+ if(_patches.use_destinations && u->num_packets>0) {
+ uint entry, j;
+ // we print the total info, thus we must join packets and skip empty packets
+ for (j=0; j<u->num_packets; j++) {
+ for (entry=0; entry<max_pass_entries; entry++) {
+ if(pass_entries[entry].enroute_to==u->packets[j].enroute_to && u->packets[j].amount>0) break;
+ }
+ if(entry>=max_pass_entries) {
+ // not yet there: new line to add
+ pass_entries[entry].amount = 0;
+ max_pass_entries ++;
+ num ++;
+ }
+ pass_entries[entry].enroute_to = u->packets[j].enroute_to;
+ pass_entries[entry].amount += u->packets[j].amount;
+ }
+ }
} while ((u = u->next) != NULL);
/* Set scroll-amount seperately from counting, as to not compute num double
@@ -503,8 +523,23 @@
DrawString(x, y + 2, FreightWagonMult(i) > 1 ? STR_TOTAL_CAPACITY_MULT : STR_013F_TOTAL_CAPACITY, 0);
}
}
+<<<<<<< .mine
+ // destinations details
+ if(_patches.use_destinations && max_cargo[0]>0) {
+ for(i = 0; i<max_pass_entries; i++ ) {
+ if (--sel < 0 && sel > -w->vscroll.cap) {
+ y += 14;
+ SetDParam(0, CT_PASSENGERS);
+ SetDParam(1, pass_entries[i].amount );
+ SetDParam(2, pass_entries[i].enroute_to);
+ DrawString(x, y+2, STR_CONNECTION_CARGO, 0);
+ }
+ }
+ }
+=======
SetDParam(0, v->cargo_feeder_share);
DrawString(x, y + 15, STR_FEEDER_CARGO_VALUE, 0);
+>>>>>>> .r8990
}
}
Index: src/station.cpp
===================================================================
--- src/station.cpp (revision 8990)
+++ src/station.cpp (working copy)
@@ -47,6 +47,9 @@
time_since_unload = 255;
delete_ctr = 0;
facilities = 0;
+ // no destinations
+ num_cargos = 0;
+ passenger_waiting_modulo = 0;
last_vehicle_type = VEH_Invalid;
@@ -78,6 +81,11 @@
/* Subsidies need removal as well */
DeleteSubsidyWithStation(index);
+ if(num_cargos>0) {
+ free( passcargo );
+ free( passweight );
+ }
+
free(speclist);
xy = 0;
}
Index: src/win32.cpp
===================================================================
--- src/win32.cpp (revision 8990)
+++ src/win32.cpp (working copy)
@@ -871,7 +871,8 @@
#define _OUT_TO_STDERR 1
#define _OUT_TO_MSGBOX 2
#define _REPORT_ERRMODE 3
- int _set_error_mode(int);
+// int _set_error_mode(int);
+ #define _set_error_mode(i) /* */
#endif
#if defined(WINCE) && !defined(_tWinMain)
Index: src/saveload.h
===================================================================
--- src/saveload.h (revision 8990)
+++ src/saveload.h (working copy)
@@ -9,6 +9,8 @@
#define SIZE_MAX ((size_t)-1)
+#define SL_DEST_VERSION (48)
+
typedef enum SaveOrLoadResult {
SL_OK = 0, // completed successfully
SL_ERROR = 1, // error that was caught before internal structures were modified
Index: src/station_cmd.cpp
===================================================================
--- src/station_cmd.cpp (revision 8990)
+++ src/station_cmd.cpp (working copy)
@@ -2312,11 +2312,67 @@
FOR_ALL_STATIONS(st) StationHandleSmallTick(st);
}
+// returns true, if a connection found, conn points to the current location
+// further optimisation may use a binary search (but for short lists this is rather overkill)
+inline bool GetConnection(Station *st,StationID destID,int *conn)
+{
+ // station ids are sorted from lowest to highest => need to check only half of them
+ int i;
+
+ for( i=0; i<st->num_cargos; i++) {
+ if(st->passcargo[i].enroute_to>=destID) {
+ *conn = i;
+ return st->passcargo[i].enroute_to==destID;
+ }
+ }
+
+ // not found => end of list
+ *conn = i;
+ return false;
+}
+
+// only does work to do with passenger destinations
+// check the passengers waiting, if they can still reach their destination
+// age all destinations
void StationMonthlyLoop(void)
{
+ Station *st;
+
+ // update the passenger count
+ FOR_ALL_STATIONS(st) {
+ st->passenger_last_month = st->passenger_this_month;
+ st->passenger_this_month = 0;
+ }
+
+ // age all connections
+ FOR_ALL_STATIONS(st) {
+ int i;
+ for( i=0; i<st->num_cargos; i++ ) {
+ // age connection
+ if(st->passcargo[i].transfers_count<0xF0) st->passcargo[i].transfers_count += 0x10;
+ }
+ if(_patches.use_destinations) {
+ uint16 total_pass = 0;
+ st->total_weight = 0; // update the weight for the "random" target selection
+ for( i=0; i<st->num_cargos; i++ ) {
+ // remove stale freight
+ if(!IsValidStationID(st->passcargo[i].enroute_to) || (st->passcargo[i].transfers_count&0x0F)>_patches.max_transfers_to_dest) {
+ st->num_cargos --;
+ memmove( st->passcargo+i, st->passcargo+i+1, sizeof(st->passcargo[0])*(st->num_cargos-i) );
+ i --;
+ } else {
+ total_pass += st->passcargo[i].amount;
+ // add weight
+ st->passweight[i] = st->total_weight;
+ st->total_weight += GetStation(st->passcargo[i].enroute_to)->passenger_last_month;
+ }
+ }
+ // adjust passenger count
+ SB(st->goods[0].waiting_acceptance, 0, 12, min(0xFFF, total_pass) );
+ }
+ }
}
-
void ModifyStationRatingAround(TileIndex tile, PlayerID owner, int amount, uint radius)
{
Station *st;
@@ -2335,12 +2391,257 @@
}
}
-static void UpdateStationWaiting(Station *st, int type, uint amount)
+// check, whether the station is already in the list and add it
+// if the transfer count is smaller than the one in the list
+static void CheckStationConnectionListFor(Station *st,StationID add_st_id,uint8 transfer_count)
{
- SB(st->goods[type].waiting_acceptance, 0, 12,
- min(0xFFF, GB(st->goods[type].waiting_acceptance, 0, 12) + amount)
+ int i;
+
+ // check for dereferencing
+ if(!IsValidStationID(add_st_id) || transfer_count>_patches.max_transfers_to_dest)
+ return;
+
+ if(GetConnection(st,add_st_id,&i)) {
+ // already there, may need to adjust connection count
+ if(transfer_count<=(st->passcargo[i].transfers_count&0x0F)) {
+ // add remote connections
+ int j;
+ Station *add_st=GetStation(add_st_id);
+ st->passcargo[i].transfers_count = transfer_count; // will also reset the month counter
+ // check other stations
+ for( j=0; j<add_st->num_cargos; j++) {
+ if((add_st->passcargo[j].transfers_count&0x0F)+1<=transfer_count+_patches.max_transfers_to_dest && add_st->passcargo[j].enroute_to!=st->index) {
+ CheckStationConnectionListFor(st,add_st->passcargo[j].enroute_to,(add_st->passcargo[j].transfers_count&0x0F)+transfer_count+1);
+ }
+ }
+ }
+ return;
+ } else {
+ // ok not in the list, add new one (i is at the current insert location)
+ Station *add_st=GetStation(add_st_id);
+
+ // need to extend the list?
+ if((st->num_cargos&0x00F)==0) {
+ CargoEntry *tmp= (CargoEntry *)malloc( (st->num_cargos+16)*sizeof(st->passcargo[0]) );
+ uint32 *tmp_weight=(uint32 *)malloc( (st->num_cargos+16)*sizeof(uint32) );
+ if(st->num_cargos>0) {
+ memcpy( tmp, st->passcargo, st->num_cargos*sizeof(st->passcargo[0]) );
+ free(st->passcargo);
+ memcpy( tmp_weight, st->passweight, st->num_cargos*sizeof(st->passweight[0]) );
+ free(st->passweight);
+ }
+ st->passcargo = tmp;
+ st->passweight = tmp_weight;
+ }
+ // insert station
+ memmove( st->passcargo+i+1, st->passcargo+i, (st->num_cargos-i)*sizeof(st->passcargo[0]) );
+ st->passcargo[i].enroute_to = add_st->index;
+ st->passcargo[i].transfers_count = transfer_count; // will reset age too
+ st->passcargo[i].amount = 0; // since we store here the passengers too
+ st->num_cargos ++;
+ // adjust the weight
+ for( i++; i<st->num_cargos; i++) {
+ st->passweight[i] += add_st->passenger_last_month;
+ }
+ st->total_weight += add_st->passenger_last_month;
+ // add the remote connections
+ for( i=0; i<add_st->num_cargos; i++) {
+ if((add_st->passcargo[i].transfers_count&0x0F)<=1 && add_st->passcargo[i].enroute_to!=st->index) {
+ CheckStationConnectionListFor(st, add_st->passcargo[i].enroute_to, (add_st->passcargo[i].transfers_count&0x0F)+transfer_count+1);
+ }
+ }
+ }
+}
+
+// add the vehicles order to the station list
+void RecalcStationConnections(Station *st, Vehicle *v)
+{
+ int i;
+ Order *o;
+ unsigned total_pass = 0;
+
+ // engine has the order list
+ if(v->first!=NULL) v = v->first;
+ o = v->orders;
+
+ while(o!=NULL) {
+ if(o->type==OT_GOTO_STATION && o->dest!=st->index) {
+ // ok, a station where we are stopping but not this station
+ CheckStationConnectionListFor(st,o->dest,0);
+ }
+ o = o->next;
+ }
+ // remove obsolete connections (month set per patches)
+ for( i=0; i<st->num_cargos; i++) {
+ if(!IsValidStationID(st->passcargo[i].enroute_to) || (st->passcargo[i].transfers_count&0x0F)>_patches.max_transfers_to_dest || (st->passcargo[i].transfers_count>>4)>_patches.forget_connections_after) {
+
+ if(i+1<st->num_cargos) {
+ // first: adjust the weight
+ int j;