-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuilding_plan.as
More file actions
1947 lines (1711 loc) · 63.1 KB
/
building_plan.as
File metadata and controls
1947 lines (1711 loc) · 63.1 KB
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
#include "utils"
float EPSILON = 0.03125f;
int BUILD_MATERIAL = I_WOOD; // material needed to build stuff
float ARMOR_VALUE = 10;
class BuildPartInfo
{
int type;
string copy_ent;
string title;
int cost; // material needed to build
BuildPartInfo() {
type = -1;
}
BuildPartInfo(int t, string tit, string copy, int matCost) {
type = t;
copy_ent = copy;
title = tit;
cost = matCost;
}
}
class Item
{
int type;
int stackSize;
bool isWeapon;
bool isAmmo;
string title;
string desc;
string classname;
string ammoName;
array<RawItem> costs;
Item() {
type = -1;
stackSize = 1;
}
Item(int t, int stackSz, bool wep, bool ammo, string cname, string ammoName, string tit, RawItem@ cost1,
RawItem@ cost2, string description="") {
type = t;
stackSize = stackSz;
title = tit;
desc = description;
isWeapon = wep;
isAmmo = ammo;
classname = cname;
this.ammoName = ammoName;
if (cost1 !is null)
costs.insertLast(cost1);
if (cost2 !is null)
costs.insertLast(cost2);
}
string getCostText()
{
if (costs.size() == 0)
return "";
string ret = " (";
for (uint i = 0; i < costs.size(); i++)
{
ret += "" + costs[i].amt + " " + g_items[costs[i].type].title;
if (i != costs.size()-1)
ret += " + ";
}
ret += ")";
return ret;
}
string getCraftText(CBasePlayer@ plr)
{
if (g_free_build)
return translate(plr, title);
string cost = getCostText();
// The menu font isn't monospace, so we can only try to get items aligned...
// It looks different on every resolution, but it's still better than using multiple lines imo
string tabs;
switch(type)
{
case I_WOOD_DOOR: tabs = " "; break;
case I_WOOD_SHUTTERS: tabs = " "; break;
case I_WOOD_BARS: tabs = " "; break;
case I_METAL_DOOR: tabs = " "; break;
case I_METAL_BARS: tabs = " "; break;
case I_HIGH_WOOD_WALL: tabs = " "; break;
case I_HIGH_STONE_WALL: tabs = " "; break;
case I_CODE_LOCK: tabs = " "; break;
case I_SMALL_CHEST: tabs = " "; break;
case I_LARGE_CHEST: tabs = " "; break;
case I_FURNACE: tabs = " "; break;
case I_LADDER: tabs = " "; break;
case I_LADDER_HATCH: tabs = " "; break;
case I_TOOL_CUPBOARD: tabs = " "; break;
case I_BED: tabs = " "; break;
case I_ROCK: tabs = " "; break;
case I_BUILDING_PLAN: tabs = " "; break;
case I_HAMMER: tabs = " "; break;
case I_STONE_HATCHET: tabs = " "; break;
case I_STONE_PICKAXE: tabs = " "; break;
case I_METAL_HATCHET: tabs = " "; break;
case I_METAL_PICKAXE: tabs = " "; break;
case I_SYRINGE: tabs = " "; break;
case I_ARMOR: tabs = " "; break;
case I_GUITAR: tabs = " "; break;
case I_BOAT_WOOD: tabs = " "; break;
case I_BOAT_METAL: tabs = " "; break;
case I_CROWBAR: tabs = " "; break;
case I_BOW: tabs = " "; break;
case I_DEAGLE: tabs = " "; break;
case I_SHOTGUN: tabs = " "; break;
case I_SNIPER: tabs = " "; break;
case I_UZI: tabs = " "; break;
case I_SAW: tabs = " "; break;
case I_FLAMETHROWER: tabs = " "; break;
case I_RPG: tabs = " "; break;
case I_GRENADE: tabs = " "; break;
case I_SATCHEL: tabs = " "; break;
case I_C4: tabs = " "; break;
case I_ARROW: tabs = " "; break;
case I_9MM: tabs = " "; break;
case I_556: tabs = " "; break;
case I_BUCKSHOT: tabs = " "; break;
case I_ROCKET: tabs = " "; break;
default: tabs = " "; break;
}
return translate(plr, title + tabs + cost);
}
}
enum build_types
{
B_FOUNDATION = 0,
B_FOUNDATION_TRI,
B_WALL,
B_DOORWAY,
B_WINDOW,
B_LOW_WALL,
B_FLOOR,
B_FLOOR_TRI,
B_ROOF,
B_STAIRS,
B_STAIRS_L,
B_FOUNDATION_STEPS,
B_WOOD_DOOR,
B_METAL_DOOR,
B_WOOD_BARS,
B_METAL_BARS,
B_WOOD_SHUTTERS,
B_CODE_LOCK,
B_TOOL_CUPBOARD,
B_HIGH_WOOD_WALL,
B_HIGH_STONE_WALL,
B_LADDER,
B_LADDER_HATCH,
B_SMALL_CHEST,
B_LARGE_CHEST,
B_FURNACE,
B_BED,
B_FIRE,
E_BOAT_WOOD,
E_BOAT_METAL,
B_ITEM_TYPES,
E_SUPPLY_CRATE,
};
int B_TYPES = B_FOUNDATION_STEPS+1;
// What to update when adding a new buildable item:
// building_plan.as -> build_types + item_types + g_part_info + g_items + getCraftText
// rust.as -> part_names
// utils.as -> isFloorItem
// items.as -> openPlayerMenu (if craftable)
enum item_types
{
I_WOOD_DOOR = 0,
I_METAL_DOOR,
I_WOOD_BARS,
I_METAL_BARS,
I_WOOD_SHUTTERS,
I_CODE_LOCK,
I_TOOL_CUPBOARD,
I_HIGH_WOOD_WALL,
I_HIGH_STONE_WALL,
I_LADDER,
I_LADDER_HATCH,
I_SMALL_CHEST,
I_LARGE_CHEST,
I_FURNACE,
I_BED,
I_FIRE,
I_BOAT_WOOD,
I_BOAT_METAL,
I_HAMMER,
I_BUILDING_PLAN,
I_ROCK,
I_STONE_HATCHET,
I_STONE_PICKAXE,
I_METAL_HATCHET,
I_METAL_PICKAXE,
I_CROWBAR,
I_BOW,
I_SYRINGE,
I_ARMOR,
I_FLAMETHROWER,
I_RPG,
I_GRENADE,
I_SATCHEL,
I_C4,
I_DEAGLE,
I_SHOTGUN,
I_SNIPER,
I_UZI,
I_SAW,
I_GUITAR,
I_ARROW,
I_FUEL,
I_556,
I_9MM,
I_BUCKSHOT,
I_ROCKET,
I_WOOD,
I_STONE,
I_METAL,
I_HQMETAL,
I_METAL_ORE,
I_HQMETAL_ORE,
I_SCRAP,
ITEM_TYPES,
};
enum socket_types
{
SOCKET_FOUNDATION = 0,
SOCKET_MIDDLE,
SOCKET_WALL,
SOCKET_DOORWAY,
SOCKET_DOOR,
SOCKET_WINDOW,
SOCKET_HIGH_WALL,
};
enum builder_status
{
STATUS_RAIDER = 0,
STATUS_SETTLER,
STATUS_OUTSKIRTS,
}
array<BuildPartInfo> g_part_info = {
BuildPartInfo(B_FOUNDATION, "{b_foundation}", "b_foundation", 50),
BuildPartInfo(B_FOUNDATION_TRI, "{b_foundation_tri}", "b_foundation_tri", 25),
BuildPartInfo(B_WALL, "{b_wall}", "b_wall", 50),
BuildPartInfo(B_DOORWAY, "{b_doorway}", "b_doorway", 35),
BuildPartInfo(B_WINDOW, "{b_window}", "b_window", 35),
BuildPartInfo(B_LOW_WALL, "{b_low_wall}", "b_low_wall", 25),
BuildPartInfo(B_FLOOR, "{b_floor}", "b_floor", 25),
BuildPartInfo(B_FLOOR_TRI, "{b_floor_tri}", "b_floor_tri", 15),
BuildPartInfo(B_ROOF, "{b_roof}", "b_roof", 50),
BuildPartInfo(B_STAIRS, "{b_stairs}", "b_stairs", 50),
BuildPartInfo(B_STAIRS_L, "{b_stairs_l}", "b_stairs_l", 50),
BuildPartInfo(B_FOUNDATION_STEPS, "{b_foundation_steps}", "b_foundation_steps", 25),
BuildPartInfo(B_WOOD_DOOR, "{b_wood_door}", "b_wood_door", 0),
BuildPartInfo(B_METAL_DOOR, "{b_metal_door}", "b_metal_door", 0),
BuildPartInfo(B_WOOD_BARS, "{b_wood_bars}", "b_wood_bars", 0),
BuildPartInfo(B_METAL_BARS, "{b_metal_bars}", "b_metal_bars", 0),
BuildPartInfo(B_WOOD_SHUTTERS, "{b_wood_shutters}", "b_wood_shutters", 0),
BuildPartInfo(B_CODE_LOCK, "{b_code_lock}", "b_code_lock", 0),
BuildPartInfo(B_TOOL_CUPBOARD, "{b_tool_cupboard}", "b_tool_cupboard", 0),
BuildPartInfo(B_HIGH_WOOD_WALL, "{b_high_wood_wall}", "b_high_wood_wall", 0),
BuildPartInfo(B_HIGH_STONE_WALL, "{b_high_stone_wall}", "b_high_stone_wall", 0),
BuildPartInfo(B_LADDER, "{b_ladder}", "b_ladder", 0),
BuildPartInfo(B_LADDER_HATCH, "{b_ladder_hatch}", "b_ladder_hatch", 0),
BuildPartInfo(B_SMALL_CHEST, "{b_small_chest}", "b_small_chest", 0),
BuildPartInfo(B_LARGE_CHEST, "{b_large_chest}", "b_large_chest", 0),
BuildPartInfo(B_FURNACE, "{b_furnace}", "b_furnace", 0),
BuildPartInfo(B_BED, "{b_bed}", "b_bed", 0),
BuildPartInfo(B_FIRE, "{b_fire}", "b_fire", 0),
BuildPartInfo(E_BOAT_WOOD, "{e_boat_wood}", "e_boat_wood", 0),
BuildPartInfo(E_BOAT_METAL, "{e_boat_metal}", "e_boat_metal", 0),
BuildPartInfo(E_SUPPLY_CRATE, "{e_supply_crate}", "e_supply_crate", 0),
};
array<Item> g_items = {
Item(I_WOOD_DOOR, 1, false, false, "b_wood_door", "", "{b_wood_door}", RawItem(I_WOOD, 200), null, "{d_wood_door}"),
Item(I_METAL_DOOR, 1, false, false, "b_metal_door", "", "{b_metal_door}", RawItem(I_WOOD, 200), RawItem(I_METAL, 150), "{d_metal_door}"),
Item(I_WOOD_BARS, 1, false, false, "b_wood_bars", "", "{b_wood_bars}", RawItem(I_WOOD, 50), null, "{d_wood_bars}"),
Item(I_METAL_BARS, 1, false, false, "b_metal_bars", "", "{b_metal_bars}", RawItem(I_METAL, 25), null, "{d_metal_bars}"),
Item(I_WOOD_SHUTTERS, 1, false, false, "b_wood_shutters", "", "{b_wood_shutters}", RawItem(I_WOOD, 100), null, "{d_wood_shutters}"),
Item(I_CODE_LOCK, 1, false, false, "b_code_lock", "", "{b_code_lock}", RawItem(I_METAL, 100), null, "{d_code_lock}"),
Item(I_TOOL_CUPBOARD, 1, false, false, "b_tool_cupboard", "", "{b_tool_cupboard}", RawItem(I_WOOD, 1000), null, "{d_tool_cupboard}"),
Item(I_HIGH_WOOD_WALL, 1, false, false, "b_high_wood_wall", "", "{b_high_wood_wall}", RawItem(I_WOOD, 1500), null, "{d_high_wood_wall}"),
Item(I_HIGH_STONE_WALL, 1, false, false, "b_high_stone_wall", "", "{b_high_stone_wall}", RawItem(I_STONE, 1500), null, "{d_high_stone_wall}"),
Item(I_LADDER, 1, false, false, "b_ladder", "", "{b_ladder}", RawItem(I_WOOD, 300), RawItem(I_SCRAP, 10), "{d_ladder}"),
Item(I_LADDER_HATCH, 1, false, false, "b_ladder_hatch", "", "{b_ladder_hatch}", RawItem(I_METAL, 300), RawItem(I_SCRAP, 15), "{d_ladder_hatch}"),
Item(I_SMALL_CHEST, 1, false, false, "b_small_chest", "", "{b_small_chest}", RawItem(I_WOOD, 100), null, "{d_small_chest}"),
Item(I_LARGE_CHEST, 1, false, false, "b_large_chest", "", "{b_large_chest}", RawItem(I_WOOD, 250), RawItem(I_METAL, 50), "{d_large_chest}"),
Item(I_FURNACE, 1, false, false, "b_furnace", "", "{b_furnace}", RawItem(I_STONE, 300), RawItem(I_FUEL, 50), "{d_furnace}"),
Item(I_BED, 1, false, false, "b_bed", "", "{b_bed}", RawItem(I_WOOD, 100), null, "{d_bed}"),
Item(I_FIRE, 1, false, false, "b_fire", "", "{b_fire}", RawItem(I_WOOD, 100), null, "{d_fire}"),
Item(I_BOAT_WOOD, 1, false, false, "e_boat_wood", "", "{e_boat_wood}", RawItem(I_WOOD, 200), null, "{d_boat_wood}"),
Item(I_BOAT_METAL, 1, false, false, "e_boat_metal", "", "{e_boat_metal}", RawItem(I_METAL, 100), RawItem(I_SCRAP, 2), "{d_boat_metal}"),
Item(I_HAMMER, 1, true, false, "weapon_hammer", "", "{i_hammer}", RawItem(I_WOOD, 100), null, "{d_hammer}"),
Item(I_BUILDING_PLAN, 1, true, false, "weapon_building_plan", "", "{i_building_plan}", RawItem(I_WOOD, 10), null, "{d_building_plan}"),
Item(I_ROCK, 1, true, false, "weapon_rock", "", "{i_rock}", RawItem(I_STONE, 10), null, "{d_rock}"),
Item(I_STONE_HATCHET, 1, true, false, "weapon_stone_hatchet", "", "{i_stone_hatchet}", RawItem(I_WOOD, 200), RawItem(I_STONE, 100), "{d_stone_hatchet}"),
Item(I_STONE_PICKAXE, 1, true, false, "weapon_stone_pickaxe", "", "{i_stone_pickaxe}", RawItem(I_WOOD, 200), RawItem(I_STONE, 100), "{d_stone_pickaxe}"),
Item(I_METAL_HATCHET, 1, true, false, "weapon_metal_hatchet", "", "{i_metal_hatchet}", RawItem(I_WOOD, 100), RawItem(I_METAL, 75), "{d_metal_hatchet}"),
Item(I_METAL_PICKAXE, 1, true, false, "weapon_metal_pickaxe", "", "{i_metal_pickaxe}", RawItem(I_WOOD, 100), RawItem(I_METAL, 125), "{d_metal_pickaxe}"),
Item(I_CROWBAR, 1, true, false, "weapon_custom_crowbar", "", "{i_crowbar}", RawItem(I_METAL, 50), null, "{d_crowbar}"),
Item(I_BOW, 1, true, false, "weapon_bow", "", "{i_bow}", RawItem(I_WOOD, 200), null, "{d_bow}"),
Item(I_SYRINGE, 100, true, false, "weapon_syringe", "health", "{i_syringe}", RawItem(I_FUEL, 10), RawItem(I_SCRAP, 1), "{d_syringe}"),
Item(I_ARMOR, 10, false, false, "item_battery", "", "{i_armor}", RawItem(I_HQMETAL, 10), RawItem(I_SCRAP, 5), "{d_armor}"),
Item(I_FLAMETHROWER, 1, true, false, "weapon_flamethrower", "", "{i_flamethrower}", RawItem(I_HQMETAL, 20), RawItem(I_SCRAP, 20), "{d_flamethrower}"),
Item(I_RPG, 1, true, false, "weapon_custom_rpg", "", "{i_rpg}", RawItem(I_HQMETAL, 80), RawItem(I_SCRAP, 10), "{d_rpg}"),
Item(I_GRENADE, 10, true, false, "weapon_custom_grenade", "hand grenade", "{i_grenade}", RawItem(I_METAL, 100), null, "{d_grenade}"),
Item(I_SATCHEL, 10, true, false, "weapon_satchel_charge", "satchel", "{i_satchel}", RawItem(I_METAL, 50), RawItem(I_SCRAP, 5), "{d_satchel}"),
Item(I_C4, 10, true, false, "weapon_custom_c4", "c4", "{i_c4}", RawItem(I_METAL, 200), RawItem(I_SCRAP, 20), "{d_c4}"),
Item(I_DEAGLE, 1, true, false, "weapon_custom_deagle", "", "{i_deagle}", RawItem(I_HQMETAL, 10), RawItem(I_SCRAP, 5), "{d_deagle}"),
Item(I_SHOTGUN, 1, true, false, "weapon_custom_shotgun", "", "{i_shotgun}", RawItem(I_HQMETAL, 20), RawItem(I_SCRAP, 10), "{d_shotgun}"),
Item(I_SNIPER, 1, true, false, "weapon_custom_sniper", "", "{i_sniper}", RawItem(I_HQMETAL, 50), RawItem(I_SCRAP, 15), "{d_sniper}"),
Item(I_UZI, 1, true, false, "weapon_custom_uzi", "", "{i_uzi}", RawItem(I_HQMETAL, 25), RawItem(I_SCRAP, 5), "{d_uzi}"),
Item(I_SAW, 1, true, false, "weapon_custom_saw", "", "{i_saw}", RawItem(I_HQMETAL, 60), RawItem(I_SCRAP, 15), "{d_saw}"),
Item(I_GUITAR, 1, true, false, "weapon_guitar", "", "{i_guitar}", RawItem(I_WOOD, 100), RawItem(I_SCRAP, 2), "{d_guitar}"),
Item(I_ARROW, 50, false, true, "arrows", "", "{i_arrow}", RawItem(I_WOOD, 50), null, "{d_arrow}"),
Item(I_FUEL, 500, false, true, "fuel", "", "{i_fuel}", null, null, "{d_fuel}"),
Item(I_556, 100, false, true, "556", "", "{i_556}", RawItem(I_METAL, 10), RawItem(I_HQMETAL, 5), "{d_556}"),
Item(I_9MM, 100, false, true, "9mm", "", "{i_9mm}", RawItem(I_METAL, 10), RawItem(I_HQMETAL, 5), "{d_9mm}"),
Item(I_BUCKSHOT, 50, false, true, "buckshot", "", "{i_buckshot}", RawItem(I_METAL, 10), RawItem(I_HQMETAL, 5), "{d_buckshot}"),
Item(I_ROCKET, 5, false, true, "rockets", "", "{i_rocket}", RawItem(I_HQMETAL, 20), RawItem(I_SCRAP, 5), "{d_rocket}"),
Item(I_WOOD, 1000, false, false, "", "", "{i_wood}", null, null, "{d_wood}"),
Item(I_STONE, 1000, false, false, "", "", "{i_stone}", null, null, "{d_stone}"),
Item(I_METAL, 1000, false, false, "", "", "{i_metal}", null, null, "{d_metal}"),
Item(I_HQMETAL, 100, false, false, "", "", "{i_hq_metal}", null, null, "{d_hq_metal}"),
Item(I_METAL_ORE, 1000, false, false, "", "", "{i_metal_ore}", null, null, "{d_metal_ore}"),
Item(I_HQMETAL_ORE, 100, false, false, "", "", "{i_hq_metal_ore}", null, null, "{d_hq_metal_ore}"),
Item(I_SCRAP, 100, false, false, "", "", "{i_scrap}", null, null, "{d_scrap}"),
};
class weapon_building_plan : ScriptBasePlayerWeaponEntity
{
float m_flNextAnimTime;
bool canShootAgain = false;
EHandle h_buildEnt = null;
EHandle h_buildEnt2 = null;
EHandle h_attachEnt = null;
bool active = false;
bool validBuild = false;
bool forbidden = false;
int buildType = B_FOUNDATION;
float nextCycle = 0;
float nextAlternate = 0;
float lastHudUpdate = 0;
int nextSnd = 0;
int zoneid = -1;
bool alternateBuild = false;
Vector lastLookOri;
void Spawn()
{
Precache();
g_EntityFuncs.SetModel( self, "models/rust/w_blueprint.mdl" );
//self.m_iDefaultAmmo = 0;
//self.m_iClip = self.m_iDefaultAmmo;
self.FallInit();
SetThink( ThinkFunction( WeaponThink ) );
}
void Precache()
{
self.PrecacheCustomModels();
PrecacheModel( "models/rust/w_blueprint.mdl" );
PrecacheModel( "models/rust/p_blueprint.mdl" );
PrecacheModel( "models/rust/v_blueprint.mdl" );
PrecacheSound("rust/build1.ogg");
PrecacheSound("rust/build2.ogg");
}
bool GetItemInfo( ItemInfo& out info )
{
info.iMaxAmmo1 = 20;
info.iMaxAmmo2 = -1;
info.iMaxClip = 0;
info.iSlot = 6;
info.iPosition = 9;
info.iFlags = 6;
info.iWeight = 5;
return true;
}
bool AddToPlayer( CBasePlayer@ pPlayer )
{
if( BaseClass.AddToPlayer( pPlayer ) == true and pPlayer !is null )
{
NetworkMessage message( MSG_ONE, NetworkMessages::WeapPickup, pPlayer.edict() );
message.WriteLong( self.m_iId );
message.End();
return true;
}
return false;
}
bool Deploy()
{
bool bResult = self.DefaultDeploy( self.GetV_Model( "models/rust/v_blueprint.mdl" ),
self.GetP_Model( "models/rust/p_blueprint.mdl" ), 0, "trip" );
createBuildEnts();
updateBuildPlaceholder(true);
active = true;
return true;
}
void createBuildEnts()
{
CBaseEntity@ buildEnt = h_buildEnt;
CBaseEntity@ buildEnt2 = h_buildEnt2;
if (h_buildEnt) {
g_EntityFuncs.Remove(h_buildEnt);
h_buildEnt = null;
}
if (h_buildEnt2) {
g_EntityFuncs.Remove(h_buildEnt2);
h_buildEnt2 = null;
}
TraceResult look = TraceLook(getPlayer(), 280);
string suffix = alternateBuild ? "" : "_twig";
dictionary keys;
keys["origin"] = (look.vecEndPos + Vector(0,0,16)).ToString();
keys["model"] = getModelFromName(g_part_info[buildType].copy_ent + suffix);
keys["rendermode"] = "1";
keys["renderamt"] = "128";
keys["rendercolor"] = "0 255 255";
keys["colormap"] = "" + buildType;
@buildEnt = g_EntityFuncs.CreateEntity("func_illusionary", keys, true);
keys["rendermode"] = "2";
@buildEnt2 = g_EntityFuncs.CreateEntity("func_illusionary", keys, true);
buildEnt2.pev.scale = 0.5f;
buildEnt.pev.movetype = MOVETYPE_NONE;
buildEnt.pev.solid = SOLID_TRIGGER;
//g_EntityFuncs.SetOrigin(buildEnt, buildEnt.pev.origin);
h_buildEnt = buildEnt;
h_buildEnt2 = buildEnt2;
// increment force_retouch
//g_EntityFuncs.FireTargets("push", null, null, USE_TOGGLE);
string cost = "\n\n(" + g_part_info[buildType].cost + " " + g_items[BUILD_MATERIAL].title + ")";
if (buildType >= B_WOOD_DOOR or g_free_build)
cost = "";
PrintKeyBindingString(getPlayer(), g_part_info[buildType].title + cost);
}
void Holster(int iSkipLocal = 0)
{
active = false;
if (h_buildEnt) {
g_EntityFuncs.Remove(h_buildEnt);
h_buildEnt = null;
}
if (h_buildEnt2) {
g_EntityFuncs.Remove(h_buildEnt2);
h_buildEnt2 = null;
}
}
float WeaponTimeBase()
{
return g_Engine.time; //g_WeaponFuncs.WeaponTimeBase();
}
void updateBuildPlaceholder(bool force_update=false)
{
CBasePlayer@ plr = getPlayer();
CBaseEntity@ buildEnt = h_buildEnt;
CBaseEntity@ buildEnt2 = h_buildEnt2;
// show building placeholder
if (buildEnt is null)
return;
float buildDist = 160.0f;
if (buildType >= B_WOOD_DOOR and buildType != B_HIGH_STONE_WALL and buildType != B_HIGH_WOOD_WALL
and buildType != B_LADDER_HATCH)
buildDist = 96.0f;
if (isFloorItem(buildEnt) or buildType == B_FIRE)
buildDist = 128.0f;
bool buildingBoat = buildType == E_BOAT_WOOD or buildType == E_BOAT_METAL;
if (buildingBoat)
buildDist = 192.0f;
float maxSnapDist = buildDist + 32.0f;
TraceResult tr = TraceLook(plr, buildDist);
Vector newOri = tr.vecEndPos;
if (!force_update and (newOri - lastLookOri).Length() < EPSILON)
return;
lastLookOri = newOri;
h_attachEnt = null;
CBaseEntity@ attachEnt = h_attachEnt;
float newYaw = plr.pev.angles.y;
float newPitch = buildEnt.pev.angles.x;
float newRot = buildEnt.pev.angles.z;
CBaseEntity@ phit = g_EntityFuncs.Instance( tr.pHit );
if (buildingBoat)
newYaw -= 90;
int partSocket = socketType(buildType);
bool attaching = false;
CBaseEntity@ skipCollide = null;
validBuild = false;
if (buildingBoat)
{
if (g_EngineFuncs.PointContents(tr.vecEndPos) == CONTENTS_WATER)
{
newOri.z = g_Utility.WaterLevel(tr.vecEndPos, tr.vecEndPos.z, tr.vecEndPos.z + 8192) - 12;
validBuild = true;
}
}
else if (partSocket == SOCKET_HIGH_WALL)
{
if (phit.pev.classname == "worldspawn" and tr.flFraction < 1.0f) {
validBuild = true;
}
g_EngineFuncs.MakeVectors(buildEnt.pev.angles);
Vector left = tr.vecEndPos - g_Engine.v_right*128;
Vector right = tr.vecEndPos + g_Engine.v_right*128;
CBaseEntity@ part = null;
do {
@part = g_EntityFuncs.FindEntityInSphere(part, tr.vecEndPos, 768.0f, "func_breakable_custom", "classname");
if (part !is null)
{
if (part is null or socketType(part.pev.colormap) != SOCKET_HIGH_WALL)
continue;
if ((part.pev.origin - buildEnt.pev.origin + Vector(0,0,120)).Length() > 500)
continue;
float attachDist = 64;
g_EngineFuncs.MakeVectors(part.pev.angles);
Vector attachLeft = part.pev.origin + g_Engine.v_right*-128 + Vector(0,0,-120);
Vector attachRight = part.pev.origin + g_Engine.v_right*128 + Vector(0,0,-120);
float ll = (attachLeft - left).Length();
float lr = (attachLeft - right).Length();
float rr = (attachRight - right).Length();
float rl = (attachRight - left).Length();
if (ll > attachDist and lr > attachDist and rr > attachDist and rl > attachDist)
continue;
if (attaching)
{
// can attach to two walls (bridging a gap)
// just disable collision and let the player align it right
// (but only if it's close enough to the end)
@skipCollide = @part;
break;
}
bool sameDir = false;
if (ll < lr and ll < rr and ll < rl)
{
newOri = newOri + (attachLeft - left);
attaching = true;
}
else if (lr < ll and lr < rr and lr < rl)
{
newOri = newOri + (attachLeft - right);
attaching = true;
sameDir = true;
}
else if (rr < ll and rr < lr and rr < rl)
{
newOri = newOri + (attachRight - right);
attaching = true;
}
else if (rl < ll and rl < lr and rl < rr)
{
newOri = newOri + (attachRight - left);
attaching = true;
sameDir = true;
}
if (attaching)
{
float dot = DotProduct((attachLeft - attachRight).Normalize(), (left - right).Normalize());
if (!sameDir)
dot = -dot;
if (dot > -0.55f)
{
TraceResult tr2;
g_Utility.TraceLine( newOri, newOri + Vector(0,0,-16), dont_ignore_monsters, null, tr2 );
CBaseEntity@ phit2 = g_EntityFuncs.Instance( tr2.pHit );
validBuild = tr2.flFraction < 1.0f and phit2 !is null and phit2.pev.classname == "worldspawn";
@phit = @part;
}
else
{
validBuild = false;
}
}
}
} while (part !is null);
newOri.z += 120;
}
else if (partSocket == SOCKET_FOUNDATION or partSocket == SOCKET_WALL or buildType == B_FLOOR or
buildType == B_LADDER_HATCH or buildType == B_ROOF or partSocket == SOCKET_MIDDLE or
partSocket == SOCKET_DOORWAY or partSocket == SOCKET_WINDOW or buildType == B_FLOOR_TRI)
{
g_EngineFuncs.MakeVectors(buildEnt.pev.angles);
float bestDist = 9000;
CBaseEntity@ part = null;
do {
@part = g_EntityFuncs.FindEntityInSphere(part, tr.vecEndPos, 256.0f, "func_breakable_custom", "classname");
if (part !is null)
{
int attachType = part.pev.colormap;
int attachSocket = socketType(part.pev.colormap);
if (partSocket == SOCKET_FOUNDATION and (part.pev.colormap != B_FOUNDATION and part.pev.colormap != B_FOUNDATION_TRI))
continue;
if ((partSocket == SOCKET_WALL or buildType == B_FLOOR or buildType == B_LADDER_HATCH or buildType == B_FLOOR_TRI)
and !isFloorPiece(part) and attachSocket != SOCKET_WALL)
continue;
if (buildType == B_ROOF and attachSocket != SOCKET_WALL)
continue;
if (partSocket == SOCKET_MIDDLE and !isFloorPiece(part))
continue;
if (partSocket == SOCKET_DOORWAY and attachType != B_DOORWAY)
continue;
if (partSocket == SOCKET_WINDOW and attachType != B_WINDOW)
continue;
if (part.pev.colormap == B_LADDER_HATCH and part.pev.targetname != "") // don't attach to door
continue;
float attachDist = 96;
if (partSocket == SOCKET_DOORWAY or partSocket == SOCKET_WINDOW)
attachDist = 200;
g_EngineFuncs.MakeVectors(part.pev.angles);
Vector attachOri = tr.vecEndPos;
float attachYaw = part.pev.angles.y;
float minDist = 0;
if (isFloorPiece(part) and partSocket != SOCKET_MIDDLE and
!((buildType == B_FLOOR or buildType == B_LADDER_HATCH or buildType == B_FLOOR_TRI) and
isFoundation(part)))
{
if (isTriangular(part))
{
// Tri mathematical properties:
// Height = 110.851
// Center point = 64, 36.95
// edge mid point (relative to origin) = -32, 18.476
// Actual brush properties are different, but using floats instead of ints in the export fucks this up somehow
Vector left = part.pev.origin + g_Engine.v_right*-32 + g_Engine.v_forward*18.476;
Vector right = part.pev.origin + g_Engine.v_right*32 + g_Engine.v_forward*18.476;
Vector back = part.pev.origin + g_Engine.v_forward*-36.95;
float dl = (left - tr.vecEndPos).Length();
float dr = (right - tr.vecEndPos).Length();
float db = (back - tr.vecEndPos).Length();
if (dl > attachDist and dr > attachDist and db > attachDist)
continue;
if (dl > bestDist and dr > bestDist and db > bestDist)
continue;
float oriDist = 73.9;
if (partSocket == SOCKET_WALL)
oriDist = 36.95;
if (buildType == B_FOUNDATION or buildType == B_FOUNDATION_STEPS or buildType == B_FLOOR or buildType == B_LADDER_HATCH)
oriDist = 64 + 36.95;
attachYaw = part.pev.angles.y;
minDist = dl;
if (dl < dr and dl < db)
{
attachOri = part.pev.origin + (left - part.pev.origin).Normalize()*oriDist;
attachYaw = part.pev.angles.y + (buildType == B_FOUNDATION_TRI ? -60 : 60);
minDist = dl;
}
else if (dr < dl and dr < db)
{
attachOri = part.pev.origin + (right - part.pev.origin).Normalize()*oriDist;
attachYaw = part.pev.angles.y + (buildType == B_FOUNDATION_TRI ? 60 : -60);
minDist = dr;
}
else if (db < dl and db < dr)
{
attachOri = part.pev.origin + g_Engine.v_forward*-oriDist;
attachYaw = Math.VecToAngles(part.pev.origin - back).y + 180;
minDist = db;
}
if (buildType == B_FOUNDATION_STEPS) {
attachYaw += 180;
}
}
else
{
Vector left = part.pev.origin + g_Engine.v_right*-64;
Vector right = part.pev.origin + g_Engine.v_right*64;
Vector front = part.pev.origin + g_Engine.v_forward*64;
Vector back = part.pev.origin + g_Engine.v_forward*-64;
float dl = (left - tr.vecEndPos).Length();
float dr = (right - tr.vecEndPos).Length();
float df = (front - tr.vecEndPos).Length();
float db = (back - tr.vecEndPos).Length();
if (dl > attachDist and dr > attachDist and df > attachDist and db > attachDist)
continue;
if (dl > bestDist and dr > bestDist and df > bestDist and db > bestDist)
continue;
float oriDist = 128;
if (partSocket == SOCKET_WALL)
oriDist = 64;
if (isTriangular(buildEnt))
oriDist = 36.95 + 64;
attachYaw = part.pev.angles.y;
minDist = dl;
if (dl < dr and dl < df and dl < db)
{
attachOri = part.pev.origin + g_Engine.v_right*-oriDist;
attachYaw = Math.VecToAngles(part.pev.origin - left).y;
minDist = dl;
}
else if (dr < dl and dr < df and dr < db)
{
attachOri = part.pev.origin + g_Engine.v_right*oriDist;
attachYaw = Math.VecToAngles(part.pev.origin - right).y;
minDist = dr;
}
else if (df < dl and df < dr and df < db)
{
attachOri = part.pev.origin + g_Engine.v_forward*oriDist;
attachYaw = Math.VecToAngles(part.pev.origin - front).y;
minDist = df;
}
else if (db < dl and db < dr and db < df)
{
attachOri = part.pev.origin + g_Engine.v_forward*-oriDist;
attachYaw = Math.VecToAngles(part.pev.origin - back).y;
minDist = db;
}
if (isTriangular(buildEnt)) {
attachYaw += 180;
}
}
}
else if ((attachSocket == SOCKET_WALL and attachType != B_LOW_WALL) and (buildType == B_FLOOR or buildType == B_LADDER_HATCH or buildType == B_FLOOR_TRI))
{
Vector front = part.pev.origin + g_Engine.v_forward*4 + Vector(0,0,128);
Vector back = part.pev.origin + g_Engine.v_forward*-4 + Vector(0,0,128);
float df = (front - tr.vecEndPos).Length();
float db = (back - tr.vecEndPos).Length();
if (df > attachDist and db > attachDist)
continue;
if (df > bestDist and db > bestDist)
continue;
attachYaw = part.pev.angles.y;
float oriDist = buildType == B_FLOOR_TRI ? 36.95 : 64;
minDist = df;
if (df < db)
{
attachOri = part.pev.origin + g_Engine.v_forward*oriDist + Vector(0,0,128);
attachYaw = Math.VecToAngles(part.pev.origin - front).y;
minDist = df;
}
else if (db < df)
{
attachOri = part.pev.origin + g_Engine.v_forward*-oriDist + Vector(0,0,128);
attachYaw = Math.VecToAngles(part.pev.origin - back).y;
minDist = db;
}
if (buildType == B_FLOOR_TRI)
attachYaw += 180;
}
else if (partSocket == SOCKET_DOORWAY and attachType == B_DOORWAY)
{
Vector front = part.pev.origin + g_Engine.v_forward*32 + Vector(0,0,64);
Vector back = part.pev.origin + g_Engine.v_forward*-32 + Vector(0,0,64);
float df = (front - tr.vecEndPos).Length();
float db = (back - tr.vecEndPos).Length();
if (df > attachDist or db > attachDist)
continue;
if (df > bestDist or db > bestDist)
continue;
attachYaw = part.pev.angles.y;
minDist = df;
if (df > db)
{
attachOri = part.pev.origin + g_Engine.v_right*-32 + Vector(0,0,64);
attachYaw = Math.VecToAngles(part.pev.origin - front).y;
minDist = df;
}
else if (db > df)
{
attachOri = part.pev.origin + g_Engine.v_right*32 + Vector(0,0,64);
attachYaw = Math.VecToAngles(part.pev.origin - back).y;
minDist = db;
}
}
else if (partSocket == SOCKET_WINDOW and attachType == B_WINDOW)
{
Vector front = part.pev.origin + g_Engine.v_forward*32 + Vector(0,0,64);
Vector back = part.pev.origin + g_Engine.v_forward*-32 + Vector(0,0,64);
float df = (front - tr.vecEndPos).Length();
float db = (back - tr.vecEndPos).Length();
if (df > attachDist or db > attachDist)
continue;
if (df > bestDist or db > bestDist)
continue;
float oriDist = buildType == B_WOOD_SHUTTERS ? 4 : 0;
attachYaw = part.pev.angles.y;
minDist = df;
if (df > db)
{
attachOri = part.pev.origin + g_Engine.v_forward*-oriDist + Vector(0,0,64);
attachYaw = Math.VecToAngles(part.pev.origin - front).y;
minDist = df;
}
else if (db > df)
{
attachOri = part.pev.origin + g_Engine.v_forward*oriDist + Vector(0,0,64);
attachYaw = Math.VecToAngles(part.pev.origin - back).y;
minDist = db;
}
}
else if (attachSocket == SOCKET_WALL and attachType != B_LOW_WALL and buildType != B_ROOF) // stacking walls
{
Vector up = part.pev.origin + Vector(0,0,128);
float du = (up - tr.vecEndPos).Length();
if (du > attachDist or du > bestDist)
continue;
attachOri = up;
attachYaw = part.pev.angles.y;
minDist = du;
}
else if (attachSocket == SOCKET_WALL and attachType != B_LOW_WALL and buildType == B_ROOF) // roof
{
Vector front = part.pev.origin + g_Engine.v_forward*16 + Vector(0,0,128);
Vector back = part.pev.origin + g_Engine.v_forward*-16 + Vector(0,0,128);
float df = (front - tr.vecEndPos).Length();
float db = (back - tr.vecEndPos).Length();
//attachDist = 112;
if (df > attachDist or db > attachDist)
continue;
if (df > bestDist or db > bestDist)
continue;
attachYaw = part.pev.angles.y;
minDist = df;
if (df < db)
{
attachOri = part.pev.origin + g_Engine.v_forward*64 + Vector(0,0,192);
attachYaw = Math.VecToAngles(part.pev.origin - front).y;
minDist = df;
}
else if (db < df)
{
attachOri = part.pev.origin + g_Engine.v_forward*-64 + Vector(0,0,192);
attachYaw = Math.VecToAngles(part.pev.origin - back).y;
minDist = db;
}
}
else if (partSocket == SOCKET_MIDDLE and attachType == B_FOUNDATION or attachType == B_FLOOR)
{
Vector up = part.pev.origin + Vector(0,0,64);
float du = (up - tr.vecEndPos).Length();
if (du > attachDist or du > bestDist)
continue;
attachOri = up;
minDist = du;
}
else
continue;
if (buildType == B_LADDER_HATCH or partSocket == SOCKET_MIDDLE and isFloorPiece(part))
{
// orient stairs according to where the player is looking
Vector floor_forward = g_Engine.v_forward;
Vector floor_right = g_Engine.v_right;
g_EngineFuncs.MakeVectors(plr.pev.angles);
Vector plr_forward = g_Engine.v_forward;
plr_forward.z = 0;
plr_forward.Normalize();
float fdot = DotProduct(plr_forward, floor_forward);
float rdot = DotProduct(plr_forward, floor_right);
if (buildType == B_LADDER_HATCH and attachSocket == SOCKET_WALL)
{
fdot = -fdot;
rdot = -rdot;
}
if (abs(fdot) > abs(rdot)) {
if (fdot > 0) {
attachYaw += 0;
} else {
attachYaw += 180;
}
} else {
if (rdot > 0) {
attachYaw += 270;
} else {
attachYaw += 90;
}
}
}
if (getPartAtPos(attachOri) !is null)
continue;
if (partSocket == SOCKET_DOORWAY and getPartsByParent(part.pev.weapons).length() > 0)
continue;
if (buildType == B_FOUNDATION_TRI or buildType == B_FLOOR_TRI)
{
CBaseEntity@ ent = getPartAtPos(attachOri, 28);
if (ent !is null and (ent.pev.colormap == B_FOUNDATION or ent.pev.colormap == B_FLOOR))
{
// triangle would be completely inside a square piece
continue;
}
}
if (buildType == B_FOUNDATION or buildType == B_FLOOR)
{
CBaseEntity@ ent = getPartAtPos(attachOri, 28);