-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathassign_wpn_armor.c
2598 lines (2309 loc) · 108 KB
/
assign_wpn_armor.c
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
/*****************************************************************************
* assign_wpn_armor.c Part of LuminariMUD
* author: Zusuk
* Assigning weapon and armor values for respective types
*****************************************************************************/
#include "conf.h"
#include "sysdep.h"
#include "structs.h"
#include "comm.h"
#include "utils.h"
#include "db.h"
#include "mud_event.h"
#include "actions.h"
#include "actionqueues.h"
#include "assign_wpn_armor.h"
#include "craft.h"
#include "feats.h"
#include "constants.h"
#include "modify.h"
#include "domains_schools.h"
#include "spec_abilities.h"
#include "handler.h"
#include "spells.h"
/* global */
struct armor_table armor_list[NUM_SPEC_ARMOR_TYPES];
struct weapon_table weapon_list[NUM_WEAPON_TYPES];
const char *weapon_type[NUM_WEAPON_TYPES];
/* simply checks if ch has proficiency with given weapon_type */
int is_proficient_with_weapon(struct char_data *ch, int weapon)
{
if (affected_by_spell(ch, SPELL_BESTOW_WEAPON_PROFICIENCY))
return true;
if (HAS_FEAT(ch, FEAT_WEAPON_PROFICIENCY_KENDER) && weapon == WEAPON_TYPE_HOOPAK);
return TRUE;
if (HAS_REAL_FEAT(ch, FEAT_PALE_MASTER_WEAPONS) && weapon == WEAPON_TYPE_SCYTHE)
return TRUE;
/* :) */
if (weapon == WEAPON_TYPE_UNARMED && MONK_TYPE((ch)))
return TRUE;
if ((HAS_FEAT(ch, FEAT_SIMPLE_WEAPON_PROFICIENCY) || HAS_FEAT(ch, FEAT_WEAPON_EXPERT)) &&
IS_SET(weapon_list[weapon].weaponFlags, WEAPON_FLAG_SIMPLE))
return TRUE;
if ((HAS_FEAT(ch, FEAT_MARTIAL_WEAPON_PROFICIENCY) || HAS_FEAT(ch, FEAT_WEAPON_EXPERT)) &&
IS_SET(weapon_list[weapon].weaponFlags, WEAPON_FLAG_MARTIAL))
return TRUE;
if (HAS_FEAT(ch, FEAT_EXOTIC_WEAPON_PROFICIENCY) &&
IS_SET(weapon_list[weapon].weaponFlags, WEAPON_FLAG_EXOTIC))
return TRUE;
if (HAS_FEAT(ch, FEAT_WEAPON_PROFICIENCY_MONK) &&
weapon_list[weapon].weaponFamily == WEAPON_FAMILY_MONK)
return TRUE;
if (CLASS_LEVEL(ch, CLASS_INQUISITOR) && GET_1ST_DOMAIN(ch) && domain_list[GET_1ST_DOMAIN(ch)].favored_weapon == weapon)
return TRUE;
/* updated by zusuk: Druids are proficient with the following weapons: club,
* dagger, dart, quarterstaff, scimitar, scythe, sickle, shortspear, sling,
* and spear. They are also proficient with all natural attacks (claw, bite,
* and so forth) of any form they assume with wild shape.*/
if (HAS_FEAT(ch, FEAT_WEAPON_PROFICIENCY_DRUID) ||
CLASS_LEVEL(ch, CLASS_DRUID) > 0)
{
switch (weapon)
{
case WEAPON_TYPE_CLUB:
case WEAPON_TYPE_DAGGER:
case WEAPON_TYPE_KNIFE:
case WEAPON_TYPE_QUARTERSTAFF:
case WEAPON_TYPE_SCIMITAR:
case WEAPON_TYPE_SCYTHE:
case WEAPON_TYPE_SICKLE:
case WEAPON_TYPE_SHORTSPEAR:
case WEAPON_TYPE_SLING:
case WEAPON_TYPE_SPEAR:
return TRUE;
}
}
if (HAS_FEAT(ch, FEAT_INQUISITOR_WEAPON_PROFICIENCY) ||
CLASS_LEVEL(ch, CLASS_INQUISITOR) > 0)
{
switch (weapon)
{
case WEAPON_TYPE_HAND_CROSSBOW:
case WEAPON_TYPE_LONG_BOW:
case WEAPON_TYPE_SHORT_BOW:
case WEAPON_TYPE_LIGHT_REP_XBOW:
case WEAPON_TYPE_HEAVY_REP_XBOW:
case WEAPON_TYPE_COMPOSITE_SHORTBOW:
case WEAPON_TYPE_COMPOSITE_SHORTBOW_2:
case WEAPON_TYPE_COMPOSITE_SHORTBOW_3:
case WEAPON_TYPE_COMPOSITE_SHORTBOW_4:
case WEAPON_TYPE_COMPOSITE_SHORTBOW_5:
case WEAPON_TYPE_COMPOSITE_LONGBOW:
case WEAPON_TYPE_COMPOSITE_LONGBOW_2:
case WEAPON_TYPE_COMPOSITE_LONGBOW_3:
case WEAPON_TYPE_COMPOSITE_LONGBOW_4:
case WEAPON_TYPE_COMPOSITE_LONGBOW_5:
return TRUE;
}
}
if (HAS_FEAT(ch, FEAT_WEAPON_PROFICIENCY_BARD) ||
CLASS_LEVEL(ch, CLASS_BARD) > 0)
{
switch (weapon)
{
case WEAPON_TYPE_LONG_SWORD:
case WEAPON_TYPE_RAPIER:
case WEAPON_TYPE_SAP:
case WEAPON_TYPE_SHORT_SWORD:
case WEAPON_TYPE_SHORT_BOW:
case WEAPON_TYPE_WHIP:
return TRUE;
}
}
if (HAS_FEAT(ch, FEAT_WEAPON_PROFICIENCY_ASSASSIN) ||
CLASS_LEVEL(ch, CLASS_ASSASSIN) > 0)
{
switch (weapon)
{
case WEAPON_TYPE_HAND_CROSSBOW:
case WEAPON_TYPE_LIGHT_CROSSBOW:
case WEAPON_TYPE_HEAVY_CROSSBOW:
case WEAPON_TYPE_DAGGER:
case WEAPON_TYPE_KNIFE:
case WEAPON_TYPE_DART:
case WEAPON_TYPE_RAPIER:
case WEAPON_TYPE_SHORT_BOW:
case WEAPON_TYPE_COMPOSITE_SHORTBOW:
case WEAPON_TYPE_COMPOSITE_SHORTBOW_2:
case WEAPON_TYPE_COMPOSITE_SHORTBOW_3:
case WEAPON_TYPE_COMPOSITE_SHORTBOW_4:
case WEAPON_TYPE_COMPOSITE_SHORTBOW_5:
case WEAPON_TYPE_SHORT_SWORD:
return TRUE;
}
}
if (HAS_FEAT(ch, FEAT_WEAPON_PROFICIENCY_ROGUE) ||
CLASS_LEVEL(ch, CLASS_ROGUE) > 0)
{
switch (weapon)
{
case WEAPON_TYPE_HAND_CROSSBOW:
case WEAPON_TYPE_RAPIER:
case WEAPON_TYPE_SAP:
case WEAPON_TYPE_SHORT_SWORD:
case WEAPON_TYPE_SHORT_BOW:
return TRUE;
}
}
if (HAS_FEAT(ch, FEAT_WEAPON_PROFICIENCY_WIZARD) ||
CLASS_LEVEL(ch, CLASS_WIZARD) > 0)
{
switch (weapon)
{
case WEAPON_TYPE_DAGGER:
case WEAPON_TYPE_KNIFE:
case WEAPON_TYPE_QUARTERSTAFF:
case WEAPON_TYPE_CLUB:
case WEAPON_TYPE_HEAVY_CROSSBOW:
case WEAPON_TYPE_LIGHT_CROSSBOW:
return TRUE;
}
}
if (HAS_FEAT(ch, FEAT_WEAPON_PROFICIENCY_PSIONICIST) ||
CLASS_LEVEL(ch, CLASS_PSIONICIST) > 0)
{
switch (weapon)
{
case WEAPON_TYPE_DAGGER:
case WEAPON_TYPE_KNIFE:
case WEAPON_TYPE_QUARTERSTAFF:
case WEAPON_TYPE_CLUB:
case WEAPON_TYPE_HEAVY_CROSSBOW:
case WEAPON_TYPE_LIGHT_CROSSBOW:
case WEAPON_TYPE_SHORTSPEAR:
return TRUE;
}
}
if (HAS_FEAT(ch, FEAT_WEAPON_PROFICIENCY_SHADOWDANCER) ||
CLASS_LEVEL(ch, CLASS_SHADOWDANCER) > 0)
{
switch (weapon)
{
case WEAPON_TYPE_CLUB:
case WEAPON_TYPE_HEAVY_CROSSBOW:
case WEAPON_TYPE_LIGHT_CROSSBOW:
case WEAPON_TYPE_HAND_CROSSBOW:
case WEAPON_TYPE_DAGGER:
case WEAPON_TYPE_KNIFE:
case WEAPON_TYPE_KUKRI:
case WEAPON_TYPE_DART:
case WEAPON_TYPE_LIGHT_MACE:
case WEAPON_TYPE_HEAVY_MACE:
case WEAPON_TYPE_MORNINGSTAR:
case WEAPON_TYPE_QUARTERSTAFF:
case WEAPON_TYPE_RAPIER:
case WEAPON_TYPE_SAP:
case WEAPON_TYPE_SHORT_BOW:
case WEAPON_TYPE_COMPOSITE_SHORTBOW:
case WEAPON_TYPE_COMPOSITE_SHORTBOW_2:
case WEAPON_TYPE_COMPOSITE_SHORTBOW_3:
case WEAPON_TYPE_COMPOSITE_SHORTBOW_4:
case WEAPON_TYPE_COMPOSITE_SHORTBOW_5:
case WEAPON_TYPE_SHORT_SWORD:
return TRUE;
}
}
if (HAS_FEAT(ch, FEAT_WEAPON_PROFICIENCY_DROW) ||
IS_DROW(ch))
{
switch (weapon)
{
case WEAPON_TYPE_HAND_CROSSBOW:
case WEAPON_TYPE_RAPIER:
case WEAPON_TYPE_SHORT_SWORD:
return TRUE;
}
}
if (HAS_FEAT(ch, FEAT_WEAPON_PROFICIENCY_ELF) ||
IS_ELF(ch))
{
switch (weapon)
{
case WEAPON_TYPE_LONG_SWORD:
case WEAPON_TYPE_RAPIER:
case WEAPON_TYPE_LONG_BOW:
case WEAPON_TYPE_COMPOSITE_LONGBOW:
case WEAPON_TYPE_COMPOSITE_LONGBOW_2:
case WEAPON_TYPE_COMPOSITE_LONGBOW_3:
case WEAPON_TYPE_COMPOSITE_LONGBOW_4:
case WEAPON_TYPE_COMPOSITE_LONGBOW_5:
case WEAPON_TYPE_SHORT_BOW:
case WEAPON_TYPE_COMPOSITE_SHORTBOW:
case WEAPON_TYPE_COMPOSITE_SHORTBOW_2:
case WEAPON_TYPE_COMPOSITE_SHORTBOW_3:
case WEAPON_TYPE_COMPOSITE_SHORTBOW_4:
case WEAPON_TYPE_COMPOSITE_SHORTBOW_5:
return TRUE;
}
}
if (IS_DWARF(ch))
{
switch (weapon)
{
case WEAPON_TYPE_BATTLE_AXE:
case WEAPON_TYPE_HEAVY_PICK:
case WEAPON_TYPE_WARHAMMER:
case WEAPON_TYPE_DWARVEN_WAR_AXE:
case WEAPON_TYPE_DWARVEN_URGOSH:
return TRUE;
}
}
if (HAS_FEAT(ch, FEAT_DWARVEN_WEAPON_PROFICIENCY))
{
switch (weapon)
{
case WEAPON_TYPE_BATTLE_AXE:
case WEAPON_TYPE_HEAVY_PICK:
case WEAPON_TYPE_LIGHT_PICK:
case WEAPON_TYPE_WARHAMMER:
case WEAPON_TYPE_LIGHT_HAMMER:
case WEAPON_TYPE_DWARVEN_WAR_AXE:
case WEAPON_TYPE_DWARVEN_URGOSH:
return TRUE;
}
}
if (IS_DUERGAR(ch))
{
switch (weapon)
{
case WEAPON_TYPE_BATTLE_AXE:
case WEAPON_TYPE_HEAVY_PICK:
case WEAPON_TYPE_WARHAMMER:
case WEAPON_TYPE_DWARVEN_WAR_AXE:
case WEAPON_TYPE_DWARVEN_URGOSH:
return TRUE;
}
}
/* cleric domain, favored weapons */
if (!IS_NPC(ch) && domain_list[GET_1ST_DOMAIN(ch)].favored_weapon == weapon)
return TRUE;
if (!IS_NPC(ch) && domain_list[GET_2ND_DOMAIN(ch)].favored_weapon == weapon)
return TRUE;
/* TODO: Adapt this - Focus on an aspect of the divine, not a deity. */
/* if (HAS_FEAT((char_data *) ch, FEAT_DEITY_WEAPON_PROFICIENCY) && weapon == deity_list[GET_DEITY(ch)].favored_weapon)
return TRUE;
*/
/* //deprecated
if (HAS_COMBAT_FEAT(ch, CFEAT_EXOTIC_WEAPON_PROFICIENCY, DAMAGE_TYPE_SLASHING) &&
IS_SET(weapon_list[weapon].weaponFlags, WEAPON_FLAG_EXOTIC) &&
IS_SET(weapon_list[weapon].damageTypes, DAMAGE_TYPE_SLASHING)) {
return TRUE;
}
if (HAS_COMBAT_FEAT(ch, CFEAT_EXOTIC_WEAPON_PROFICIENCY, DAMAGE_TYPE_PIERCING) &&
IS_SET(weapon_list[weapon].weaponFlags, WEAPON_FLAG_EXOTIC) &&
IS_SET(weapon_list[weapon].damageTypes, DAMAGE_TYPE_PIERCING)) {
return TRUE;
}
if (HAS_COMBAT_FEAT(ch, CFEAT_EXOTIC_WEAPON_PROFICIENCY, DAMAGE_TYPE_BLUDGEONING) &&
IS_SET(weapon_list[weapon].weaponFlags, WEAPON_FLAG_EXOTIC) &&
IS_SET(weapon_list[weapon].damageTypes, DAMAGE_TYPE_BLUDGEONING)) {
return TRUE;
}
*/
/* nope not proficient with given weapon! */
return FALSE;
}
/* is weapon out of ammo? */
bool weapon_needs_reload(struct char_data *ch, struct obj_data *weapon, bool silent_mode)
{
/* object value 5 is for loaded status */
if (GET_OBJ_VAL(weapon, 5) > 0)
{
if (!silent_mode)
send_to_char(ch, "Your weapon is not empty yet!\r\n");
return FALSE;
}
return TRUE;
}
bool ready_to_reload(struct char_data *ch, struct obj_data *wielded, bool silent_mode)
{
switch (GET_OBJ_VAL(wielded, 0))
{
case WEAPON_TYPE_HEAVY_REP_XBOW:
case WEAPON_TYPE_LIGHT_REP_XBOW:
case WEAPON_TYPE_HEAVY_CROSSBOW:
/* RAPID RELOAD! */
if (HAS_FEAT(ch, FEAT_RAPID_RELOAD))
{
if (is_action_available(ch, atMOVE, FALSE))
{
if (reload_weapon(ch, wielded, silent_mode))
{
USE_MOVE_ACTION(ch); /* success! */
}
else
{
/* failed reload */
if (!silent_mode)
send_to_char(ch, "You need a move action to reload!\r\n");
return FALSE;
}
}
else
{
/* reloading requires a move action */
if (!silent_mode)
send_to_char(ch, "You need a move action to reload!\r\n");
return FALSE;
}
/* no rapid reload */
}
else if (is_action_available(ch, atSTANDARD, FALSE) &&
is_action_available(ch, atMOVE, FALSE))
{
if (reload_weapon(ch, wielded, silent_mode))
{
USE_FULL_ROUND_ACTION(ch); /* success! */
}
else
{
if (!silent_mode)
send_to_char(ch, "You need a full round action to reload!\r\n");
/* failed reload */
return FALSE;
}
}
else
{
/* reloading requires a full round action */
if (!silent_mode)
send_to_char(ch, "You need a full round action to reload!\r\n");
return FALSE;
}
break;
case WEAPON_TYPE_HAND_CROSSBOW:
case WEAPON_TYPE_LIGHT_CROSSBOW:
case WEAPON_TYPE_SLING:
/* RAPID RELOAD! */
if (HAS_FEAT(ch, FEAT_RAPID_RELOAD))
reload_weapon(ch, wielded, silent_mode);
else if (is_action_available(ch, atMOVE, FALSE))
{
if (reload_weapon(ch, wielded, silent_mode))
{
USE_MOVE_ACTION(ch); /* success! */
}
else
{
/* failed reload */
if (!silent_mode)
send_to_char(ch, "You need a move action to reload!\r\n");
return FALSE;
}
}
else
{
/* reloading requires a move action */
if (!silent_mode)
send_to_char(ch, "You need a move action to reload!\r\n");
return FALSE;
}
break;
default:
/* shouldn't get here */
if (!silent_mode)
send_to_char(ch, "The cucumber you are wielding is fully loaded! (error)\r\n");
return FALSE;
}
/* we made it! */
return TRUE;
}
/* trying to put shared proces between auto_reload_weapon
and do_reload:
disqualifiers such as position
appropriate weapon? (ranged + xbow type)
does this actually need reloading (still has ammo)
can reload (appropriate action available)
then run reload_weapon() for actual reloading
finally burn up appropriate action
* @returns: true if success */
bool process_load_weapon(struct char_data *ch, struct obj_data *weapon,
bool silent_mode)
{
/* position check */
if (GET_POS(ch) <= POS_STUNNED)
{
if (!silent_mode)
send_to_char(ch, "You are in no position to do this!\r \n");
return FALSE;
}
/* can't do this if stunned */
if (AFF_FLAGGED(ch, AFF_STUN) || char_has_mud_event(ch, eSTUNNED))
{
if (!silent_mode)
send_to_char(ch, "You can not reload a weapon while stunned!\r\n");
return FALSE;
}
/* ranged weapon? */
if (!is_using_ranged_weapon(ch, silent_mode))
{
return FALSE;
}
/* weapon that needs reloading? */
if (!is_reloading_weapon(ch, weapon, silent_mode))
{
return FALSE;
}
/* emptied out yet? */
if (!weapon_needs_reload(ch, weapon, silent_mode))
{
return FALSE;
}
/* check for actions, if available, reload */
if (!ready_to_reload(ch, weapon, silent_mode))
{
return FALSE;
}
/* success! */
send_to_char(ch, "You reload %s.\r\n", weapon->short_description);
if (FIGHTING(ch))
FIRING(ch) = TRUE;
return TRUE;
}
/* ranged-weapons, reload mechanic for slings, crossbows */
bool auto_reload_weapon(struct char_data *ch, bool silent_mode)
{
struct obj_data *wielded = is_using_ranged_weapon(ch, silent_mode);
if (!process_load_weapon(ch, wielded, silent_mode))
return FALSE;
return TRUE;
}
#define MAX_AMMO_INSIDE_WEAPON 5 // unused
bool reload_weapon(struct char_data *ch, struct obj_data *wielded, bool silent_mode)
{
int load_amount = 0;
switch (GET_OBJ_VAL(wielded, 0))
{
case WEAPON_TYPE_HEAVY_REP_XBOW:
load_amount = 5;
break;
case WEAPON_TYPE_LIGHT_REP_XBOW:
load_amount = 3;
break;
case WEAPON_TYPE_HAND_CROSSBOW:
case WEAPON_TYPE_HEAVY_CROSSBOW:
case WEAPON_TYPE_LIGHT_CROSSBOW:
case WEAPON_TYPE_SLING:
load_amount = 1;
break;
default:
return FALSE;
}
/* load her up! Object Value 5 is "loaded status" */
GET_OBJ_VAL(wielded, 5) = load_amount;
/* if we are in combat, let's make sure we start firing! */
if (FIGHTING(ch))
FIRING(ch) = TRUE;
return TRUE;
}
/* this function checks if weapon is loaded (like crossbows) */
bool weapon_is_loaded(struct char_data *ch, struct obj_data *wielded, bool silent)
{
if (!IS_NPC(ch) && PRF_FLAGGED(ch, PRF_AUTORELOAD) && FIGHTING(ch))
silent = TRUE; /* ornir suggested this */
if (GET_OBJ_VAL(wielded, 5) <= 0)
{ /* object value 5 is for loaded status */
if (!silent)
send_to_char(ch, "You have to reload your weapon!\r\n");
FIRING(ch) = FALSE;
return FALSE;
}
return TRUE;
}
/* this function will check to make sure ammo is ready for firing */
bool has_ammo_in_pouch(struct char_data *ch, struct obj_data *wielded,
bool silent)
{
struct obj_data *ammo_pouch = GET_EQ(ch, WEAR_AMMO_POUCH);
if (!wielded)
{
if (!silent)
send_to_char(ch, "You have no weapon!\r\n");
FIRING(ch) = FALSE;
return FALSE;
}
if (!ammo_pouch)
{
if (!silent)
send_to_char(ch, "You have no ammo pouch!\r\n");
FIRING(ch) = FALSE;
return FALSE;
}
if (!ammo_pouch->contains)
{
if (!silent)
send_to_char(ch, "Your ammo pouch is empty!\r\n");
FIRING(ch) = FALSE;
return FALSE;
}
if (GET_OBJ_TYPE(ammo_pouch->contains) != ITEM_MISSILE)
{
if (!silent)
send_to_char(ch, "Your ammo pouch needs to be filled with only ammo!\r\n");
FIRING(ch) = FALSE;
return FALSE;
}
switch (GET_OBJ_VAL(ammo_pouch->contains, 0))
{
case AMMO_TYPE_ARROW:
switch (GET_OBJ_VAL(wielded, 0))
{
case WEAPON_TYPE_LONG_BOW:
case WEAPON_TYPE_SHORT_BOW:
case WEAPON_TYPE_COMPOSITE_LONGBOW:
case WEAPON_TYPE_COMPOSITE_LONGBOW_2:
case WEAPON_TYPE_COMPOSITE_LONGBOW_3:
case WEAPON_TYPE_COMPOSITE_LONGBOW_4:
case WEAPON_TYPE_COMPOSITE_LONGBOW_5:
case WEAPON_TYPE_COMPOSITE_SHORTBOW:
case WEAPON_TYPE_COMPOSITE_SHORTBOW_2:
case WEAPON_TYPE_COMPOSITE_SHORTBOW_3:
case WEAPON_TYPE_COMPOSITE_SHORTBOW_4:
case WEAPON_TYPE_COMPOSITE_SHORTBOW_5:
break;
default:
if (!silent)
act("Your $p requires a bow.", FALSE, ch, ammo_pouch->contains, NULL, TO_CHAR);
FIRING(ch) = FALSE;
return FALSE;
}
break;
case AMMO_TYPE_BOLT:
switch (GET_OBJ_VAL(wielded, 0))
{
case WEAPON_TYPE_HAND_CROSSBOW:
case WEAPON_TYPE_HEAVY_REP_XBOW:
case WEAPON_TYPE_LIGHT_REP_XBOW:
case WEAPON_TYPE_HEAVY_CROSSBOW:
case WEAPON_TYPE_LIGHT_CROSSBOW:
break;
default:
if (!silent)
act("Your $p requires a crossbow.", FALSE, ch, ammo_pouch->contains, NULL, TO_CHAR);
FIRING(ch) = FALSE;
return FALSE;
}
break;
case AMMO_TYPE_STONE:
switch (GET_OBJ_VAL(wielded, 0))
{
case WEAPON_TYPE_SLING:
break;
default:
if (!silent)
act("Your $p requires a sling.", FALSE, ch, ammo_pouch->contains, NULL, TO_CHAR);
FIRING(ch) = FALSE;
return FALSE;
}
break;
case AMMO_TYPE_DART:
switch (GET_OBJ_VAL(wielded, 0))
{
case WEAPON_TYPE_DART:
break;
default:
if (!silent)
act("Your $p requires a dart-gun.", FALSE, ch, ammo_pouch->contains, NULL, TO_CHAR);
FIRING(ch) = FALSE;
return FALSE;
}
break;
case AMMO_TYPE_UNDEFINED:
default:
if (!silent)
act("Your $p does not fit your weapon...", FALSE, ch, ammo_pouch->contains, NULL, TO_CHAR);
FIRING(ch) = FALSE;
return FALSE;
}
/* cleared all checks */
return TRUE;
}
/* ranged combat (archery, etc)
* this function will check for a ranged weapon, ammo and does
* a check of loaded-status (like x-bow) and "has_ammo_in_pouch" */
bool can_fire_ammo(struct char_data *ch, bool silent)
{
struct obj_data *wielded = NULL;
if (!(wielded = is_using_ranged_weapon(ch, silent)))
{
FIRING(ch) = FALSE;
return FALSE;
}
if (!has_ammo_in_pouch(ch, wielded, silent))
{
FIRING(ch) = FALSE;
return FALSE;
}
/* ranged weapons that need reloading such as crossbows */
/* this is handled in hit() now*
if (is_reloading_weapon(ch, wielded)) {
if (!weapon_is_loaded(ch, wielded, silent)) {
//a message is sent in weapon_is_loaded()
FIRING(ch) = FALSE;
return FALSE;
}
}
**/
/* ok! */
return TRUE;
}
/*check all wielded slots looking for ranged weapon*/
struct obj_data *is_using_ranged_weapon(struct char_data *ch, bool silent_mode)
{
struct obj_data *wielded = GET_EQ(ch, WEAR_WIELD_2H);
if (!wielded)
wielded = GET_EQ(ch, WEAR_WIELD_1);
if (!wielded)
wielded = GET_EQ(ch, WEAR_WIELD_OFFHAND);
if (!wielded)
{
if (!silent_mode)
send_to_char(ch, "You are not wielding a ranged weapon!\r\n");
return NULL;
}
if (IS_WILDSHAPED(ch) || IS_MORPHED(ch))
{
if (!silent_mode)
send_to_char(ch, "What?!!?\r\n");
return NULL;
}
if (IS_SET(weapon_list[GET_OBJ_VAL(wielded, 0)].weaponFlags, WEAPON_FLAG_RANGED))
return wielded;
if (!silent_mode)
send_to_char(ch, "You are not wielding a ranged weapon!\r\n");
return NULL;
}
/* is this ranged weapon the type that needs reloading? */
bool is_reloading_weapon(struct char_data *ch, struct obj_data *wielded, bool silent_mode)
{
/* value 0 = weapon define value */
switch (GET_OBJ_VAL(wielded, 0))
{
case WEAPON_TYPE_HEAVY_CROSSBOW:
case WEAPON_TYPE_HEAVY_REP_XBOW:
case WEAPON_TYPE_LIGHT_REP_XBOW:
case WEAPON_TYPE_LIGHT_CROSSBOW:
case WEAPON_TYPE_SLING:
case WEAPON_TYPE_HAND_CROSSBOW:
return TRUE;
}
if (!silent_mode)
send_to_char(ch, "This is not a ranged weapon that needs reloading!\r\n");
return FALSE;
}
/* more weapon flags we have to deal with */
/* can throw weapon, such as shuriken, throwing axes, etc */
//#define WEAPON_FLAG_THROWN (1 << 4)
/* Reach: You use a reach weapon to strike opponents 10 feet away, but you can't
* use it against an adjacent foe. */
//#define WEAPON_FLAG_REACH (1 << 5)
//#define WEAPON_FLAG_ENTANGLE (1 << 6)
/* Trip*: You can use a trip weapon to make trip attacks. If you are tripped
* during your own trip attempt, you can drop the weapon to avoid being tripped
* (*see FAQ/Errata.) */
//#define WEAPON_FLAG_TRIP (1 << 7)
/* Disarm: When you use a disarm weapon, you get a +2 bonus on Combat Maneuver
* Checks to disarm an enemy. */
//#define WEAPON_FLAG_DISARM (1 << 9)
/* Nonlethal: These weapons deal nonlethal damage (see Combat). */
//#define WEAPON_FLAG_NONLETHAL (1 << 10)
//#define WEAPON_FLAG_SLOW_RELOAD (1 << 11)
//#define WEAPON_FLAG_BALANCED (1 << 12)
//#define WEAPON_FLAG_CHARGE (1 << 13)
//#define WEAPON_FLAG_REPEATING (1 << 14)
//#define WEAPON_FLAG_TWO_HANDED (1 << 15)
/* Blocking: When you use this weapon to fight defensively, you gain a +1 shield
* bonus to AC. Source: Ultimate Combat. */
//#define WEAPON_FLAG_BLOCKING (1 << 17)
/* Brace: If you use a readied action to set a brace weapon against a charge,
* you deal double damage on a successful hit against a charging creature
* (see Combat). */
//#define WEAPON_FLAG_BRACING (1 << 18)
/* Deadly: When you use this weapon to deliver a coup de grace, it gains a +4
* bonus to damage when calculating the DC of the Fortitude saving throw to see
* whether the target of the coup de grace dies from the attack. The bonus is
* not added to the actual damage of the coup de grace attack.
* Source: Ultimate Combat. */
//#define WEAPON_FLAG_DEADLY (1 << 19)
/* Distracting: You gain a +2 bonus on Bluff skill checks to feint in combat
* while wielding this weapon. Source: Ultimate Combat. */
//#define WEAPON_FLAG_DISTRACTING (1 << 20)
/* Fragile: Weapons and armor with the fragile quality cannot take the beating
* that sturdier weapons can. A fragile weapon gains the broken condition if the
* wielder rolls a natural 1 on an attack roll with the weapon. If a fragile
* weapon is already broken, the roll of a natural 1 destroys it instead.
* Masterwork and magical fragile weapons and armor lack these flaws unless
* otherwise noted in the item description or the special material description.
* If a weapon gains the broken condition in this way, that weapon is considered
* to have taken damage equal to half its hit points +1. This damage is repaired
* either by something that addresses the effect that granted the weapon the
* broken condition (like quick clear in the case of firearm misfires or the
* Field Repair feat) or by the repair methods described in the broken condition.
* When an effect that grants the broken condition is removed, the weapon
* regains the hit points it lost when the broken condition was applied. Damage
* done by an attack against a weapon (such as from a sunder combat maneuver)
* cannot be repaired by an effect that removes the broken condition.
* Source: Ultimate Combat.*/
//#define WEAPON_FLAG_FRAGILE (1 << 21)
/* Grapple: On a successful critical hit with a weapon of this type, you can
* grapple the target of the attack. The wielder can then attempt a combat
* maneuver check to grapple his opponent as a free action. This grapple attempt
* does not provoke an attack of opportunity from the creature you are
* attempting to grapple if that creature is not threatening you. While you
* grapple the target with a grappling weapon, you can only move or damage the
* creature on your turn. You are still considered grappled, though you do not
* have to be adjacent to the creature to continue the grapple. If you move far
* enough away to be out of the weapon’s reach, you end the grapple with that
* action. Source: Ultimate Combat. */
//#define WEAPON_FLAG_GRAPPLING (1 << 22)
/* Performance: When wielding this weapon, if an attack or combat maneuver made
* with this weapon prompts a combat performance check, you gain a +2 bonus on
* that check. See Gladiator Weapons below for more information. */
//#define WEAPON_FLAG_PERFORMANCE (1 << 23)
/* ***Strength (#): This feature is usually only applied to ranged weapons (such
* as composite bows). Some weapons function better in the hands of stronger
* users. All such weapons are made with a particular Strength rating (that is,
* each requires a minimum Strength modifier to use with proficiency and this
* number is included in parenthesis). If your Strength bonus is less than the
* strength rating of the weapon, you can't effectively use it, so you take a –2
* penalty on attacks with it. For example, the default (lowest form of)
* composite longbow requires a Strength modifier of +0 or higher to use with
* proficiency. A weapon with the Strength feature allows you to add your
* Strength bonus to damage, up to the maximum bonus indicated for the bow. Each
* point of Strength bonus granted by the bow adds 100 gp to its cost. If you
* have a penalty for low Strength, apply it to damage rolls when you use a
* composite longbow. Editor's Note: The "Strength" weapon feature was 'created'
* by d20pfsrd.com as a shorthand note to the composite bow mechanics. This is
* not "Paizo" or "official" content. */
//#define WEAPON_FLAG_STRENGTH (1 << 24)
/* Sunder: When you use a sunder weapon, you get a +2 bonus on Combat Maneuver
* Checks to sunder attempts. */
//#define WEAPON_FLAG_SUNDER (1 << 25)
/* light weapons - necessary for some feats such as weapon finesse */
bool is_using_light_weapon(struct char_data *ch, struct obj_data *wielded)
{
if (!wielded) /* fists are light? i need to check this */
return TRUE;
if (GET_EQ(ch, WEAR_WIELD_OFFHAND) == wielded && HAS_FEAT(ch, FEAT_OVERSIZED_TWO_WEAPON_FIGHTING))
return TRUE;
if (GET_OBJ_SIZE(wielded) > GET_SIZE(ch))
return FALSE;
if (IS_SET(weapon_list[GET_OBJ_VAL(wielded, 0)].weaponFlags, WEAPON_FLAG_LIGHT))
return TRUE;
if (IS_SET(weapon_list[GET_OBJ_VAL(wielded, 0)].weaponFlags, WEAPON_FLAG_BALANCED))
return TRUE;
/* if you are a size classes bigger than the weapon, then it is light */
if (GET_SIZE(ch) - GET_OBJ_SIZE(wielded) >= 1)
return TRUE;
/* not a light weapon! */
return FALSE;
}
/* Double: You can use a double weapon to fight as if fighting with two weapons,
* but if you do, you incur all the normal attack penalties associated with
* fighting with two weapons, just as if you were using a one-handed weapon and
* a light weapon. You can choose to wield one end of a double weapon two-handed,
* but it cannot be used as a double weapon when wielded in this way—only one
* end of the weapon can be used in any given round. */
bool is_using_double_weapon(struct char_data *ch)
{
struct obj_data *wielded = GET_EQ(ch, WEAR_WIELD_2H);
/* we are going to say it is not enough that the weapon just be flagged
double, we also need the weapon to be a size-class larger than the player */
if (!wielded)
return FALSE;
if (GET_OBJ_SIZE(wielded) <= GET_SIZE(ch))
return FALSE;
if (IS_SET(weapon_list[GET_OBJ_VAL(wielded, 0)].weaponFlags, WEAPON_FLAG_DOUBLE))
return TRUE;
return FALSE;
}
/* end utility, start base set/load/init functions for weapons/armor */
static void setweapon(int type, const char *name, int numDice, int diceSize, int critRange, int critMult,
int weaponFlags, int cost, int damageTypes, int weight, int range, int weaponFamily, int size,
int material, int handle_type, int head_type, const char *description)
{
weapon_type[type] = strdup(name);
weapon_list[type].name = name;
weapon_list[type].numDice = numDice;
weapon_list[type].diceSize = diceSize;
weapon_list[type].critRange = critRange;
if (critMult == 2)
weapon_list[type].critMult = CRIT_X2;
else if (critMult == 3)
weapon_list[type].critMult = CRIT_X3;
else if (critMult == 4)
weapon_list[type].critMult = CRIT_X4;
else if (critMult == 5)
weapon_list[type].critMult = CRIT_X5;
else if (critMult == 6)
weapon_list[type].critMult = CRIT_X6;
weapon_list[type].weaponFlags = weaponFlags;
weapon_list[type].cost = cost;
weapon_list[type].damageTypes = damageTypes;
weapon_list[type].weight = weight;
weapon_list[type].range = range;
weapon_list[type].weaponFamily = weaponFamily;
weapon_list[type].size = size;
weapon_list[type].material = material;
weapon_list[type].handle_type = handle_type;
weapon_list[type].head_type = head_type;
weapon_list[type].description = description;
}
void initialize_weapons(int type)
{
weapon_list[type].name = "unused weapon";
weapon_list[type].description = "unused weapon";
weapon_list[type].numDice = 1;
weapon_list[type].diceSize = 1;
weapon_list[type].critRange = 0;
weapon_list[type].critMult = 1;
weapon_list[type].weaponFlags = 0;
weapon_list[type].cost = 0;
weapon_list[type].damageTypes = 0;
weapon_list[type].weight = 0;
weapon_list[type].range = 0;
weapon_list[type].weaponFamily = 0;
weapon_list[type].size = 0;
weapon_list[type].material = 0;
weapon_list[type].handle_type = 0;
weapon_list[type].head_type = 0;
}
void load_weapons(void)
{
int i = 0;
for (i = 0; i < NUM_WEAPON_TYPES; i++)
initialize_weapons(i);
/* (weapon num, name, numDamDice, sizeDamDice, critRange, critMult, weapon flags, cost,
* damageType, weight, range, weaponFamily, Size, material,
* handle, head) */
setweapon(WEAPON_TYPE_UNARMED, "knuckle", 1, 3, 0, 2, WEAPON_FLAG_SIMPLE, 2,
DAMAGE_TYPE_BLUDGEONING, 1, 0, WEAPON_FAMILY_MONK, SIZE_SMALL, MATERIAL_ORGANIC,
HANDLE_TYPE_GLOVE, HEAD_TYPE_FIST,
"A knuckle can be any type of unarmed weapon, such as a spiked gauntlet, brass knuckles, hand wraps, cesti, and so forth.");
setweapon(WEAPON_TYPE_DAGGER, "dagger", 1, 4, 1, 2, WEAPON_FLAG_THROWN | WEAPON_FLAG_SIMPLE, 2, DAMAGE_TYPE_PIERCING, 1, 10, WEAPON_FAMILY_SMALL_BLADE, SIZE_TINY,
MATERIAL_STEEL, HANDLE_TYPE_HILT, HEAD_TYPE_BLADE,
"A dagger has a blade that is about 1 foot in length.");
setweapon(WEAPON_TYPE_KNIFE, "knife", 1, 3, 1, 2, WEAPON_FLAG_THROWN | WEAPON_FLAG_SIMPLE, 2, DAMAGE_TYPE_PIERCING, 1, 10, WEAPON_FAMILY_SMALL_BLADE, SIZE_DIMINUTIVE,
MATERIAL_STEEL, HANDLE_TYPE_HILT, HEAD_TYPE_BLADE,
"A dagger has a blade that is about 1 foot in length.");
setweapon(WEAPON_TYPE_LIGHT_MACE, "light mace", 1, 6, 0, 2, WEAPON_FLAG_SIMPLE, 5,
DAMAGE_TYPE_BLUDGEONING, 4, 0, WEAPON_FAMILY_CLUB, SIZE_SMALL, MATERIAL_STEEL,
HANDLE_TYPE_HANDLE, HEAD_TYPE_HEAD,
"A light mace is made up of an ornate metal head attached to a simple wooden or metal shaft.");
setweapon(WEAPON_TYPE_SICKLE, "sickle", 1, 6, 0, 2, WEAPON_FLAG_SIMPLE | WEAPON_FLAG_TRIP, 6,
DAMAGE_TYPE_SLASHING, 2, 0, WEAPON_FAMILY_SMALL_BLADE, SIZE_SMALL, MATERIAL_STEEL,
HANDLE_TYPE_HANDLE, HEAD_TYPE_BLADE,
"A sickle is usually used for harvesting crops, but can also be used as a weapon. It has a curving C-shaped blade.");
setweapon(WEAPON_TYPE_CLUB, "club", 1, 6, 0, 2, WEAPON_FLAG_SIMPLE, 1,
DAMAGE_TYPE_BLUDGEONING, 3, 0, WEAPON_FAMILY_CLUB, SIZE_SMALL, MATERIAL_WOOD,
HANDLE_TYPE_HANDLE, HEAD_TYPE_HEAD,