summaryrefslogtreecommitdiff
path: root/src/script/api/script_event_types.hpp
blob: 3ed6c5b10aaf1ad91672acbbbce9cd74eb0e38ff (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
/*
 * This file is part of OpenTTD.
 * 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.
 * 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.
 * 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/>.
 */

/** @file script_event_types.hpp The detailed types of all events. */

#ifndef SCRIPT_EVENT_TYPES_HPP
#define SCRIPT_EVENT_TYPES_HPP

#include "script_event.hpp"
#include "script_goal.hpp"
#include "script_window.hpp"

/**
 * Event Vehicle Crash, indicating a vehicle of yours is crashed.
 *  It contains the crash site, the crashed vehicle and the reason for the crash.
 * @api ai game
 */
class ScriptEventVehicleCrashed : public ScriptEvent {
public:
	/**
	 * The reasons for vehicle crashes
	 */
	enum CrashReason {
		CRASH_TRAIN,                ///< Two trains collided
		CRASH_RV_LEVEL_CROSSING,    ///< Road vehicle got under a train
		CRASH_RV_UFO,               ///< Road vehicle got under a landing ufo
		CRASH_PLANE_LANDING,        ///< Plane crashed on landing
		CRASH_AIRCRAFT_NO_AIRPORT,  ///< Aircraft crashed after it found not a single airport for landing
		CRASH_FLOODED,              ///< Vehicle was flooded
	};

	/**
	 * @param vehicle The vehicle that crashed.
	 * @param crash_site Where the vehicle crashed.
	 * @param crash_reason The reason why the vehicle crashed.
	 */
	ScriptEventVehicleCrashed(VehicleID vehicle, TileIndex crash_site, CrashReason crash_reason) :
		ScriptEvent(ET_VEHICLE_CRASHED),
		crash_site(crash_site),
		vehicle(vehicle),
		crash_reason(crash_reason)
	{}

	/**
	 * Convert an ScriptEvent to the real instance.
	 * @param instance The instance to convert.
	 * @return The converted instance.
	 */
	static ScriptEventVehicleCrashed *Convert(ScriptEvent *instance) { return (ScriptEventVehicleCrashed *)instance; }

	/**
	 * Get the VehicleID of the crashed vehicle.
	 * @return The crashed vehicle.
	 */
	VehicleID GetVehicleID() { return this->vehicle; }

	/**
	 * Find the tile the vehicle crashed.
	 * @return The crash site.
	 */
	TileIndex GetCrashSite() { return this->crash_site; }

	/**
	 * Get the reason for crashing
	 * @return The reason for crashing
	 */
	CrashReason GetCrashReason() { return this->crash_reason; }

private:
	TileIndex crash_site;     ///< The location of the crash.
	VehicleID vehicle;        ///< The crashed vehicle.
	CrashReason crash_reason; ///< The reason for crashing.
};

/**
 * Event Subsidy Offered, indicating someone offered a subsidy.
 * @api ai game
 */
class ScriptEventSubsidyOffer : public ScriptEvent {
public:
	/**
	 * @param subsidy_id The index of this subsidy in the _subsidies array.
	 */
	ScriptEventSubsidyOffer(SubsidyID subsidy_id) :
		ScriptEvent(ET_SUBSIDY_OFFER),
		subsidy_id(subsidy_id)
	{}

	/**
	 * Convert an ScriptEvent to the real instance.
	 * @param instance The instance to convert.
	 * @return The converted instance.
	 */
	static ScriptEventSubsidyOffer *Convert(ScriptEvent *instance) { return (ScriptEventSubsidyOffer *)instance; }

	/**
	 * Get the SubsidyID of the subsidy.
	 * @return The subsidy id.
	 */
	SubsidyID GetSubsidyID() { return this->subsidy_id; }

private:
	SubsidyID subsidy_id; ///< The subsidy that got offered.
};

/**
 * Event Subsidy Offer Expired, indicating a subsidy will no longer be awarded.
 * @api ai game
 */
class ScriptEventSubsidyOfferExpired : public ScriptEvent {
public:
	/**
	 * @param subsidy_id The index of this subsidy in the _subsidies array.
	 */
	ScriptEventSubsidyOfferExpired(SubsidyID subsidy_id) :
		ScriptEvent(ET_SUBSIDY_OFFER_EXPIRED),
		subsidy_id(subsidy_id)
	{}

	/**
	 * Convert an ScriptEvent to the real instance.
	 * @param instance The instance to convert.
	 * @return The converted instance.
	 */
	static ScriptEventSubsidyOfferExpired *Convert(ScriptEvent *instance) { return (ScriptEventSubsidyOfferExpired *)instance; }

	/**
	 * Get the SubsidyID of the subsidy.
	 * @return The subsidy id.
	 */
	SubsidyID GetSubsidyID() { return this->subsidy_id; }

private:
	SubsidyID subsidy_id; ///< The subsidy offer that expired.
};

/**
 * Event Subsidy Awarded, indicating a subsidy is awarded to some company.
 * @api ai game
 */
class ScriptEventSubsidyAwarded : public ScriptEvent {
public:
	/**
	 * @param subsidy_id The index of this subsidy in the _subsidies array.
	 */
	ScriptEventSubsidyAwarded(SubsidyID subsidy_id) :
		ScriptEvent(ET_SUBSIDY_AWARDED),
		subsidy_id(subsidy_id)
	{}

	/**
	 * Convert an ScriptEvent to the real instance.
	 * @param instance The instance to convert.
	 * @return The converted instance.
	 */
	static ScriptEventSubsidyAwarded *Convert(ScriptEvent *instance) { return (ScriptEventSubsidyAwarded *)instance; }

	/**
	 * Get the SubsidyID of the subsidy.
	 * @return The subsidy id.
	 */
	SubsidyID GetSubsidyID() { return this->subsidy_id; }

private:
	SubsidyID subsidy_id; ///< The subsidy that was awarded.
};

/**
 * Event Subsidy Expired, indicating a route that was once subsidized no longer is.
 * @api ai game
 */
class ScriptEventSubsidyExpired : public ScriptEvent {
public:
	/**
	 * @param subsidy_id The index of this subsidy in the _subsidies array.
	 */
	ScriptEventSubsidyExpired(SubsidyID subsidy_id) :
		ScriptEvent(ET_SUBSIDY_EXPIRED),
		subsidy_id(subsidy_id)
	{}

	/**
	 * Convert an ScriptEvent to the real instance.
	 * @param instance The instance to convert.
	 * @return The converted instance.
	 */
	static ScriptEventSubsidyExpired *Convert(ScriptEvent *instance) { return (ScriptEventSubsidyExpired *)instance; }

	/**
	 * Get the SubsidyID of the subsidy.
	 * @return The subsidy id.
	 */
	 SubsidyID GetSubsidyID() { return this->subsidy_id; }

private:
	SubsidyID subsidy_id; ///< The subsidy that expired.
};

/**
 * Event Engine Preview, indicating a manufacturer offer you to test a new engine.
 *  You can get the same information about the offered engine as a real user
 *  would see in the offer window. And you can also accept the offer.
 * @api ai
 */
class ScriptEventEnginePreview : public ScriptEvent {
public:
	/**
	 * @param engine The engine offered to test.
	 */
	ScriptEventEnginePreview(EngineID engine) :
		ScriptEvent(ET_ENGINE_PREVIEW),
		engine(engine)
	{}

	/**
	 * Convert an ScriptEvent to the real instance.
	 * @param instance The instance to convert.
	 * @return The converted instance.
	 */
	static ScriptEventEnginePreview *Convert(ScriptEvent *instance) { return (ScriptEventEnginePreview *)instance; }

	/**
	 * Get the name of the offered engine.
	 * @return The name the engine has.
	 */
	char *GetName();

	/**
	 * Get the cargo-type of the offered engine. In case it can transport multiple cargoes, it
	 *  returns the first/main.
	 * @return The cargo-type of the engine.
	 */
	CargoID GetCargoType();

	/**
	 * Get the capacity of the offered engine. In case it can transport multiple cargoes, it
	 *  returns the first/main.
	 * @return The capacity of the engine.
	 */
	int32 GetCapacity();

	/**
	 * Get the maximum speed of the offered engine.
	 * @return The maximum speed the engine has.
	 * @note The speed is in OpenTTD's internal speed unit.
	 *       This is mph / 1.6, which is roughly km/h.
	 *       To get km/h multiply this number by 1.00584.
	 */
	int32 GetMaxSpeed();

	/**
	 * Get the new cost of the offered engine.
	 * @return The new cost the engine has.
	 */
	Money GetPrice();

	/**
	 * Get the running cost of the offered engine.
	 * @return The running cost of the vehicle per year.
	 * @note Cost is per year; divide by 365 to get per day.
	 */
	Money GetRunningCost();

	/**
	 * Get the type of the offered engine.
	 * @return The type the engine has.
	 */
#ifdef DOXYGEN_API
	ScriptVehicle::VehicleType GetVehicleType();
#else
	int32 GetVehicleType();
#endif /* DOXYGEN_API */

	/**
	 * Accept the engine preview.
	 * @return True when the accepting succeeded.
	 */
	bool AcceptPreview();

private:
	EngineID engine; ///< The engine the preview is for.

	/**
	 * Check whether the engine from this preview is still valid.
	 * @return True iff the engine is still valid.
	 */
	bool IsEngineValid() const;
};

/**
 * Event Company New, indicating a new company has been created.
 * @api ai game
 */
class ScriptEventCompanyNew : public ScriptEvent {
public:
	/**
	 * @param owner The new company.
	 */
	ScriptEventCompanyNew(Owner owner) :
		ScriptEvent(ET_COMPANY_NEW),
		owner((ScriptCompany::CompanyID)owner)
	{}

	/**
	 * Convert an ScriptEvent to the real instance.
	 * @param instance The instance to convert.
	 * @return The converted instance.
	 */
	static ScriptEventCompanyNew *Convert(ScriptEvent *instance) { return (ScriptEventCompanyNew *)instance; }

	/**
	 * Get the CompanyID of the company that has been created.
	 * @return The CompanyID of the company.
	 */
	ScriptCompany::CompanyID GetCompanyID() { return this->owner; }

private:
	ScriptCompany::CompanyID owner; ///< The new company.
};

/**
 * Event Company In Trouble, indicating a company is in trouble and might go
 *  bankrupt soon.
 * @api ai game
 */
class ScriptEventCompanyInTrouble : public ScriptEvent {
public:
	/**
	 * @param owner The company that is in trouble.
	 */
	ScriptEventCompanyInTrouble(Owner owner) :
		ScriptEvent(ET_COMPANY_IN_TROUBLE),
		owner((ScriptCompany::CompanyID)owner)
	{}

	/**
	 * Convert an ScriptEvent to the real instance.
	 * @param instance The instance to convert.
	 * @return The converted instance.
	 */
	static ScriptEventCompanyInTrouble *Convert(ScriptEvent *instance) { return (ScriptEventCompanyInTrouble *)instance; }

	/**
	 * Get the CompanyID of the company that is in trouble.
	 * @return The CompanyID of the company in trouble.
	 */
	ScriptCompany::CompanyID GetCompanyID() { return this->owner; }

private:
	ScriptCompany::CompanyID owner; ///< The company that is in trouble.
};

/**
 * Event Company Ask Merger, indicating a company can be bought (cheaply) by you.
 * @api ai
 */
class ScriptEventCompanyAskMerger : public ScriptEvent {
public:
	/**
	 * @param owner The company that can be bought.
	 * @param value The value/costs of buying the company.
	 */
	ScriptEventCompanyAskMerger(Owner owner, int32 value) :
		ScriptEvent(ET_COMPANY_ASK_MERGER),
		owner((ScriptCompany::CompanyID)owner),
		value(value)
	{}

	/**
	 * Convert an ScriptEvent to the real instance.
	 * @param instance The instance to convert.
	 * @return The converted instance.
	 */
	static ScriptEventCompanyAskMerger *Convert(ScriptEvent *instance) { return (ScriptEventCompanyAskMerger *)instance; }

	/**
	 * Get the CompanyID of the company that can be bought.
	 * @return The CompanyID of the company that can be bought.
	 * @note If the company is bought this will become invalid.
	 */
	ScriptCompany::CompanyID GetCompanyID() { return this->owner; }

	/**
	 * Get the value of the new company.
	 * @return The value of the new company.
	 */
	int32 GetValue() { return this->value; }

	/**
	 * Take over the company for this merger.
	 * @return true if the merger was a success.
	 */
	bool AcceptMerger();

private:
	ScriptCompany::CompanyID owner; ///< The company that is in trouble.
	int32 value;                ///< The value of the company, i.e. the amount you would pay.
};

/**
 * Event Company Merger, indicating a company has been bought by another
 *  company.
 * @api ai game
 */
class ScriptEventCompanyMerger : public ScriptEvent {
public:
	/**
	 * @param old_owner The company bought off.
	 * @param new_owner The company that bought owner.
	 */
	ScriptEventCompanyMerger(Owner old_owner, Owner new_owner) :
		ScriptEvent(ET_COMPANY_MERGER),
		old_owner((ScriptCompany::CompanyID)old_owner),
		new_owner((ScriptCompany::CompanyID)new_owner)
	{}

	/**
	 * Convert an ScriptEvent to the real instance.
	 * @param instance The instance to convert.
	 * @return The converted instance.
	 */
	static ScriptEventCompanyMerger *Convert(ScriptEvent *instance) { return (ScriptEventCompanyMerger *)instance; }

	/**
	 * Get the CompanyID of the company that has been bought.
	 * @return The CompanyID of the company that has been bought.
	 * @note: The value below is not valid anymore as CompanyID, and
	 *  ScriptCompany::ResolveCompanyID will return COMPANY_COMPANY. It's
	 *  only useful if you're keeping track of company's yourself.
	 */
	ScriptCompany::CompanyID GetOldCompanyID() { return this->old_owner; }

	/**
	 * Get the CompanyID of the new owner.
	 * @return The CompanyID of the new owner.
	 */
	ScriptCompany::CompanyID GetNewCompanyID() { return this->new_owner; }

private:
	ScriptCompany::CompanyID old_owner; ///< The company that ended to exist.
	ScriptCompany::CompanyID new_owner; ///< The company that's the end result of the merger.
};

/**
 * Event Company Bankrupt, indicating a company has gone bankrupt.
 * @api ai game
 */
class ScriptEventCompanyBankrupt : public ScriptEvent {
public:
	/**
	 * @param owner The company that has gone bankrupt.
	 */
	ScriptEventCompanyBankrupt(Owner owner) :
		ScriptEvent(ET_COMPANY_BANKRUPT),
		owner((ScriptCompany::CompanyID)owner)
	{}

	/**
	 * Convert an ScriptEvent to the real instance.
	 * @param instance The instance to convert.
	 * @return The converted instance.
	 */
	static ScriptEventCompanyBankrupt *Convert(ScriptEvent *instance) { return (ScriptEventCompanyBankrupt *)instance; }

	/**
	 * Get the CompanyID of the company that has gone bankrupt.
	 * @return The CompanyID of the company that has gone bankrupt.
	 */
	ScriptCompany::CompanyID GetCompanyID() { return this->owner; }

private:
	ScriptCompany::CompanyID owner; ///< The company that has gone bankrupt.
};

/**
 * Event Vehicle Lost, indicating a vehicle can't find its way to its destination.
 * @api ai
 */
class ScriptEventVehicleLost : public ScriptEvent {
public:
	/**
	 * @param vehicle_id The vehicle that is lost.
	 */
	ScriptEventVehicleLost(VehicleID vehicle_id) :
		ScriptEvent(ET_VEHICLE_LOST),
		vehicle_id(vehicle_id)
	{}

	/**
	 * Convert an ScriptEvent to the real instance.
	 * @param instance The instance to convert.
	 * @return The converted instance.
	 */
	static ScriptEventVehicleLost *Convert(ScriptEvent *instance) { return (ScriptEventVehicleLost *)instance; }

	/**
	 * Get the VehicleID of the vehicle that is lost.
	 * @return The VehicleID of the vehicle that is lost.
	 */
	VehicleID GetVehicleID() { return this->vehicle_id; }

private:
	VehicleID vehicle_id; ///< The vehicle that is lost.
};

/**
 * Event VehicleWaitingInDepot, indicating a vehicle has arrived a depot and is now waiting there.
 * @api ai
 */
class ScriptEventVehicleWaitingInDepot : public ScriptEvent {
public:
	/**
	 * @param vehicle_id The vehicle that is waiting in a depot.
	 */
	ScriptEventVehicleWaitingInDepot(VehicleID vehicle_id) :
		ScriptEvent(ET_VEHICLE_WAITING_IN_DEPOT),
		vehicle_id(vehicle_id)
	{}

	/**
	 * Convert an ScriptEvent to the real instance.
	 * @param instance The instance to convert.
	 * @return The converted instance.
	 */
	static ScriptEventVehicleWaitingInDepot *Convert(ScriptEvent *instance) { return (ScriptEventVehicleWaitingInDepot *)instance; }

	/**
	 * Get the VehicleID of the vehicle that is waiting in a depot.
	 * @return The VehicleID of the vehicle that is waiting in a depot.
	 */
	VehicleID GetVehicleID() { return this->vehicle_id; }

private:
	VehicleID vehicle_id; ///< The vehicle that is waiting in the depot.
};

/**
 * Event Vehicle Unprofitable, indicating a vehicle lost money last year.
 * @api ai
 */
class ScriptEventVehicleUnprofitable : public ScriptEvent {
public:
	/**
	 * @param vehicle_id The vehicle that was unprofitable.
	 */
	ScriptEventVehicleUnprofitable(VehicleID vehicle_id) :
		ScriptEvent(ET_VEHICLE_UNPROFITABLE),
		vehicle_id(vehicle_id)
	{}

	/**
	 * Convert an ScriptEvent to the real instance.
	 * @param instance The instance to convert.
	 * @return The converted instance.
	 */
	static ScriptEventVehicleUnprofitable *Convert(ScriptEvent *instance) { return (ScriptEventVehicleUnprofitable *)instance; }

	/**
	 * Get the VehicleID of the vehicle that lost money.
	 * @return The VehicleID of the vehicle that lost money.
	 */
	VehicleID GetVehicleID() { return this->vehicle_id; }

private:
	VehicleID vehicle_id; ///< The vehicle that is unprofitable.
};

/**
 * Event Industry Open, indicating a new industry has been created.
 * @api ai game
 */
class ScriptEventIndustryOpen : public ScriptEvent {
public:
	/**
	 * @param industry_id The new industry.
	 */
	ScriptEventIndustryOpen(IndustryID industry_id) :
		ScriptEvent(ET_INDUSTRY_OPEN),
		industry_id(industry_id)
	{}

	/**
	 * Convert an ScriptEvent to the real instance.
	 * @param instance The instance to convert.
	 * @return The converted instance.
	 */
	static ScriptEventIndustryOpen *Convert(ScriptEvent *instance) { return (ScriptEventIndustryOpen *)instance; }

	/**
	 * Get the IndustryID of the new industry.
	 * @return The IndustryID of the industry.
	 */
	IndustryID GetIndustryID() { return this->industry_id; }

private:
	IndustryID industry_id; ///< The industry that opened.
};

/**
 * Event Industry Close, indicating an industry is going to be closed.
 * @api ai game
 */
class ScriptEventIndustryClose : public ScriptEvent {
public:
	/**
	 * @param industry_id The new industry.
	 */
	ScriptEventIndustryClose(IndustryID industry_id) :
		ScriptEvent(ET_INDUSTRY_CLOSE),
		industry_id(industry_id)
	{}

	/**
	 * Convert an ScriptEvent to the real instance.
	 * @param instance The instance to convert.
	 * @return The converted instance.
	 */
	static ScriptEventIndustryClose *Convert(ScriptEvent *instance) { return (ScriptEventIndustryClose *)instance; }

	/**
	 * Get the IndustryID of the closing industry.
	 * @return The IndustryID of the industry.
	 */
	IndustryID GetIndustryID() { return this->industry_id; }

private:
	IndustryID industry_id; ///< The industry that closed.
};

/**
 * Event Engine Available, indicating a new engine is available.
 * @api ai
 */
class ScriptEventEngineAvailable : public ScriptEvent {
public:
	/**
	 * @param engine The engine that is available.
	 */
	ScriptEventEngineAvailable(EngineID engine) :
		ScriptEvent(ET_ENGINE_AVAILABLE),
		engine(engine)
	{}

	/**
	 * Convert an ScriptEvent to the real instance.
	 * @param instance The instance to convert.
	 * @return The converted instance.
	 */
	static ScriptEventEngineAvailable *Convert(ScriptEvent *instance) { return (ScriptEventEngineAvailable *)instance; }

	/**
	 * Get the EngineID of the new engine.
	 * @return The EngineID of the new engine.
	 */
	EngineID GetEngineID() { return this->engine; }

private:
	EngineID engine; ///< The engine that became available.
};

/**
 * Event Station First Vehicle, indicating a station has been visited by a vehicle for the first time.
 * @api ai game
 */
class ScriptEventStationFirstVehicle : public ScriptEvent {
public:
	/**
	 * @param station The station visited for the first time.
	 * @param vehicle The vehicle visiting the station.
	 */
	ScriptEventStationFirstVehicle(StationID station, VehicleID vehicle) :
		ScriptEvent(ET_STATION_FIRST_VEHICLE),
		station(station),
		vehicle(vehicle)
	{}

	/**
	 * Convert an ScriptEvent to the real instance.
	 * @param instance The instance to convert.
	 * @return The converted instance.
	 */
	static ScriptEventStationFirstVehicle *Convert(ScriptEvent *instance) { return (ScriptEventStationFirstVehicle *)instance; }

	/**
	 * Get the StationID of the visited station.
	 * @return The StationID of the visited station.
	 */
	StationID GetStationID() { return this->station; }

	/**
	 * Get the VehicleID of the first vehicle.
	 * @return The VehicleID of the first vehicle.
	 */
	VehicleID GetVehicleID() { return this->vehicle; }

private:
	StationID station; ///< The station the vehicle arrived at.
	VehicleID vehicle; ///< The vehicle that arrived at the station.
};

/**
 * Event Disaster Zeppeliner Crashed, indicating a zeppeliner has crashed on an airport and is blocking the runway.
 * @api ai
 */
class ScriptEventDisasterZeppelinerCrashed : public ScriptEvent {
public:
	/**
	 * @param station The station containing the affected airport
	 */
	ScriptEventDisasterZeppelinerCrashed(StationID station) :
		ScriptEvent(ET_DISASTER_ZEPPELINER_CRASHED),
		station(station)
	{}

	/**
	 * Convert an ScriptEvent to the real instance.
	 * @param instance The instance to convert.
	 * @return The converted instance.
	 */
	static ScriptEventDisasterZeppelinerCrashed *Convert(ScriptEvent *instance) { return (ScriptEventDisasterZeppelinerCrashed *)instance; }

	/**
	 * Get the StationID of the station containing the affected airport.
	 * @return The StationID of the station containing the affected airport.
	 */
	StationID GetStationID() { return this->station; }

private:
	StationID station; ///< The station the zeppeliner crashed.
};

/**
 * Event Disaster Zeppeliner Cleared, indicating a previously crashed zeppeliner has been removed, and the airport is operating again.
 * @api ai
 */
class ScriptEventDisasterZeppelinerCleared : public ScriptEvent {
public:
	/**
	 * @param station The station containing the affected airport
	 */
	ScriptEventDisasterZeppelinerCleared(StationID station) :
		ScriptEvent(ET_DISASTER_ZEPPELINER_CLEARED),
		station(station)
	{}

	/**
	 * Convert an ScriptEvent to the real instance.
	 * @param instance The instance to convert.
	 * @return The converted instance.
	 */
	static ScriptEventDisasterZeppelinerCleared *Convert(ScriptEvent *instance) { return (ScriptEventDisasterZeppelinerCleared *)instance; }

	/**
	 * Get the StationID of the station containing the affected airport.
	 * @return The StationID of the station containing the affected airport.
	 */
	StationID GetStationID() { return this->station; }

private:
	StationID station; ///< The station the zeppeliner crashed.
};

/**
 * Event Town Founded, indicating a new town has been created.
 * @api ai game
 */
class ScriptEventTownFounded : public ScriptEvent {
public:
	/**
	 * @param town The town that was created.
	 */
	ScriptEventTownFounded(TownID town) :
		ScriptEvent(ET_TOWN_FOUNDED),
		town(town)
	{}

	/**
	 * Convert an ScriptEvent to the real instance.
	 * @param instance The instance to convert.
	 * @return The converted instance.
	 */
	static ScriptEventTownFounded *Convert(ScriptEvent *instance) { return (ScriptEventTownFounded *)instance; }

	/**
	 * Get the TownID of the town.
	 * @return The TownID of the town that was created.
	 */
	TownID GetTownID() { return this->town; }

private:
	TownID town; ///< The town that got founded.
};

/**
 * Event AircraftDestTooFar, indicating the next destination of an aircraft is too far away.
 * This event can be triggered when the current order of an aircraft changes, usually either when
 * loading is done or when switched manually.
 * @api ai
 */
class ScriptEventAircraftDestTooFar : public ScriptEvent {
public:
	/**
	 * @param vehicle_id The aircraft whose destination is too far away.
	 */
	ScriptEventAircraftDestTooFar(VehicleID vehicle_id) :
		ScriptEvent(ET_AIRCRAFT_DEST_TOO_FAR),
		vehicle_id(vehicle_id)
	{}

	/**
	 * Convert an ScriptEvent to the real instance.
	 * @param instance The instance to convert.
	 * @return The converted instance.
	 */
	static ScriptEventAircraftDestTooFar *Convert(ScriptEvent *instance) { return (ScriptEventAircraftDestTooFar *)instance; }

	/**
	 * Get the VehicleID of the aircraft whose destination is too far away.
	 * @return The VehicleID of the aircraft whose destination is too far away.
	 */
	VehicleID GetVehicleID() { return this->vehicle_id; }

private:
	VehicleID vehicle_id; ///< The vehicle aircraft whose destination is too far away.
};

/**
 * Event Admin Port, indicating the admin port is sending you information.
 * @api game
 */
class ScriptEventAdminPort : public ScriptEvent {
public:
	/**
	 * @param json The JSON string which got sent.
	 */
	ScriptEventAdminPort(const std::string &json);

	/**
	 * Convert an ScriptEvent to the real instance.
	 * @param instance The instance to convert.
	 * @return The converted instance.
	 */
	static ScriptEventAdminPort *Convert(ScriptEvent *instance) { return (ScriptEventAdminPort *)instance; }

	/**
	 * Get the information that was sent to you back as Squirrel object.
	 */
	SQInteger GetObject(HSQUIRRELVM vm);

private:
	std::string json; ///< The JSON string.

	/**
	 * Read a table from a JSON string.
	 * @param vm The VM used.
	 * @param p The (part of the) JSON string reading.
	 */
	const char *ReadTable(HSQUIRRELVM vm, const char *p);

	/**
	 * Read a value from a JSON string.
	 * @param vm The VM used.
	 * @param p The (part of the) JSON string reading.
	 */
	const char *ReadValue(HSQUIRRELVM vm, const char *p);

	/**
	 * Read a string from a JSON string.
	 * @param vm The VM used.
	 * @param p The (part of the) JSON string reading.
	 */
	const char *ReadString(HSQUIRRELVM vm, const char *p);
};

/**
 * Event Window Widget Click, when a user clicks on a highlighted widget.
 * @api game
 */
class ScriptEventWindowWidgetClick : public ScriptEvent {
public:
	/**
	 * @param window The windowclass that was clicked.
	 * @param number The windownumber that was clicked.
	 * @param widget The widget in the window that was clicked.
	 */
	ScriptEventWindowWidgetClick(ScriptWindow::WindowClass window, uint32 number, uint8 widget) :
		ScriptEvent(ET_WINDOW_WIDGET_CLICK),
		window(window),
		number(number),
		widget(widget)
	{}

	/**
	 * Convert an ScriptEvent to the real instance.
	 * @param instance The instance to convert.
	 * @return The converted instance.
	 */
	static ScriptEventWindowWidgetClick *Convert(ScriptEvent *instance) { return (ScriptEventWindowWidgetClick *)instance; }

	/**
	 * Get the class of the window that was clicked.
	 */
	ScriptWindow::WindowClass GetWindowClass() { return this->window; }

	/**
	 * Get the number of the window that was clicked.
	 */
	uint32 GetWindowNumber() { return this->number; }

	/**
	 * Get the number of the widget that was clicked.
	 */
	uint8 GetWidgetNumber() { return this->widget; }

private:
	ScriptWindow::WindowClass window; ///< Window of the click.
	uint32 number;                    ///< Number of the click.
	uint8 widget;                     ///< Widget of the click.
};

/**
 * Event Goal Question Answer, where you receive the answer given to your questions.
 * @note It is possible that you get more than 1 answer from the same company
 *  (due to lag). Please keep this in mind while handling this event.
 * @api game
 */
class ScriptEventGoalQuestionAnswer : public ScriptEvent {
public:
	/**
	 * @param uniqueid The uniqueID you have given this question.
	 * @param company The company that is replying.
	 * @param button The button the company pressed.
	 */
	ScriptEventGoalQuestionAnswer(uint16 uniqueid, ScriptCompany::CompanyID company, ScriptGoal::QuestionButton button) :
		ScriptEvent(ET_GOAL_QUESTION_ANSWER),
		uniqueid(uniqueid),
		company(company),
		button(button)
	{}

	/**
	 * Convert an ScriptEvent to the real instance.
	 * @param instance The instance to convert.
	 * @return The converted instance.
	 */
	static ScriptEventGoalQuestionAnswer *Convert(ScriptEvent *instance) { return (ScriptEventGoalQuestionAnswer *)instance; }

	/**
	 * Get the unique id of the question.
	 */
	uint16 GetUniqueID() { return this->uniqueid; }

	/**
	 * Get the company that pressed a button.
	 */
	ScriptCompany::CompanyID GetCompany() { return this->company; }

	/**
	 * Get the button that got pressed.
	 */
	ScriptGoal::QuestionButton GetButton() { return this->button; }

private:
	uint16 uniqueid;                   ///< The uniqueid of the question.
	ScriptCompany::CompanyID company;  ///< The company given the answer.
	ScriptGoal::QuestionButton button; ///< The button that was pressed.
};

/**
 * Base class for events involving a town and a company.
 * @api ai game
 */
class ScriptEventCompanyTown : public ScriptEvent {
public:
	/**
	 * @param event The eventtype.
	 * @param company The company.
	 * @param town The town.
	 */
	ScriptEventCompanyTown(ScriptEventType event, ScriptCompany::CompanyID company, TownID town) :
		ScriptEvent(event),
		company(company),
		town(town)
	{}

	/**
	 * Convert an ScriptEvent to the real instance.
	 * @param instance The instance to convert.
	 * @return The converted instance.
	 */
	static ScriptEventCompanyTown *Convert(ScriptEvent *instance) { return (ScriptEventCompanyTown *)instance; }

	/**
	 * Get the CompanyID of the company.
	 * @return The CompanyID of the company involved into the event.
	 */
	ScriptCompany::CompanyID GetCompanyID() { return this->company; }

	/**
	 * Get the TownID of the town.
	 * @return The TownID of the town involved into the event.
	 */
	TownID GetTownID() { return this->town; }

private:
	ScriptCompany::CompanyID company; ///< The company involved into the event.
	TownID town;                      ///< The town involved into the event.
};

/**
 * Event Exclusive Transport Rights, indicating that company bought
 * exclusive transport rights in a town.
 * @api ai game
 */
class ScriptEventExclusiveTransportRights : public ScriptEventCompanyTown {
public:
	/**
	 * @param company The company.
	 * @param town The town.
	 */
	ScriptEventExclusiveTransportRights(ScriptCompany::CompanyID company, TownID town) :
		ScriptEventCompanyTown(ET_EXCLUSIVE_TRANSPORT_RIGHTS, company, town)
	{}

	/**
	 * Convert an ScriptEvent to the real instance.
	 * @param instance The instance to convert.
	 * @return The converted instance.
	 */
	static ScriptEventExclusiveTransportRights *Convert(ScriptEventCompanyTown *instance) { return (ScriptEventExclusiveTransportRights *)instance; }
};

/**
 * Event Road Reconstruction, indicating that company triggered
 * road reconstructions in a town.
 * @api ai game
 */
class ScriptEventRoadReconstruction : public ScriptEventCompanyTown {
public:
	/**
	 * @param company The company.
	 * @param town The town.
	 */
	ScriptEventRoadReconstruction(ScriptCompany::CompanyID company, TownID town) :
		ScriptEventCompanyTown(ET_ROAD_RECONSTRUCTION, company, town)
	{}

	/**
	 * Convert an ScriptEvent to the real instance.
	 * @param instance The instance to convert.
	 * @return The converted instance.
	 */
	static ScriptEventRoadReconstruction *Convert(ScriptEventCompanyTown *instance) { return (ScriptEventRoadReconstruction *)instance; }
};

/**
 * Event VehicleAutoReplaced, indicating a vehicle has been auto replaced.
 * @api ai
 */
class ScriptEventVehicleAutoReplaced : public ScriptEvent {
public:
	/**
	 * @param old_id The vehicle that has been replaced.
	 * @param new_id The vehicle that has been created in replacement.
	 */
	ScriptEventVehicleAutoReplaced(VehicleID old_id, VehicleID new_id) :
		ScriptEvent(ET_VEHICLE_AUTOREPLACED),
		old_id(old_id),
		new_id(new_id)
	{}

	/**
	 * Convert an ScriptEvent to the real instance.
	 * @param instance The instance to convert.
	 * @return The converted instance.
	 */
	static ScriptEventVehicleAutoReplaced *Convert(ScriptEvent *instance) { return (ScriptEventVehicleAutoReplaced *)instance; }

	/**
	 * Get the VehicleID of the vehicle that has been replaced.
	 * @return The VehicleID of the vehicle that has been replaced. This ID is no longer valid for referencing the vehicle.
	 */
	VehicleID GetOldVehicleID() { return this->old_id; }

	/**
	 * Get the VehicleID of the vehicle that has been created in replacement.
	 * @return The VehicleID of the vehicle that has been created in replacement.
	 */
	VehicleID GetNewVehicleID() { return this->new_id; }

private:
	VehicleID old_id; ///< The vehicle that has been replaced.
	VehicleID new_id; ///< The vehicle that has been created in replacement.
};

/**
 * Event StoryPageButtonClick, indicating a player clicked a push button on a storybook page.
 * @api game
 */
class ScriptEventStoryPageButtonClick : public ScriptEvent {
public:
	/**
	 * @param company_id  Which company triggered the event.
	 * @param page_id     Which page was the clicked button on.
	 * @param element_id  Which button element was clicked.
	 */
	ScriptEventStoryPageButtonClick(CompanyID company_id, StoryPageID page_id, StoryPageElementID element_id) :
		ScriptEvent(ET_STORYPAGE_BUTTON_CLICK),
		company_id((ScriptCompany::CompanyID)company_id),
		page_id(page_id),
		element_id(element_id)
	{ }

	/**
	 * Convert an ScriptEvent to the real instance.
	 * @param instance The instance to convert.
	 * @return The converted instance.
	 */
	static ScriptEventStoryPageButtonClick *Convert(ScriptEvent *instance) { return (ScriptEventStoryPageButtonClick *)instance; }

	/** Get the CompanyID of the player that selected a tile. */
	ScriptCompany::CompanyID GetCompanyID() { return this->company_id; }

	/** Get the StoryPageID of the storybook page the clicked button is located on. */
	StoryPageID GetStoryPageID() { return this->page_id; }

	/** Get the StoryPageElementID of the button element that was clicked. */
	StoryPageElementID GetElementID() { return this->element_id; }

private:
	ScriptCompany::CompanyID company_id;
	StoryPageID page_id;
	StoryPageElementID element_id;
};

/**
 * Event StoryPageTileSelect, indicating a player clicked a tile selection button on a storybook page, and selected a tile.
 * @api game
 */
class ScriptEventStoryPageTileSelect : public ScriptEvent {
public:
	/**
	 * @param company_id  Which company triggered the event.
	 * @param page_id     Which page is the used selection button on.
	 * @param element_id  Which button element was used to select the tile.
	 * @param tile_index  Which tile was selected by the player.
	 */
	ScriptEventStoryPageTileSelect(CompanyID company_id, StoryPageID page_id, StoryPageElementID element_id, TileIndex tile_index) :
		ScriptEvent(ET_STORYPAGE_TILE_SELECT),
		company_id((ScriptCompany::CompanyID)company_id),
		page_id(page_id),
		element_id(element_id),
		tile_index(tile_index)
	{ }

	/**
	 * Convert an ScriptEvent to the real instance.
	 * @param instance The instance to convert.
	 * @return The converted instance.
	 */
	static ScriptEventStoryPageTileSelect *Convert(ScriptEvent *instance) { return (ScriptEventStoryPageTileSelect *)instance; }

	/** Get the CompanyID of the player that selected a tile. */
	ScriptCompany::CompanyID GetCompanyID() { return this->company_id; }

	/** Get the StoryPageID of the storybook page the used selection button is located on. */
	StoryPageID GetStoryPageID() { return this->page_id; }

	/** Get the StoryPageElementID of the selection button used to select the tile. */
	StoryPageElementID GetElementID() { return this->element_id; }

	/** Get the TileIndex of the tile the player selected */
	TileIndex GetTile() { return this->tile_index; }

private:
	ScriptCompany::CompanyID company_id;
	StoryPageID page_id;
	StoryPageElementID element_id;
	TileIndex tile_index;
};

/**
 * Event StoryPageTileSelect, indicating a player clicked a tile selection button on a storybook page, and selected a tile.
 * @api game
 */
class ScriptEventStoryPageVehicleSelect : public ScriptEvent {
public:
	/**
	 * @param company_id  Which company triggered the event.
	 * @param page_id     Which page is the used selection button on.
	 * @param element_id  Which button element was used to select the tile.
	 * @param vehicle_id  Which vehicle was selected by the player.
	 */
	ScriptEventStoryPageVehicleSelect(CompanyID company_id, StoryPageID page_id, StoryPageElementID element_id, VehicleID vehicle_id) :
		ScriptEvent(ET_STORYPAGE_VEHICLE_SELECT),
		company_id((ScriptCompany::CompanyID)company_id),
		page_id(page_id),
		element_id(element_id),
		vehicle_id(vehicle_id)
	{ }

	/**
	 * Convert an ScriptEvent to the real instance.
	 * @param instance The instance to convert.
	 * @return The converted instance.
	 */
	static ScriptEventStoryPageVehicleSelect *Convert(ScriptEvent *instance) { return (ScriptEventStoryPageVehicleSelect *)instance; }

	/** Get the CompanyID of the player that selected a tile. */
	ScriptCompany::CompanyID GetCompanyID() { return this->company_id; }

	/** Get the StoryPageID of the storybook page the used selection button is located on. */
	StoryPageID GetStoryPageID() { return this->page_id; }

	/** Get the StoryPageElementID of the selection button used to select the vehicle. */
	StoryPageElementID GetElementID() { return this->element_id; }

	/** Get the VehicleID of the vehicle the player selected */
	VehicleID GetVehicleID() { return this->vehicle_id; }

private:
	ScriptCompany::CompanyID company_id;
	StoryPageID page_id;
	StoryPageElementID element_id;
	VehicleID vehicle_id;
};

#endif /* SCRIPT_EVENT_TYPES_HPP */