This repository has been archived by the owner on Sep 20, 2023. It is now read-only.
/
main.fos
3428 lines (3077 loc) · 122 KB
/
main.fos
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
//
// FOnline: 2238
// Rotators
//
// main.fos
//
#include "_animation.fos"
#include "_basetypes.fos"
#include "_colors.fos"
#include "_macros.fos"
#include "_town.fos"
#include "_vars.fos"
#include "_npc_pids.fos"
#include "_vals.fos"
#include "backend_h.fos"
#include "broadcast_h.fos"
#include "caravans_h.fos"
#include "config_h.fos"
#include "config_file_h.fos"
#include "critter_age_h.fos"
#include "debug_h.fos"
#include "economy_h.fos"
#include "factions_h.fos"
#include "follower_capturing.fos"
#include "follower_common_h.fos"
#include "follower_h.fos"
#include "groups_h.fos"
#include "item_dogtags_h.fos"
#include "item_perks_h.fos"
#include "logging_h.fos"
#include "map_tent_h.fos"
#include "mapdata_h.fos"
#include "messages_h.fos"
#include "minigames_h.fos"
#include "mob_wave_h.fos"
#include "MsgStr.h"
#include "npc_common_h.fos"
#include "npc_planes_h.fos"
#include "npc_schedule_h.fos"
#include "online_stats_h.fos"
#include "recycler_h.fos"
#include "reinforcements_h.fos"
#include "reputations_h.fos"
#include "town_h.fos"
#include "utils_h.fos"
#include "weather_h.fos"
#include "world_common_h.fos"
#include "worldmap_h.fos"
#include "xfire_h.fos"
// Imports
import void DropDrugEffects(Critter& cr) from "drugs";
import bool FindBaseEncounter(array<Critter@>& group, Item@ car, uint x, uint y, uint& encounterDescriptor, bool& waitForAnswer) from "factions_player";
import bool IsArenaCombatant(Critter& cr) from "arena";
import bool IsCarTrunk(Item@ item) from "car";
import bool OnUseExplode(Critter& cr, Item& explode, Critter@ targetCr, Item@ targetItem, Scenery@ targetScen, uint timer) from "explode";
import bool PerkCheck(Critter& cr, uint perk, bool always) from "perks";
import bool ReversableItem(Item& item) from "fix_boy";
import bool ReverseItem(Critter& cr, Item& item) from "fix_boy";
import bool TryRepairItem(Critter& cr, Item& item) from "repair";
import bool UseItemOnCar(Critter& cr, Item& car, Item& item) from "car";
import bool UseProspectMap(Critter& cr, Item& map) from "prospects";
import bool UseSkillOnCar(Critter& cr, Item& car, int skill) from "car";
import bool UseSkillOnLocker(Critter& cr, Item& locker, int skill) from "lockers";
import bool WantedSignSet(Item& wantedSign, string& name, uint cost) from "wanted";
import int GetCarTrunkComplexity(Item@ item) from "car";
import uint GetRandomDeathAnimation() from "cheats";
import void AddCrittersKilled() from "cavelog";
import void AddPlayerDeaths() from "cavelog";
import void ApplyTimeout(array<Item@>& items, array<uint>& itemsCount, array<Item@>& resources, Critter& crafter) from "fix_boy";
import void CheckBountyHunters(Critter& cr, Critter@ killer) from "bounties";
import void CombatAttack(Critter& cr, Critter& target, ProtoItem& weapon, uint8 weaponMode, ProtoItem@ ammo) from "combat";
import void CritterGenerate(Critter& cr) from "parameters";
import void CritterDescription_Set(Critter& player, int& description1, int& description2) from "critter_description";
import void EditRadioSettings(Critter& player, Item& radio) from "radio";
import void FlushInfluenceBuffer(Critter& cr, ITown@ town) from "town";
import uint GMTrack(uint targetId, string@ message) from "cheats";
import void GreetPlayer(Critter@ player, Map@ map) from "map_greet";
import void InitCheats(bool fromGame) from "cheats";
import void InitBrahminPens() from "brahmin_pens";
import void InitBrahminTraders() from "brahmin_traders";
import void InitCars() from "car_seller";
import void InitCaveLog() from "cavelog";
import void InitCaveRandomization() from "cave";
import void InitCompanions() from "companion";
import void InitMercs() from "mercs";
import void InitReverseItem() from "fix_boy";
import void InitRoutes() from "patrolroutes";
import void InitSlaveruns() from "slaverun";
import void InitTowns() from "towns";
import void InitTrains() from "trains";
import void InitBlueprints() from "blueprints";
import void InitPerks() from "perks";
import void InitProduction() from "production";
import void InitShufflingSpawns() from "shuffling_spawner";
import bool IsArenaItem(Item@ item) from "arena";
import void LogAction(Critter& cr, string& s) from "logging_critter";
import void NpcProcessLevel(Critter& cr) from "parameters";
import void PlaySound(Critter& cr, string& soundName) from "media";
import string PrepareSound_Pick(Item& item) from "media";
import void ProcessCrippling() from "crippling";
import void RemoveAuthed(uint id) from "cheats";
import void RemoveWorkbenches(Critter& player) from "workbench";
import void ReplicateCritter(Critter& cr) from "replication";
import void RemoveArenaItems(Critter& cr) from "arena";
import void RemoveOnlinePlayer(Critter& cr) from "utils";
import void SaveBrahminPenData() from "brahmin_pens";
import void SaveEventSpawns() from "cheats";
import void SaveCarPriceData() from "car_seller";
import void SaveCompanionData() from "companion";
import void SetReplicationTime(Critter& cr) from "replication";
import void SetSpectator(Critter& cr, bool on) from "utils";
import void SetStartLocation(Critter& cr) from "replication";
import void SetTimeoutForAll(Map& map, int timeout, int time) from "cheats";
import void UseDrug(Critter& cr, Item& drug) from "drugs";
import void UseDrugOn(Critter& cr, Critter& onCr, Item& drug) from "drugs";
import void WearItem(Critter& cr, Item& item, int wearCount) from "repair";
import void WorldmapInit() from "worldmap";
import void WorldmapUpdatePlayer(Critter@ player) from "worldmap_players";
import void WorldmapRemovePlayer(Critter@ player) from "worldmap_players";
import void TrackLocation(Critter& player) from "globalmap_group";
import bool UseFirstAidOnCritter(Critter& cr, Critter& targetCr, Item@ item) from "skills";
import bool UseDoctorOnCritter(Critter& cr, Critter& targetCr, Item@ item) from "skills";
import void FixDrugs(Critter& cr) from "utils";
import void MakeSleepy(Critter& cr) from "sleepiness";
import void TryMakeSleepy(Critter& cr) from "sleepiness";
import void WMIdleCall(Critter& cr) from "sleepiness";
import void UpdateSleepiness(Critter& cr) from "sleepiness";
import void FreezeSleepiness(Critter& cr) from "sleepiness";
import void CumulateSleepiness(Critter& cr) from "sleepiness";
import void DecumulateSleepiness(Critter& cr) from "sleepiness";
import void TrySetCombatZone(Map& map) from "sleepiness";
import void TrySendCombatZones(Critter& cr) from "sleepiness";
import void MasterSleepiness(Critter& cr) from "sleepiness";
import bool GuardNotLegit(Critter@ cr, Item@ item, bool deleteItem) from "cheats";
import void RemoveNotLegit(Critter@ cr) from "cheats";
dictionary ItemPids;
dictionary VarIds;
dictionary BaseTypes;
dictionary MapData;
array<string> ItemNames;
array<string> VarNames;
//// Get the id of the item using identifiers
// stored in ITEMPID.H file
bool GetItemPid(const string& in identifier, int& out pid)
{
return ItemPids.get(identifier, pid);
}
bool GetVarId(const string& in identifier, int& out id)
{
return VarIds.get(identifier, id);
}
// void GetVarNames(const string& filter
bool GetBaseType(const string& in identifier, int& out id)
{
return BaseTypes.get(identifier, id);
}
bool GetMapData(const string& in identifier, int& out id)
{
return MapData.get(identifier, id);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// Called before world generation.
void init()
{
InitLogs(); // Should be first
InitDebug();
InitializeGame();
InitPerks();
InitBlueprints();
FLog(LOG_WMLOCATIONS, "START");
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// Call on start server.
bool start()
{
// Send info about others critters
// Remember:
// - all this info can be hacked in client;
// - more parameters - more traffic.
SetSendParameter(ST_GENDER, true);
SetSendParameter(ST_AGE, true);
SetSendParameter(ST_FOLLOW_CRIT, true);
SetSendParameter(ST_PLAYER_KARMA, true);
// Armor class, uses Agility and Perks for runtime calc
SetSendParameter(ST_ARMOR_CLASS, true);
SetSendParameter(PE_LIVEWIRE, true);
SetSendParameter(PE_HTH_EVADE, true);
SetSendParameter(PE_HTH_EVADE_II, true);
// SetSendParameter(ST_TURN_BASED_AC,true);
// Agility
SetSendParameter(ST_AGILITY, true);
// Hit points, uses Strenght and Endurance
SetSendParameter(ST_MAX_LIFE, true, "Utils.dll@_AllowParameterIfAwareness");
SetSendParameter(ST_MAX_LIFE_EXT, true, "Utils.dll@_AllowParameterIfAwareness");
SetSendParameter(ST_CURRENT_HP, true, "Utils.dll@_AllowParameterIfAwareness");
SetSendParameter(ST_HEALTH_LEVEL, true);
SetSendParameter(ST_TURN_BASED_AC, true);
// Strenght, uses battle timeout
SetSendParameter(ST_STRENGTH, true, "Utils.dll@_AllowParameterIfAwareness");
// Battle timeout
SetSendParameter(TO_BATTLE, true);
// Endurance
SetSendParameter(ST_ENDURANCE, true, "Utils.dll@_AllowParameterIfAwareness");
// Injures
SetSendParameter(DAMAGE_EYE, true);
SetSendParameter(DAMAGE_RIGHT_ARM, true);
SetSendParameter(DAMAGE_LEFT_ARM, true);
SetSendParameter(DAMAGE_RIGHT_LEG, true);
SetSendParameter(DAMAGE_LEFT_LEG, true);
// Item slots, passed with -
SetSendParameter(-SLOT_HAND1, true, "Utils.dll@_AllowSlotHand1");
SetSendParameter(-SLOT_HAND2, false);
SetSendParameter(-SLOT_ARMOR, true, "Utils.dll@_AllowSlotHand1");
SetSendParameter(-SLOT_HEAD, true);
// Some flags for correct client working
SetSendParameter(MODE_HIDE, true, "cheats@AllowParameterIfModer");
SetSendParameter(MODE_NO_BARTER, true);
SetSendParameter(MODE_NO_LOOT, true);
SetSendParameter(MODE_NO_STEAL, true);
SetSendParameter(MODE_NO_FLATTEN, true);
SetSendParameter(MODE_NO_TALK, true);
SetSendParameter(ST_BODY_TYPE, true, "Utils.dll@_AllowParameterIfAwareness");
// 3d animation layers, from Skin to Backpack
#ifdef PLAYERS_3D
for(uint i = ST_ANIM3D_LAYERS + ANIM3D_LAYER_SKIN;
i <= ST_ANIM3D_LAYERS + ANIM3D_LAYER_BACKPACK; i++)
SetSendParameter(i, true);
#endif
// Npc talk distance
SetSendParameter(ST_TALK_DISTANCE, true);
// Dialog id
SetSendParameter(ST_DIALOG_ID, true);
// To see pid of unarmed attack
SetSendParameter(ST_HANDS_ITEM_AND_MODE, true);
// Scale factor
SetSendParameter(ST_SCALE_FACTOR, true);
SetSendParameter(ST_WALK_TIME, true);
SetSendParameter(ST_RUN_TIME, true);
// faction id, only for team mates
SetSendParameter(ST_TEAM_ID, true, "Utils.dll@_AllowParameterIfEqualNZ");
// Critter description
SetSendParameter(ST_DESCRIPTION1, true, "Utils.dll@_AllowParameterIfAwareness");
SetSendParameter(ST_DESCRIPTION2, true, "Utils.dll@_AllowParameterIfAwareness");
SetSendParameter(KARMA_SLAVER, true);
// Minigames data (team, id, custom data)
SetSendParameter(ST_MINIGAME_DATA, true);
// Look fields in fonline.h 'struct Item::ItemData'
// SortValue Info Indicator PicMapHash PicInvHash AnimWaitBase AStay[2] AShow[2] AHide[2] Flags Rate LightDist Inten Flags LightColor ScriptId TrapValue Count Cost ScriptValues[10] Other 36 bytes
// ITEM_DATA_MASK_CHOSEN ITEM_DATA_MASK_CHOSEN ITEM_DATA_MASK_CHOSEN
int8[] mask0 = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0 };
// ITEM_DATA_MASK_CRITTER ITEM_DATA_MASK_CRITTER ITEM_DATA_MASK_CRITTER
int8[] mask1 = { 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// ITEM_DATA_MASK_CRITTER_EXT ITEM_DATA_MASK_CRITTER_EXT ITEM_DATA_MASK_CRITTER_EXT
int8[] mask2 = { 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0 };
// ITEM_DATA_MASK_CONTAINER ITEM_DATA_MASK_CONTAINER ITEM_DATA_MASK_CONTAINER
int8[] mask3 = { -1, -1, -1, -1, 0, 0, 0, 0, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0 };
// ITEM_DATA_MASK_MAP ITEM_DATA_MASK_MAP ITEM_DATA_MASK_MAP
int8[] mask4 = { -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0 };
SetItemDataMask(ITEM_DATA_MASK_CHOSEN, mask0);
SetItemDataMask(ITEM_DATA_MASK_CRITTER, mask1);
SetItemDataMask(ITEM_DATA_MASK_CRITTER_EXT, mask2);
SetItemDataMask(ITEM_DATA_MASK_CONTAINER, mask3);
SetItemDataMask(ITEM_DATA_MASK_MAP, mask4);
InitDBLogs();
WorldmapInit();
ReadDefines("scripts/ITEMPID.H", ItemPids, ItemNames);
ReadDefines("scripts/_vars.fos", VarIds, VarNames);
ReadDefines("scripts/_basetypes.fos", BaseTypes, null);
ReadDefines("scripts/mapdata_h.fos", MapData, null);
// cheats init
InitCheats(true);
// factions!
InitFactions();
// register big factions
RegisterFaction(FACTION_BOS, "Brotherhood Of Steel", false);
RegisterFaction(FACTION_ENCLAVE, "Enclave", false);
RegisterFaction(FACTION_UNITY, "The Unity", false);
RegisterFaction(FACTION_NCR, "New California Republic", false);
RegisterFaction(FACTION_VAULT_CITY, "Vault City", false);
RegisterFaction(FACTION_RAIDERS, "Raiders", false);
RegisterFaction(FACTION_MORDINOS, "Mordinos", false);
// RegisterFaction(FACTION_GUNRUNNERS, "Gun Runners", false); <- screw it
// and some fixed playerdriven factions
RegisterFaction(FACTION_VAGRANTS, "The Tanker Vagrants", true);
RegisterFaction(FACTION_REDDING_GUTTERSNIPES, "The Redding Guttersnipes", true);
__TimeoutBattle = REAL_SECOND(10); // do not move this to InitializeGame() - __TimeMultiplier is still 0 there!
InitTents();
InitCars();
// Initialize the script for improved economy
InitEconomy();
// radiation tables
// InitRadiationEffects();
// Mercenaries
InitMercs();
//
InitNpcSchedules();
// Patrol routes
InitRoutes();
// Brahmin pens
InitBrahminPens();
// Bramin traders
InitBrahminTraders();
// Towns
InitTowns();
InitCaveRandomization();
InitSlaveruns();
// InitAmmoLog();
InitCaveLog();
InitCompanions();
// Caravans wohoo
InitCaravans(); // Uncomment if you want to have one caravan running Hub-Adytum-Lost Hills
// reputations, alliances
InitGroups();
// scenariooos
// InitScenarios();
InitTrains();
InitAlertMaps();
InitWeather();
InitReverseItem();
InitProduction();
InitShufflingSpawns();
ProcessCrippling();
array<Map@> allMaps;
uint allMapsCount = GetAllMaps(0, allMaps);
uint noGridsMaps = 0;
for(uint m = 0; m < allMapsCount; m++)
{
if(!valid(allMaps[m]) || allMaps[m].IsNotValid) // JIC
continue;
if(_MapHasMode(allMaps[m], MAP_MODE_NO_GRIDS))
{
// in case of changes, remember about editing cheats@ExecMapGrids
allMaps[m].SetEvent(MAP_EVENT_LOOP_3, "cheats@_LockMap");
allMaps[m].SetLoopTime(3, 500);
SetTimeoutForAll(allMaps[m], TO_TRANSFER, REAL_SECOND(2238));
noGridsMaps++;
}
// if()
}
if(noGridsMaps > 0)
Log("Exit grids disabled on " + noGridsMaps + " map" + (noGridsMaps > 1 ? "s" : ""));
StartPersonalDataCleanup();
SetGvar(GVAR_is_first_time, 0);
return true;
}
array<uint> Tents;
void GotoTent(Critter& cr, int p0, int p1, int p2)
{
cr.TransitToMap(Tents[p0], 0);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// Call on world initialization.
// Parameter Min Max
// multiplier 1 99
// year 1700 30000
// month 1 12
// day 1 31
// hour 0 23
// minute 0 59
void get_start_time(uint16& multiplier, uint16& year, uint16& month, uint16& day, uint16& hour, uint16& minute)
{
multiplier = 20;
year = 2238;
month = 1;
day = 9;
hour = 6;
minute = 3;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// Call on finish server.
void finish()
{
FLog(LOG_WMLOCATIONS, "FINISH");
CloseLogs();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// Call every returned value, in milliseconds.
// Return next call in milliseconds or zero to disable loop.
uint lastsecond = 0;
uint last_os_save = 0;
uint last_os_mod = 0;
uint loop()
{
// updates worldmap
// WorldmapUpdate(10000);
uint16 second = 0;
uint16 minute = 0;
uint16 hour = 0;
uint16 a, b, c, d, g;
GetTime(a, b, c, d, hour, minute, second, g);
if((minute == 0 || minute == 30) && second < 20) // a time buffer to make sure that long cycles won't prevent updating
{
for(uint i = 1; i < TOWN_COUNT + 1; i++)
{
ITown@ town = GetTown(i);
town.Update(hour, minute);
}
}
for(uint i = 1; i < TOWN_COUNT + 1; i++)
{
ITown@ town = GetTown(i);
town.UpdateTick();
if(((second % 10) == 0) && lastsecond != second)
{
if(town.GetVersion() == TOWN_VERSION_INFLUENCE)
town.TownCheck();
else
town.AreaCheck();
}
}
UpdateBroadcast();
if(last_os_save == 0)
last_os_save = ELAPSED_TIME;
else if(ELAPSED_TIME > last_os_save + OS_CYCLE_TIME)
{
array<Critter@> players;
uint n = GetAllOnlinePlayers(players);
for(uint i = 0; i < n; i++)
if(players[i].Id % OS_MAX_MOD == last_os_mod)
OnlineStats_TrySave(players[i]);
last_os_save += OS_CYCLE_TIME;
last_os_mod++;
if(last_os_mod == OS_MAX_MOD)
last_os_mod = 0;
}
lastsecond = second;
return 500;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// Call when critter attack another.
void critter_attack(Critter& cr, Critter& target, ProtoItem& weapon, uint8 weaponMode, ProtoItem@ ammo)
{
CombatAttack(cr, target, weapon, weaponMode, ammo);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// Called when a critter is attacked by another.
#define _CanHelp # (npc, who)(_GroupMode(npc) == FACTION_MODE_NPC_ONLY ? _IsTrueNpc(who) : (_GroupMode(npc) == FACTION_MODE_PLAYER_ONLY ? !_IsTrueNpc(who) : true))
#define _AnyGuard # (npc) (_GroupMode(npc) != 0 && _GroupMode(npc) != 4)
// These macros are a nice example of code that can't be inlined function nor can be put in do{}while(false) (because of continue) :)
#define _GenGuardTryHelpCr \
# (npc) if(crHelpers == 0 && !override) \
continue; if(!_CanHelp(npc, cr)) \
continue; crHelpers--; AddAttackPlane(npc, 0, attacker); continue
#define _GenGuardTryHelpAttacker \
# (npc) if(attackerHelpers == 0 && !override) \
continue; if(!_CanHelp(npc, attacker)) \
continue; attackerHelpers--; AddAttackPlane(npc, 0, cr); continue
#define _TryHelpCr \
# (npc) if(!_CanHelp(npc, cr)) \
continue; if(!_IsTrueNpc(cr)) { if(crHelpers == 0 && !override) \
continue; crHelpers--; } AddAttackPlane(npc, 0, attacker); continue
#define _TryHelpAttacker \
# (npc) if(!_CanHelp(npc, attacker)) \
continue; if(!_IsTrueNpc(attacker)) { if(attackerHelpers == 0 && !override) \
continue; attackerHelpers--; } AddAttackPlane(npc, 0, cr); continue
void critter_attacked(Critter& cr, Critter& attacker)
{
if(attacker.Id == cr.Id)
return;
Map@ map = cr.GetMap();
if(IsDueling(attacker) || IsArenaCombatant(attacker))
return;
uint crGroup = _GroupIndex(cr);
uint attackerGroup = _GroupIndex(attacker);
DPlayerLog(attacker, "" + attackerGroup + "vs" + crGroup);
if(crGroup == attackerGroup && _IsTrueNpc(cr) && _IsTrueNpc(attacker))
return;
if(attacker.IsPlayer() && !_GroupHasNoAffiliation(crGroup) && !IsFlaggedAsIllegal(cr))
{
if(IsTown(map))
SubReputation(attacker, crGroup, REP_ATK_PENALTY * MAX(1, _GroupRank(cr)));
else
TryReportOffense(cr, attacker, REP_ATK_PENALTY * MAX(1, _GroupRank(cr)));
}
if(!cr.IsPlayer() && (!_IsTrueNpc(attacker) || (crGroup != attackerGroup)))
AddAttackPlane(cr, 0, attacker);
// In similar fashion to vanilla, but only for general purpose guards (normal guards will react no matter what, unless the helped is player/follower)
uint crHelpers = 10 - attacker.Stat[ST_CHARISMA];
crHelpers = CLAMP(crHelpers, 2, 8);
if(_AnyGuard(cr))
crHelpers += 4;
uint attackerHelpers = 10 - cr.Stat[ST_CHARISMA];
attackerHelpers = CLAMP(attackerHelpers, 2, 4);
if(_AnyGuard(attacker))
attackerHelpers += 4;
// Reinforcements
bool override = GetAlertLevel(map) >= __AlertLevelReact; // map is on high alert, don't use helpers number, everyone fights
// We say again: *Helpers are potential general purpose guards or faction-guards helping player/follower :)
// Put all critters that can see either the target or the attacker in critters
array<Critter@> critters;
uint k = 0;
if(override)
k = map.GetCritters(0, FIND_LIFE_AND_KO | FIND_ONLY_NPC, critters);
else
{
uint n = cr.GetCritters(true, FIND_LIFE_AND_KO | FIND_ONLY_NPC, critters);
uint m = attacker.GetCritters(true, FIND_LIFE_AND_KO | FIND_ONLY_NPC, critters);
m += n;
if(m == 0)
return;
k = m;
if(n != 0 && m != n) // union-find if necessary (usually it is)
{
k = n;
// Remove the doubled ones
m -= 1;
while(k != m)
{
if(critters[k].IsSee(cr))
{
// Swap this guy with the last on the "probably ok" list
Critter@ temp = critters[k];
@critters[k] = critters[m];
@critters[m] = temp;
m--;
}
else
k++;
}
if(!critters[k].IsSee(cr))
k++;
}
}
// Exclude those that are already busy helping, check if a general purpose guard is there and if the attacker should be flagged
// Flagging unflagged attacker when the target is unflagged and there's no extreme reputations combination
for(uint i = 0; i < k; i++)
{
if(!_IsTrueNpc(critters[i]) || critters[i].Id == cr.Id || critters[i].Id == attacker.Id)
{
@critters[i] = null;
continue;
}
if(_CritHasExtMode(critters[i], MODE_EXT_GUARD))
{
uint crRepIndex = _GroupIndex(critters[i]);
if(!_IsTrueNpc(attacker) &&
!IsFlaggedAsIllegal(attacker) &&
!IsFlaggedAsIllegal(cr) &&
(crRepIndex >= REPUTATION_COUNT || (attacker.Reputation[crRepIndex] < __ReputationLoved) ||
(cr.Reputation[crRepIndex] >= __ReputationHated))
)
SetCritterIllegalFlag(attacker, ILLEGAL_FLAG_ATTACKING);
}
NpcPlane@ plane = critters[i].GetCurPlane();
if(valid(plane) && plane.Type == AI_PLANE_ATTACK && plane.Attack_TargId == attacker.Id)
{
if(crHelpers > 0)
crHelpers--;
@critters[i] = null; // Exclude this critter
}
if(valid(plane) && plane.Type == AI_PLANE_ATTACK && plane.Attack_TargId == cr.Id)
{
if(attackerHelpers > 0)
attackerHelpers--;
@critters[i] = null; // Exclude this critter
}
}
int crRep = 0;
int attackerRep = 0;
uint npcGroup = 0;
int crStatus = FACTION_NEUTRAL;
int attackerStatus = FACTION_NEUTRAL;
// Global rule: always help a friend against a non-friend; always attack the enemy if against non-enemy
for(uint i = 0; i < k; i++)
{
if(!valid(critters[i]))
continue; // Skip excluded
npcGroup = _GroupIndex(critters[i]);
if(_CritHasExtMode(critters[i], MODE_EXT_GUARD)) // General purpose guard
{
if(attackerHelpers == 0 && crHelpers == 0 && !override)
continue;
// Logic behind an all-purpose guard:
// Always ignore the attack if critter is flagged as illegal
// Help all npc members if they are attacking
// Help all npc members if they are attacked
// If neither of the above, check if the attacked is liked very much, and the target is not. help the attacker if this is the case.
// Otherwise, check if reputation difference is big enough, ignore the attack then
// If not, then proceed with the default action (help the target)
// Faction members npcs are ok, help them
if((npcGroup == attackerGroup) && _IsTrueNpc(attacker))
{
_GenGuardTryHelpAttacker(critters[i]);
}
// Always help a friend against a non-friend; always attack the enemy if against non-enemy
crStatus = GetGroupsStatus(cr, critters[i]);
attackerStatus = GetGroupsStatus(attacker, critters[i]);
if(crStatus == FACTION_ALLY)
{
if(attackerStatus != FACTION_ALLY)
{
_GenGuardTryHelpCr(critters[i]);
}
else
continue;
}
else if(crStatus == FACTION_NEUTRAL)
{
if(attackerStatus == FACTION_ALLY)
{
_GenGuardTryHelpAttacker(critters[i]);
}
}
else if(crStatus == FACTION_ENEMY)
{
if(attackerStatus != FACTION_ENEMY)
{
_GenGuardTryHelpAttacker(critters[i]);
}
}
// Is the critter illegal? then the attacker is ok
if(IsFlaggedAsIllegal(cr))
continue;
// Help the friendly npc
if((crGroup == npcGroup) && _IsTrueNpc(cr))
{
_GenGuardTryHelpCr(critters[i]);
}
// If the attacker is liked, and the target is not, actually help the attacker
crRep = npcGroup < REPUTATION_COUNT ? cr.Reputation[npcGroup] : 0;
attackerRep = npcGroup < REPUTATION_COUNT ? attacker.Reputation[npcGroup] : 0;
if((attackerRep >= __ReputationLoved) && (crRep < __ReputationHated))
{
_GenGuardTryHelpAttacker(critters[i]);
}
// Be neutral on medium difference
if(attackerRep - crRep > REP_DIFF)
continue;
// Default behaviour
_GenGuardTryHelpCr(critters[i]);
} // General purpose guard
else if(_GroupIndex(critters[i]) > 1 && _GroupMode(critters[i]) > 0 && _GroupMode(critters[i]) < 4) // non-general guard
{
// General rules: target is in our team, npc attacker is in our team: do nothing
// target is in our team, player attacker is in our team: kill the player
// target is in our team, attacker not is in our team: kill the attacker
// target is not in our team, attacker is in our team: kill the critter
// target is not in our team, attacker is not in our team: help the side that has v. high reputation,
// providing that the other side has v. low reputation
// Always help a friend against a non-friend; always attack the enemy if against non-enemy
crStatus = GetGroupsStatus(cr, critters[i]);
attackerStatus = GetGroupsStatus(attacker, critters[i]);
if(crStatus == FACTION_ALLY)
{
if(attackerStatus != FACTION_ALLY)
{
_GenGuardTryHelpCr(critters[i]); // Act like a generic guard in this case
}
}
else if(crStatus == FACTION_NEUTRAL)
{
if(attackerStatus == FACTION_ALLY)
{
_GenGuardTryHelpAttacker(critters[i]); // Act like a generic guard in this case
}
}
else if(crStatus == FACTION_ENEMY)
{
if(attackerStatus != FACTION_ENEMY)
{
_GenGuardTryHelpAttacker(critters[i]); // Act like a generic guard in this case
}
}
if(npcGroup == crGroup)
{
if(npcGroup == attackerGroup)
{
if(_IsTrueNpc(attacker))
continue;
else
{
_TryHelpCr(critters[i]);
}
}
else
{
if(_IsTrueNpc(attacker))
continue;
else
_TryHelpCr(critters[i]);
}
}
else
{
if(npcGroup == attackerGroup)
{
_TryHelpAttacker(critters[i]);
}
else
{
crRep = npcGroup < REPUTATION_COUNT ? cr.Reputation[npcGroup] : 0;
attackerRep = npcGroup < REPUTATION_COUNT ? attacker.Reputation[npcGroup] : 0;
if((attackerRep >= __ReputationLoved) && (crRep < __ReputationHated))
{
_TryHelpAttacker(critters[i]);
}
else if((crRep >= __ReputationLoved) && (attackerRep < __ReputationHated))
{
_TryHelpCr(critters[i]);
}
}
}
} // Non-general purpose guard
else if(_GroupHasNoAffiliation(npcGroup)) // In encounters
{
if(npcGroup == crGroup)
AddAttackPlane(critters[i], 0, attacker);
else if(npcGroup == attackerGroup)
AddAttackPlane(critters[i], 0, cr);
}
} // Main loop
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// Called after the critter gets any damage.
void PostDamage(Critter& cr)
{
if(valid(cr.GetMap()) && cr.GetMap().IsTurnBased())
return;
if(cr.IsPlayer() || !IsHumanoid(cr) || cr.Cond == COND_DEAD)
return;
if(cr.IsInjured())
{
if(cr.Timeout[TO_SK_DOCTOR] <= 0)
{
if(cr.Stat[ST_INTELLECT] >= Random(1, 10))
{
array<NpcPlane@> planes;
cr.GetPlanes(PLANE_DOCTOR_CRITTER, planes);
if(planes.length() > 0)
planes[0].IdentifierExt = cr.Id;
else
AddDoctorCritterPlane(cr, valid(cr.GetCurPlane()) ? cr.GetCurPlane().Priority + 5 : 0, cr, false); // self
}
}
}
if(cr.Stat[ST_CURRENT_HP] != cr.Stat[ST_MAX_LIFE])
{
if(cr.Timeout[TO_SK_FIRST_AID] <= 0 && cr.Timeout[TO_WEAKENED] <= 0)
{
if(cr.Stat[ST_INTELLECT] >= Random(1, 10))
{
if(cr.Stat[ST_CURRENT_HP] <= cr.Stat[ST_MAX_LIFE] / 2 || (cr.Stat[ST_MAX_LIFE] - cr.Stat[ST_CURRENT_HP] > cr.Skill[SK_FIRST_AID]))
{
array<NpcPlane@> planes;
cr.GetPlanes(PLANE_HEAL_CRITTER, planes);
if(planes.length() > 0)
planes[0].IdentifierExt = cr.Id;
else
AddHealCritterPlane(cr, valid(cr.GetCurPlane()) ? cr.GetCurPlane().Priority + 5 : 0, cr, false); // self
}
}
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// Call when a critter steals from another.
bool critter_stealing(Critter& cr, Critter& thief, Item& item, uint count)
{
if(cr.IsDead() || cr.Timeout[TO_BATTLE] > 0 || thief.Timeout[TO_BATTLE] > 0)
{
thief.StatBase[ST_LAST_STEAL_CR_ID] = 0;
thief.StatBase[ST_STEAL_COUNT] = 0;
return false;
}
int dir1 = cr.Dir;
int dir2 = thief.Dir;
int kDir = MAX(dir1, dir2) - MIN(dir1, dir2);
if(kDir > 3)
kDir = 6 - kDir;
int steal = thief.Skill[SK_STEAL];
if(steal <= 0)
steal = 1;
int size = item.Proto.Volume;
if(size <= 0)
size = 1;
// Perk pickpocket, ignore size and facing --> now only halve
bool pickpocket = thief.Perk[PE_PICKPOCKET] != 0;
// Count modifier
int kCount = count / steal;
if(kCount <= 0)
kCount = 1;
// Check time of stealing
uint lastStealCrId = thief.Stat[ST_LAST_STEAL_CR_ID];
uint stealCount = thief.Stat[ST_STEAL_COUNT];
if(lastStealCrId == cr.Id && thief.Timeout[TO_SK_STEAL] > 0)
steal -= steal * stealCount * 10 / 100;
// Calc
int k = (steal - kDir * (pickpocket ? 5 : 10)) / MAX(1, (size * kCount) / (pickpocket ? 2 : 1));
k = CLAMP(k, 5, 95);
if(thief.Timeout[TO_SLEEPY] > 0 && thief.Param[TO_SLEEPY_STOPPED] == -1 && thief.Param[ST_MINIGAME_DATA] == 0)
k = 5;
GameVar@ var = GetUnicumVar(UVAR_proximity_check, cr.Id, thief.Id);
if(var.GetValue() == 1)
k /= 2;
bool success = !(Random(1, 100) > k);
// flag critter if guards spot it
/*if (IsTown(thief.GetMap()) && !IsFlaggedAsIllegal(thief))
thief.SendMessage(MSG_IM_STEALING, cr.Id, MESSAGE_TO_VISIBLE_ME);*/
if(success || cr.Perk[PE_THIEF] != 0 || Random(1, 50) <= cr.Stat[ST_LUCK])
_SetTimeout(thief, TO_SK_STEAL, STEAL_TIMEOUT(thief));
if(success)
{
// Add experience
// const int stealExp[12]={10,30,60,100,150,210,280,360,450,550,660,780};
// const int stealExp[12]={10,20,30,40,50,60,70,80,90,100,110,120};
const int[] stealExp = { 5, 10, 15, 25, 30, 40, 50, 60, 70, 100 };
if(lastStealCrId == cr.Id && thief.Timeout[TO_SK_STEAL] > 0)
{
stealCount++;
if(stealCount > 9)
stealCount = 9;
thief.StatBase[ST_STEAL_COUNT] = stealCount;
}
else
{
thief.StatBase[ST_LAST_STEAL_CR_ID] = cr.Id;
thief.StatBase[ST_STEAL_COUNT] = 0;
}
if(_IsFollower(cr) || IsBase(cr.GetMap()) || IsTent(cr.GetMap()))
return success;
if(cr.IsNpc())
{
thief.StatBase[ST_EXPERIENCE] += stealExp[stealCount];
LogExperience(thief, stealExp[stealCount], SK_STEAL, cr.GetProtoId());
AddScore(thief, SCORE_THIEF, 1);
}
}
else
{
if(IsTown(thief.GetMap()))
SetCritterIllegalFlag(thief, ILLEGAL_FLAG_STEALING);
thief.StatBase[ST_LAST_STEAL_CR_ID] = 0;
thief.StatBase[ST_STEAL_COUNT] = 0;
if(cr.IsNpc())
{
int thiefHp = thief.Stat[ST_CURRENT_HP];
if(!(_IsFollower(cr) && IsTown(thief.GetMap())))
AddAttackPlane(cr, 0, thief, thiefHp < 10 || Random(1, 10) > cr.Stat[ST_LUCK] ? __DeadHitPoints : Random(thiefHp / 4, thiefHp / 2));
uint crGroup = _GroupIndex(cr);
if(_ValidReputationIndex(crGroup))
SubReputation(thief, crGroup, REP_STEAL_PENALTY * MAX(1, _GroupRank(cr)));
}
else
{
cr.Say(SAY_NETMSG, "|4291317840 " + thief.Name + " failed to steal from you.");
cr.RunClientScript("_ActionStealing", thief.Id, 0, 0, null, null); // send action
}
}
return success;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// Call on something critter use item.
bool critter_use_item(Critter& cr, Item& item, Critter@ targetCr, Item@ targetItem, Scenery@ targetScen, uint param)
{
// scenario
bool isPlayer = cr.IsPlayer();
uint16 pid = item.GetProtoId();
bool useOnSelf = (!valid(targetCr) && !valid(targetItem) && !valid(targetScen));
DLog("Using item with pid: " + item.GetProtoId());
// Book reading
// disabled
/*
if(useOnSelf && IsReadableBook(pid))
{
TryReadBook(cr,item);
return true;
}
*/
// Explosion
if(OnUseExplode(cr, item, targetCr, targetItem, targetScen, param))
return true;
// Use item on another item
//
if(valid(targetItem))
{
if(targetItem.GetType() == ITEM_TYPE_CAR && UseItemOnCar(cr, targetItem, item))
{
return true;
}
}
// Drugs
if(item.GetType() == ITEM_TYPE_DRUG)
{
if(item.GetProtoId() == PID_CIGARETTES && !HasItem(cr, PID_LIGHTER))
{
cr.Say(SAY_NETMSG, "You need a lighter to smoke.");
return true;
}
if(useOnSelf)
UseDrug(cr, item);
else if(valid(targetCr))
UseDrugOn(cr, targetCr, item);
else
cr.SayMsg(SAY_NETMSG, TEXTMSG_GAME, STR_USE_NOTHING);
return true;
}
// Tools (FA and doctor now)
if(!valid(targetScen) && !valid(targetItem) && item.GetType() == ITEM_TYPE_MISC)
{