-
Notifications
You must be signed in to change notification settings - Fork 388
Expand file tree
/
Copy pathcatalua_bindings_item.cpp
More file actions
1427 lines (1169 loc) · 50.3 KB
/
catalua_bindings_item.cpp
File metadata and controls
1427 lines (1169 loc) · 50.3 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 "catalua_bindings.h"
#include <ranges>
#include "catalua_bindings_utils.h"
#include "catalua_luna.h"
#include "catalua_luna_doc.h"
#include "artifact.h"
#include "itype.h"
#include "mtype.h"
#include "material.h"
#include "faction.h"
#include "character.h"
#include "martialarts.h"
#include "relic.h"
#include "vitamin.h"
#include "gun_mode.h"
#include "mod_manager.h"
#include "ammo_effect.h"
#include "mongroup.h"
#include "disease.h"
#include "skill.h"
#include "ammo.h"
#include "flag.h"
#include "emit.h"
#include "fault.h"
#include "recipe.h"
#include "explosion.h"
#include "enum_conversions.h"
#include "translations.h"
namespace
{
auto artifact_effect_names( const std::vector<art_effect_passive> &effects
) -> std::vector<std::string>
{
return effects
| std::views::transform( []( const art_effect_passive effect ) {
return io::enum_to_string( effect );
} )
| std::ranges::to<std::vector>();
}
auto artifact_effect_names( const std::vector<art_effect_active> &effects
) -> std::vector<std::string>
{
return effects
| std::views::transform( []( const art_effect_active effect ) {
return io::enum_to_string( effect );
} )
| std::ranges::to<std::vector>();
}
auto artifact_effect_description( const art_effect_passive effect ) -> std::string
{
switch( effect ) {
case AEP_NULL:
return _( "No effect" );
case AEP_STR_UP:
return _( "Strength +4" );
case AEP_DEX_UP:
return _( "Dexterity +4" );
case AEP_PER_UP:
return _( "Perception +4" );
case AEP_INT_UP:
return _( "Intelligence +4" );
case AEP_ALL_UP:
return _( "All stats +2" );
case AEP_SPEED_UP:
return _( "Speed +20" );
case AEP_PBLUE:
return _( "Reduces radiation" );
case AEP_SNAKES:
return _( "Summons friendly snakes when you're hit" );
case AEP_INVISIBLE:
return _( "Makes you invisible" );
case AEP_CLAIRVOYANCE:
return _( "See through walls" );
case AEP_CLAIRVOYANCE_PLUS:
return _( "See through walls farther" );
case AEP_SUPER_CLAIRVOYANCE:
return _( "See through walls at great distance" );
case AEP_STEALTH:
return _( "Your steps are quieted" );
case AEP_EXTINGUISH:
return _( "May extinguish nearby flames" );
case AEP_GLOW:
return _( "Emits light" );
case AEP_PSYSHIELD:
return _( "Protects from fear and paralysis" );
case AEP_RESIST_ELECTRICITY:
return _( "Protection from electricity" );
case AEP_CARRY_MORE:
return _( "Increases carrying capacity" );
case AEP_SAP_LIFE:
return _( "Killing non-zombie monsters may heal you" );
case AEP_FUN:
return _( "Passive morale boost" );
case AEP_SPLIT:
return _( "No effect" );
case AEP_HUNGER:
return _( "Increases hunger" );
case AEP_THIRST:
return _( "Increases thirst" );
case AEP_SMOKE:
return _( "Emits smoke occasionally" );
case AEP_EVIL:
return _( "Adds an evil presence" );
case AEP_SCHIZO:
return _( "Mimics schizophrenia" );
case AEP_RADIOACTIVE:
return _( "Increases your radiation" );
case AEP_MUTAGENIC:
return _( "Mutates you slowly" );
case AEP_ATTENTION:
return _( "Draws netherworld attention" );
case AEP_STR_DOWN:
return _( "Strength -3" );
case AEP_DEX_DOWN:
return _( "Dexterity -3" );
case AEP_PER_DOWN:
return _( "Perception -3" );
case AEP_INT_DOWN:
return _( "Intelligence -3" );
case AEP_ALL_DOWN:
return _( "All stats -2" );
case AEP_SPEED_DOWN:
return _( "Speed -20" );
case AEP_FORCE_TELEPORT:
return _( "Occasionally forces a teleport" );
case AEP_MOVEMENT_NOISE:
return _( "Makes noise when you move" );
case AEP_BAD_WEATHER:
return _( "More likely to experience bad weather" );
case AEP_SICK:
return _( "Decreases health over time" );
case NUM_AEPS:
break;
}
return _( "Unknown effect" );
}
auto artifact_effect_description( const art_effect_active effect ) -> std::string
{
switch( effect ) {
case AEA_NULL:
return _( "No effect" );
case AEA_STORM:
return _( "Emits shock fields" );
case AEA_FIREBALL:
return _( "Launches fireballs" );
case AEA_ADRENALINE:
return _( "Adrenaline rush" );
case AEA_MAP:
return _( "Reveals the area around you" );
case AEA_BLOOD:
return _( "Shoots blood all over" );
case AEA_FATIGUE:
return _( "Creates interdimensional fatigue" );
case AEA_ACIDBALL:
return _( "Launches acid" );
case AEA_PULSE:
return _( "Destroys adjacent terrain" );
case AEA_HEAL:
return _( "Heals minor damage" );
case AEA_CONFUSED:
return _( "Confuses nearby monsters" );
case AEA_ENTRANCE:
return _( "May make nearby monsters friendly" );
case AEA_BUGS:
return _( "May summon friendly insects" );
case AEA_TELEPORT:
return _( "Teleports you" );
case AEA_LIGHT:
return _( "Temporary light source" );
case AEA_GROWTH:
return _( "Rapid plant growth" );
case AEA_HURTALL:
return _( "Hurts all monsters" );
case AEA_FUN:
return _( "Temporary morale bonus" );
case AEA_SPLIT:
return _( "No effect" );
case AEA_RADIATION:
return _( "Spews radioactive gas" );
case AEA_PAIN:
return _( "Increases pain" );
case AEA_MUTATE:
return _( "Chance of mutation" );
case AEA_PARALYZE:
return _( "Paralyzes you" );
case AEA_FIRESTORM:
return _( "Spreads fire around you" );
case AEA_ATTENTION:
return _( "Draws attention from sub-prime denizens" );
case AEA_TELEGLOW:
return _( "Causes teleglow" );
case AEA_NOISE:
return _( "Loud noise" );
case AEA_SCREAM:
return _( "Noise and morale penalty" );
case AEA_DIM:
return _( "Darkens the sky" );
case AEA_FLASH:
return _( "Flashbang" );
case AEA_VOMIT:
return _( "User vomits" );
case AEA_SHADOWS:
return _( "Summons shadow creatures" );
case AEA_STAMINA_EMPTY:
return _( "Empties most of your stamina" );
case NUM_AEAS:
break;
}
return _( "Unknown effect" );
}
auto artifact_effect_descriptions( const std::vector<art_effect_passive> &effects
) -> std::vector<std::string>
{
return effects
| std::views::transform( []( const art_effect_passive effect ) {
return artifact_effect_description( effect );
} )
| std::ranges::to<std::vector>();
}
auto artifact_effect_descriptions( const std::vector<art_effect_active> &effects
) -> std::vector<std::string>
{
return effects
| std::views::transform( []( const art_effect_active effect ) {
return artifact_effect_description( effect );
} )
| std::ranges::to<std::vector>();
}
auto artifact_charge_description( const art_charge charge ) -> std::string
{
switch( charge ) {
case ARTC_NULL:
return _( "No charges" );
case ARTC_TIME:
return _( "Recharges over time" );
case ARTC_SOLAR:
return _( "Recharges in sunlight" );
case ARTC_PAIN:
return _( "Recharges from pain" );
case ARTC_HP:
return _( "Recharges from health loss" );
case ARTC_FATIGUE:
return _( "Recharges from fatigue" );
case ARTC_PORTAL:
return _( "Recharges near portals" );
case NUM_ARTCS:
break;
}
return _( "Unknown charge type" );
}
auto artifact_charge_req_description( const art_charge_req charge_req ) -> std::string
{
switch( charge_req ) {
case ACR_NULL:
return _( "No special requirement" );
case ACR_EQUIP:
return _( "Must be equipped" );
case ACR_SKIN:
return _( "Must be worn against bare skin" );
case ACR_SLEEP:
return _( "Charges while sleeping" );
case ACR_RAD:
return _( "Charges in radiation" );
case ACR_WET:
return _( "Charges while wet" );
case ACR_SKY:
return _( "Charges under open sky" );
case NUM_ACRS:
break;
}
return _( "Unknown charge requirement" );
}
} // namespace
static void reg_explosion_data( sol::state &lua );
static void reg_islot( sol::state &lua );
static void reg_itype( sol::state &lua );
static void reg_item( sol::state &lua );
void cata::detail::reg_item( sol::state &lua )
{
::reg_explosion_data( lua );
::reg_itype( lua );
::reg_islot( lua );
::reg_item( lua );
}
void reg_item( sol::state &lua )
{
#define UT_CLASS item
{
sol::usertype<item> ut = luna::new_usertype<item>( lua, luna::no_bases, luna::no_constructor );
luna::set_fx( ut, "get_type", &item::typeId );
DOC( "Almost for a corpse." );
luna::set_fx( ut, "get_mtype",
[]( const item & it ) { return it.get_mtype() ? it.get_mtype()->id : mtype_id::NULL_ID(); } );
DOC( "Translated item name with prefixes" );
SET_FX( tname );
DOC( "Display name with all bells and whistles like ammo and prefixes" );
SET_FX( display_name );
DOC( "Weight of the item. The first `bool` is whether including contents, second `bool` is whether it is `integral_weight`." );
luna::set_fx( ut, "weight", [](
item & it,
sol::optional<bool> include_contents,
sol::optional<bool> integral
) { return it.weight( include_contents.value_or( true ), integral.value_or( false ) ); } );
DOC( "Volume of the item. `bool` is whether it is `integral_volume`." );
luna::set_fx( ut, "volume",
[]( item & it, sol::optional<bool> integral ) { return it.volume( integral.value_or( false ) ); } );
DOC( "Cents of the item. `bool` is whether it is a post-cataclysm value." );
SET_FX( price );
DOC( "Check for variable of any type" );
SET_FX( has_var );
DOC( "Erase variable" );
SET_FX( erase_var );
DOC( "Erase all variables" );
SET_FX( clear_vars );
DOC( "Spawns a new item. Same as gapi.create_item " );
luna::set_fx( ut, "spawn", []( const itype_id & itype, int count )
{
return item::spawn( itype, calendar::turn, count );
} );
SET_FX( is_null );
SET_FX( is_unarmed_weapon );
SET_FX( is_sided );
SET_FX( is_power_armor );
SET_FX( is_money );
SET_FX( is_gun );
SET_FX( is_firearm );
SET_FX( is_silent );
SET_FX( is_gunmod );
SET_FX( is_bionic );
SET_FX( is_ammo_belt );
SET_FX( is_bandolier );
SET_FX( is_holster );
SET_FX( is_ammo );
SET_FX( is_comestible );
SET_FX( is_food );
SET_FX( is_medication );
SET_FX( is_brewable );
SET_FX( is_food_container );
SET_FX( is_med_container );
SET_FX( is_corpse );
SET_FX( is_ammo_container );
SET_FX( is_armor );
SET_FX( is_book );
SET_FX( is_map );
SET_FX( is_container );
SET_FX( is_watertight_container );
SET_FX( is_non_resealable_container );
SET_FX( is_bucket );
SET_FX( is_bucket_nonempty );
SET_FX( is_engine );
SET_FX( is_wheel );
SET_FX( is_fuel );
SET_FX( is_toolmod );
SET_FX( is_faulty );
SET_FX( is_irremovable );
SET_FX( is_container_empty );
SET_FX( is_salvageable );
SET_FX( is_craft );
SET_FX( is_emissive );
SET_FX( is_deployable );
SET_FX( is_tool );
SET_FX( is_transformable );
SET_FX( is_artifact );
SET_FX( is_relic );
SET_FX( is_seed );
SET_FX( is_dangerous );
SET_FX( is_tainted );
SET_FX( is_soft );
SET_FX( is_reloadable );
DOC( "DEPRECATED: Items are no longer filthy" );
luna::set_fx( ut, "is_filthy", []() { return false; } );
SET_FX( is_active );
SET_FX( is_upgrade );
SET_FX( activate );
SET_FX( deactivate );
SET_FX( set_charges );
SET_FX( set_counter );
SET_FX( get_counter );
DOC( "Is this item an effective melee weapon for the given damage type?" );
luna::set_fx( ut, "is_melee", sol::resolve<bool( damage_type ) const>
( &item::is_melee ) );
DOC( "Is this a magazine? (batteries are magazines)" );
SET_FX( is_magazine );
DOC( "DEPRECATED: Is this a battery? (spoiler: it isn't)" );
SET_FX( is_battery );
SET_FX( conductive );
luna::set_fx( ut, "is_stackable", sol::resolve<bool() const> ( &item::count_by_charges ) );
luna::set( ut, "charges", &item::charges );
SET_FX( energy_remaining );
SET_FX( has_infinite_charges );
SET_FX( mod_charges );
luna::set_fx( ut, "made_of", []( item & it )
{
return it.made_of();
} );
luna::set_fx( ut, "is_made_of",
sol::resolve < auto( const material_id & ) const -> bool > ( &item::made_of ) );
luna::set_fx( ut, "get_kcal", []( item & it ) -> int { return it.is_comestible() ? it.get_comestible()->default_nutrition.kcal : 0; } );
luna::set_fx( ut, "get_quench", []( item & it ) -> int { return it.is_comestible() ? it.get_comestible()->quench : 0; } );
luna::set_fx( ut, "get_comestible_fun", []( item & it ) -> int { return it.get_comestible_fun(); } );
DOC( "Gets the TimeDuration until this item rots" );
SET_FX( get_rot );
DOC( "Gets the category id this item is in" );
SET_FX( get_category_id );
DOC( "Gets the faction id that owns this item" );
SET_FX( get_owner );
DOC( "Sets the ownership of this item to a faction" );
luna::set_fx( ut, "set_owner",
sol::resolve<void( const faction_id & )>
( &item::set_owner ) );
DOC( "Sets the ownership of this item to a character" );
luna::set_fx( ut, "set_owner",
sol::resolve<void( const Character & )>
( &item::set_owner ) );
SET_FX( get_owner_name );
DOC( "Checks if this item owned by a character" );
SET_FX( is_owned_by );
DOC( "Checks if this item has the technique as an addition. Doesn't check original techniques." );
luna::set_fx( ut, "has_technique",
sol::resolve<bool( const matec_id & ) const> ( &item::has_technique ) );
DOC( "Gets all techniques. Including original techniques." );
luna::set_fx( ut, "get_techniques",
sol::resolve<std::set<matec_id>() const> ( &item::get_techniques ) );
DOC( "Adds the technique. It isn't treated original, but additional." );
luna::set_fx( ut, "add_technique",
sol::resolve<void( const matec_id & )> ( &item::add_technique ) );
DOC( "Removes the additional technique. Doesn't affect originial techniques." );
luna::set_fx( ut, "remove_technique",
sol::resolve<void( const matec_id & )> ( &item::remove_technique ) );
DOC( "Checks if this item can contain another" );
luna::set_fx( ut, "can_contain",
sol::resolve<bool( const item & ) const>
( &item::can_contain ) );
DOC( "Gets the remaining space available for a type of liquid" );
luna::set_fx( ut, "remaining_capacity_for_id", &item::get_remaining_capacity_for_id );
DOC( "Gets maximum volume this item can hold (liquids, ammo, etc)" );
luna::set_fx( ut, "total_capacity", &item::get_total_capacity );
DOC( "Gets the current magazine" );
luna::set_fx( ut, "current_magazine",
sol::resolve<const item*() const> ( &item::magazine_current ) );
DOC( "Gets the maximum capacity of a magazine" );
luna::set_fx( ut, "ammo_capacity",
sol::resolve<int( const bool ) const>
( &item::ammo_capacity ) );
DOC( "Get remaining ammo, works with batteries & stuff too" );
SET_FX( ammo_remaining );
SET_FX( ammo_data );
SET_FX( ammo_required );
SET_FX( ammo_current );
SET_FX( ammo_consume );
SET_FX( ammo_set );
SET_FX( ammo_unset );
SET_FX( get_reload_time );
DOC( "Adds an item(s) to contents" );
SET_FX( add_item_with_id );
DOC( "Checks item contents for a given item id" );
SET_FX( has_item_with_id );
DOC( "Checks if the item covers a bodypart" );
SET_FX( covers );
SET_FX( set_flag );
SET_FX( unset_flag );
SET_FX( has_flag );
SET_FX( has_own_flag );
SET_FX( set_flag_recursive );
SET_FX( unset_flags );
DOC( "Converts the item as given `ItypeId`." );
SET_FX( convert );
DOC( "Get variable as string" );
luna::set_fx( ut, "get_var_str", []( const UT_CLASS & c, const std::string & name, const std::string & def_val )
{
return c.get_var( name, def_val );
} );
DOC( "Get variable as float number" );
luna::set_fx( ut, "get_var_num", []( const UT_CLASS & c, const std::string & name, const double & def_val )
{
return c.get_var( name, def_val );
} );
DOC( "Get variable as tripoint" );
luna::set_fx( ut, "get_var_tri", []( const UT_CLASS & c, const std::string & name, const tripoint & def_val )
{
return c.get_var( name, def_val );
} );
luna::set_fx( ut, "set_var_str", []( UT_CLASS & c, const std::string & name, const std::string & val )
{
c.set_var( name, val );
} );
luna::set_fx( ut, "set_var_num", []( UT_CLASS & c, const std::string & name, const double & val )
{
c.set_var( name, val );
} );
luna::set_fx( ut, "set_var_tri", []( UT_CLASS & c, const std::string & name, const tripoint & val )
{
c.set_var( name, val );
} );
SET_FX( attack_cost );
SET_FX( stamina_cost );
// Damage (breakage) related bindings
DOC( "Get current item damage value (durability). Higher values mean more damaged. Default range is -1000 (min) to 4000 (max), configurable via 'damage_states' in JSON." );
luna::set_fx( ut, "get_damage", &item::damage );
DOC( "Get item damage as a level from 0 to max. Used for UI display and damage thresholds." );
luna::set_fx( ut, "get_damage_level", sol::overload(
[]( const item & self ) -> int {
return self.damage_level( 4 );
},
[]( const item & self, int max ) -> int {
return self.damage_level( max );
}
) );
DOC( "Get minimum possible damage value (can be negative for reinforced items). Default is -1000, configurable via 'damage_states' in JSON." );
luna::set_fx( ut, "get_min_damage", &item::min_damage );
DOC( "Get maximum possible damage value before item is destroyed. Default is 4000, configurable via 'damage_states' in JSON." );
luna::set_fx( ut, "get_max_damage", &item::max_damage );
DOC( "Get relative health as ratio 0.0-1.0, where 1.0 is undamaged and 0.0 is destroyed" );
luna::set_fx( ut, "get_relative_health", &item::get_relative_health );
DOC( "Set item damage to specified value. Clamped between min_damage and max_damage." );
luna::set_fx( ut, "set_damage", &item::set_damage );
DOC( "Modify item damage by given amount. Returns true if item should be destroyed." );
luna::set_fx( ut, "mod_damage", sol::overload(
static_cast<bool( item::* )( int )>( &item::mod_damage ),
static_cast<bool( item::* )( int, damage_type )>( &item::mod_damage )
) );
SET_FX( get_melee_damage_bonus );
SET_FX( get_melee_hit_bonus );
SET_FX( get_ranged_damage_bonus );
SET_FX( get_range_bonus );
SET_FX( get_dispersion_bonus );
SET_FX( get_recoil_bonus );
SET_FX( set_melee_damage_bonus );
SET_FX( set_melee_hit_bonus );
SET_FX( set_ranged_damage_bonus );
SET_FX( set_range_bonus );
SET_FX( set_dispersion_bonus );
SET_FX( set_recoil_bonus );
}
#undef UT_CLASS
}
#define VALUE_PTR_MEMB_N(prop_name, lua_name_str) luna::set_fx( ut, lua_name_str, [](const UT_CLASS& c) { return c.prop_name.get(); } )
void reg_itype( sol::state &lua )
{
#define UT_CLASS itype
{
DOC( "Slots for various item type properties. Each slot may contain a valid value or nil" );
sol::usertype<itype> ut = luna::new_usertype<itype>( lua, luna::no_bases, luna::no_constructor );
VALUE_PTR_MEMB_N( container, "slot_container" );
VALUE_PTR_MEMB_N( tool, "slot_tool" );
VALUE_PTR_MEMB_N( comestible, "slot_comestible" );
VALUE_PTR_MEMB_N( brewable, "slot_brewable" );
VALUE_PTR_MEMB_N( armor, "slot_armor" );
VALUE_PTR_MEMB_N( pet_armor, "slot_pet_armor" );
VALUE_PTR_MEMB_N( book, "slot_book" );
VALUE_PTR_MEMB_N( mod, "slot_mod" );
VALUE_PTR_MEMB_N( engine, "slot_engine" );
VALUE_PTR_MEMB_N( wheel, "slot_wheel" );
VALUE_PTR_MEMB_N( fuel, "slot_fuel" );
VALUE_PTR_MEMB_N( gun, "slot_gun" );
VALUE_PTR_MEMB_N( gunmod, "slot_gunmod" );
VALUE_PTR_MEMB_N( magazine, "slot_magazine" );
VALUE_PTR_MEMB_N( battery, "slot_battery" );
VALUE_PTR_MEMB_N( bionic, "slot_bionic" );
VALUE_PTR_MEMB_N( ammo, "slot_ammo" );
VALUE_PTR_MEMB_N( seed, "slot_seed" );
VALUE_PTR_MEMB_N( artifact, "slot_artifact" );
VALUE_PTR_MEMB_N( relic_data, "slot_relic" );
VALUE_PTR_MEMB_N( milling_data, "slot_milling" );
//TODO: Check nothing important is missing below
auto get_action = []( const use_function & c ) { return c.get_type();};
auto get_uses = [ = ]( const UT_CLASS & c )
{
std::vector<std::string> rv {};
std::ranges::copy( c.use_methods | std::views::values | std::views::transform( get_action ),
std::back_inserter( rv ) );
return rv;
};
SET_FX_N( get_id, "type_id" );
SET_FX( can_have_charges );
SET_FX( can_use );
SET_FX( charge_factor );
SET_FX( charges_default );
SET_FX( charges_per_volume );
SET_FX( charges_to_use );
SET_FX_N( count_by_charges, "is_stackable" );
SET_FX( damage_max );
SET_FX( damage_min );
SET_FX( get_flags );
SET_FX( has_flag );
SET_FX( has_use );
SET_FX( maximum_charges );
SET_FX_N( nname, "get_name" );
SET_MEMB_N_RO( explosion, "explosion_data" );
SET_MEMB_N_RO( m_to_hit, "melee_to_hit" );
luna::set_fx( ut, "source_mod", []( const UT_CLASS & c )
{
std::vector<mod_id> rv {};
std::ranges::copy( c.src | std::views::transform( []( auto & p ) { return p.second; } ),
std::back_inserter( rv ) );
return rv;
} );
SET_MEMB_RO( attacks );
SET_MEMB_RO( countdown_destroy );
SET_MEMB_RO( countdown_interval );
SET_MEMB_RO( default_container );
SET_MEMB_RO( emits );
SET_MEMB_RO( explode_in_fire );
SET_MEMB_RO( faults );
SET_MEMB_RO( integral_volume );
SET_MEMB_RO( integral_weight );
SET_MEMB_RO( item_tags );
SET_MEMB_RO( layer );
SET_MEMB_RO( light_emission );
SET_MEMB_RO( looks_like );
SET_MEMB_RO( materials );
SET_MEMB_RO( min_dex );
SET_MEMB_RO( min_int );
SET_MEMB_RO( min_per );
SET_MEMB_RO( min_skills );
SET_MEMB_RO( min_str );
SET_MEMB_RO( phase );
luna::set_fx( ut, "price", []( const UT_CLASS & c ) { return c.price.value(); } );
luna::set_fx( ut, "price_post", []( const UT_CLASS & c ) { return c.price.value(); } );
SET_MEMB_RO( properties );
SET_MEMB_RO( qualities );
SET_MEMB_RO( recipes );
SET_MEMB_RO( repair );
SET_MEMB_RO( repairs_like );
SET_MEMB_RO( rigid );
SET_MEMB_RO( stack_size );
SET_MEMB_RO( techniques );
SET_MEMB_RO( thrown_damage );
SET_MEMB_RO( volume );
SET_MEMB_RO( weapon_category );
SET_MEMB_RO( weight );
luna::set_fx( ut, "get_countdown_action", [ = ]( const UT_CLASS & c ) { return get_action( c.countdown_action ); } );
luna::set_fx( ut, "get_description", []( const UT_CLASS & c, const int num ) { return c.description.translated( num ); } );
luna::set_fx( ut, "get_drop_action", [ = ]( const UT_CLASS & c ) { return get_action( c.drop_action ); } );
luna::set_fx( ut, "get_uses", get_uses );
}
#undef UT_CLASS
}
void reg_islot( sol::state &lua )
{
#define UT_CLASS islot_container
{
sol::usertype<UT_CLASS> ut = luna::new_usertype<UT_CLASS>( lua, luna::no_bases, luna::no_constructor );
DOC( "Inner volume of the container" );
SET_MEMB_RO( contains );
DOC( "Contents do not spoil" );
SET_MEMB_RO( preserves );
DOC( "Can be resealed" );
SET_MEMB_RO( seals );
DOC( "If this is set to anything but \"null\", changing this container's contents in any way will turn this item into that type" );
SET_MEMB_RO( unseals_into );
DOC( "Can hold liquids" );
SET_MEMB_RO( watertight );
}
#undef UT_CLASS
#define UT_CLASS islot_tool
{
sol::usertype<UT_CLASS> ut = luna::new_usertype<UT_CLASS>( lua, luna::no_bases, luna::no_constructor );
SET_MEMB_RO( charge_factor );
SET_MEMB_RO( ammo_id );
SET_MEMB_RO( charges_per_use );
SET_MEMB_RO( def_charges );
SET_MEMB_RO( default_ammo );
SET_MEMB_RO( max_charges );
SET_MEMB_RO( power_draw );
SET_MEMB_RO( rand_charges );
SET_MEMB_RO( revert_msg );
SET_MEMB_RO( revert_to );
SET_MEMB_RO( subtype );
SET_MEMB_RO( turns_active );
SET_MEMB_RO( turns_per_charge );
SET_MEMB_RO( ups_eff_mult );
SET_MEMB_RO( ups_recharge_rate );
}
#undef UT_CLASS
#define UT_CLASS islot_comestible
{
sol::usertype<UT_CLASS> ut = luna::new_usertype<UT_CLASS>( lua, luna::no_bases, luna::no_constructor );
DOC( "comestible subtype - eg. FOOD, DRINK, MED" );
SET_MEMB_N_RO( comesttype, "comest_type" );
DOC( "tool needed to consume (e.g. lighter for cigarettes)" );
SET_MEMB_RO( tool );
DOC( "Defaults # of charges (drugs, loaf of bread? etc)" );
SET_MEMB_RO( def_charges );
DOC( "effect on character thirst (may be negative)" );
SET_MEMB_RO( quench );
DOC( "Nutrition values to use for this type when they aren't calculated from components" );
luna::set_fx( ut, "get_default_nutrition", []( const UT_CLASS & c ) -> auto& {
return c.default_nutrition.vitamins;
} );
DOC( "Time until becomes rotten at standard temperature, or zero if never spoils" );
SET_MEMB_RO( spoils );
DOC( "addiction potential" );
SET_MEMB_N_RO( addict, "addict_value" );
DOC( "effects of addiction" );
SET_MEMB_N_RO( add, "addict_type" );
DOC( "stimulant effect" );
SET_MEMB_N_RO( stim, "stimulant_type" );
DOC( "fatigue altering effect" );
SET_MEMB_RO( fatigue_mod );
DOC( "Reference to other item that replaces this one as a component in recipe results" );
SET_MEMB_RO( cooks_like );
DOC( "Reference to item that will be received after smoking current item" );
SET_MEMB_RO( smoking_result );
//DOC("TODO: add documentation");
SET_MEMB_RO( healthy );
DOC( "chance (odds) of becoming parasitised when eating (zero if never occurs)" );
SET_MEMB_RO( parasites );
DOC( "Amount of radiation you get from this comestible" );
SET_MEMB_RO( radiation );
DOC( "pet food category" );
SET_MEMB_RO( petfood );
DOC( "freezing point in degrees Fahrenheit, below this temperature item can freeze" );
SET_MEMB_RO( freeze_point );
DOC( "List of diseases carried by this comestible and their associated probability" );
SET_MEMB_RO( contamination );
DOC( "specific heats in J/(g K) and latent heat in J/g" );
SET_MEMB_RO( specific_heat_liquid );
SET_MEMB_RO( specific_heat_solid );
SET_MEMB_RO( latent_heat );
DOC( "A penalty applied to fun for every time this food has been eaten in the last 48 hours" );
SET_MEMB_RO( monotony_penalty );
SET_FX( has_calories );
SET_FX( get_default_nutr );
DOC( "The monster group that is drawn from when the item rots away" );
SET_MEMB_RO( rot_spawn );
DOC( "Chance the above monster group spawns" );
SET_MEMB_RO( rot_spawn_chance );
}
#undef UT_CLASS
#define UT_CLASS islot_brewable
{
sol::usertype<UT_CLASS> ut = luna::new_usertype<UT_CLASS>( lua, luna::no_bases, luna::no_constructor );
DOC( "What are the results of fermenting this item" );
SET_MEMB_RO( results );
DOC( "How long for this brew to ferment" );
SET_MEMB_RO( time );
}
#undef UT_CLASS
#define UT_CLASS islot_armor
{
sol::usertype<UT_CLASS> ut = luna::new_usertype<UT_CLASS>( lua, luna::no_bases, luna::no_constructor );
DOC( "Layer, encumbrance and coverage information" );
SET_MEMB_N_RO( data, "layer_data" );
DOC( "Resistance to environmental effects" );
SET_MEMB_RO( env_resist );
DOC( "Environmental protection of a gas mask with installed filter" );
SET_MEMB_RO( env_resist_w_filter );
DOC( "Damage negated by this armor. Usually calculated from materials+thickness" );
SET_MEMB_RO( resistance );
DOC( "Whether this item can be worn on either side of the body" );
SET_MEMB_RO( sided );
DOC( "How much storage this items provides when worn" );
SET_MEMB_RO( storage );
DOC( "Multiplier on resistances provided by armor's materials. Damaged armors have lower effective thickness, low capped at 1. Note: 1 thickness means item retains full resistance when damaged." );
SET_MEMB_RO( thickness );
DOC( "Whitelisted clothing mods. Restricted clothing mods must be listed here by id to be compatible." );
SET_MEMB_RO( valid_mods );
DOC( "How much warmth this item provides" );
SET_MEMB_RO( warmth );
DOC( "Bonus to weight capacity" );
SET_MEMB_RO( weight_capacity_bonus );
DOC( "Factor modifying weight capacity" );
SET_MEMB_RO( weight_capacity_modifier );
}
#undef UT_CLASS
#define UT_CLASS islot_pet_armor
{
sol::usertype<UT_CLASS> ut = luna::new_usertype<UT_CLASS>( lua, luna::no_bases, luna::no_constructor );
DOC( "The minimum volume a pet can be and wear this armor" );
SET_MEMB_RO( min_vol );
DOC( "The maximum volume a pet can be and wear this armor" );
SET_MEMB_RO( max_vol );
DOC( "Resistance to environmental effects" );
SET_MEMB_RO( env_resist );
DOC( "Environmental protection of a gas mask with installed filter" );
SET_MEMB_RO( env_resist_w_filter );
DOC( " How much storage this items provides when worn" );
SET_MEMB_RO( storage );
DOC( "Multiplier on resistances provided by this armor" );
SET_MEMB_RO( thickness );
DOC( "What animal bodytype can wear this armor" );
SET_MEMB_RO( bodytype );
}
#undef UT_CLASS
#define UT_CLASS islot_book
{
auto ut = luna::new_usertype<UT_CLASS>( lua, luna::no_bases, luna::no_constructor );
DOC( "How long in minutes it takes to read. \"To read\" means getting 1 skill point, not all of them." );
SET_MEMB_RO( time );
DOC( "Fun books have chapters; after all are read, the book is less fun." );
SET_MEMB_RO( chapters );
DOC( "Which martial art it teaches. Can be MartialArtsId.NULL_ID" );
SET_MEMB_RO( martial_art );
DOC( "How fun reading this is, can be negative" );
SET_MEMB_RO( fun );
DOC( "Intelligence required to read it" );
SET_MEMB_N_RO( intel, "intelligence" );
DOC( "Which skill it upgrades, if any. Can be SkillId.NULL_ID" );
SET_MEMB_RO( skill );
DOC( "The skill level required to understand it" );
SET_MEMB_N_RO( req, "skill_min" );
DOC( "The skill level the book provides" );
SET_MEMB_N_RO( level, "skill_max" );
DOC( "Recipes contained in this book" );
SET_MEMB_RO( recipes );
}
#undef UT_CLASS
#define UT_CLASS islot_mod
{
sol::usertype<UT_CLASS> ut = luna::new_usertype<UT_CLASS>( lua, luna::no_bases, luna::no_constructor );
DOC( "If non-empty restrict mod to items with those base (before modifiers) ammo types" );
SET_MEMB_RO( acceptable_ammo );
DOC( "If set modifies parent ammo to this type" );
SET_MEMB_RO( ammo_modifier );
DOC( "Proportional adjustment of parent item ammo capacity" );
SET_MEMB_RO( capacity_multiplier );
DOC( "If non-empty replaces the compatible magazines for the parent item" );
SET_MEMB_RO( magazine_adaptor );
}
#undef UT_CLASS
#define UT_CLASS islot_engine
{
sol::usertype<UT_CLASS> ut = luna::new_usertype<UT_CLASS>( lua, luna::no_bases, luna::no_constructor );
DOC( "For combustion engines, the displacement" );
SET_MEMB_RO( displacement );
}
#undef UT_CLASS
#define UT_CLASS islot_wheel
{
sol::usertype<UT_CLASS> ut = luna::new_usertype<UT_CLASS>( lua, luna::no_bases, luna::no_constructor );
DOC( "Diameter of wheel in inches" );
SET_MEMB_RO( diameter );
DOC( "Width of wheel in inches" );
SET_MEMB_RO( width );
}
#undef UT_CLASS
#define UT_CLASS islot_fuel
{
sol::usertype<UT_CLASS> ut = luna::new_usertype<UT_CLASS>( lua, luna::no_bases, luna::no_constructor );
DOC( "Energy of the fuel (kilojoules per charge)" );
SET_MEMB_RO( energy );
SET_MEMB_RO( explosion_data );