Source

doom / src / p_hpspr.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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
// Emacs style mode select   -*- C++ -*- 
//-----------------------------------------------------------------------------
//
// $Id: p_hpspr.c 694 2010-07-09 03:07:45Z wesleyjohnson $
//
// Copyright (C) 1993-1996 by Raven Software, Corp.
// Portions Copyright (C) 1998-2000 by DooM Legacy Team.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
//
// $Log: p_hpspr.c,v $
// Revision 1.3  2001/05/27 13:42:47  bpereira
// no message
//
// Revision 1.2  2001/02/24 13:35:20  bpereira
// no message
//
//
//
// DESCRIPTION:
//   this file is include by P_pspr.c
//   it contain all heretic player sprite specific
//
//-----------------------------------------------------------------------------


// P_pspr.c
/*
#include "doomdef.h"
#include "g_game.h"
#include "p_local.h"
#include "r_main.h"
#include "r_state.h"
#include "s_sound.h"
#include "m_random.h"
*/
// Macros

#define LOWERSPEED FRACUNIT*6
#define RAISESPEED FRACUNIT*6
#define WEAPONBOTTOM 128*FRACUNIT
#define WEAPONTOP 32*FRACUNIT
#define MAGIC_JUNK 1234
#define MAX_MACE_SPOTS 8

mobjtype_t PuffType;

static int MaceSpotCount;
static struct
{
        fixed_t x;
        fixed_t y;
} MaceSpots[MAX_MACE_SPOTS];

fixed_t bulletslope;


weaponinfo_t wpnlev1info[NUMWEAPONS] =
{
        { // Staff
                am_noammo,              // ammo
                0,
                S_STAFFUP,              // upstate
                S_STAFFDOWN,            // downstate
                S_STAFFREADY,           // readystate
                S_STAFFATK1_1,          // atkstate
                S_STAFFATK1_1,          // holdatkstate
                S_NULL                  // flashstate
        },
        { // Gold wand
                am_goldwand,            // ammo
                USE_GWND_AMMO_1,
                S_GOLDWANDUP,           // upstate
                S_GOLDWANDDOWN,         // downstate
                S_GOLDWANDREADY,        // readystate
                S_GOLDWANDATK1_1,       // atkstate
                S_GOLDWANDATK1_1,       // holdatkstate
                S_NULL                  // flashstate
        },
        { // Crossbow
                am_crossbow,            // ammo
                USE_CBOW_AMMO_1,
                S_CRBOWUP,              // upstate
                S_CRBOWDOWN,            // downstate
                S_CRBOW1,               // readystate
                S_CRBOWATK1_1,          // atkstate
                S_CRBOWATK1_1,          // holdatkstate
                S_NULL                  // flashstate
        },
        { // Blaster
                am_blaster,             // ammo
                USE_BLSR_AMMO_1,
                S_BLASTERUP,            // upstate
                S_BLASTERDOWN,          // downstate
                S_BLASTERREADY,         // readystate
                S_BLASTERATK1_1,        // atkstate
                S_BLASTERATK1_3,        // holdatkstate
                S_NULL                  // flashstate
        },
        { // Skull rod
                am_skullrod,            // ammo
                USE_SKRD_AMMO_1,
                S_HORNRODUP,            // upstate
                S_HORNRODDOWN,          // downstate
                S_HORNRODREADY,         // readystae
                S_HORNRODATK1_1,        // atkstate
                S_HORNRODATK1_1,        // holdatkstate
                S_NULL                  // flashstate
        },
        { // Phoenix rod
                am_phoenixrod,          // ammo
                USE_PHRD_AMMO_1,
                S_PHOENIXUP,            // upstate
                S_PHOENIXDOWN,          // downstate
                S_PHOENIXREADY,         // readystate
                S_PHOENIXATK1_1,        // atkstate
                S_PHOENIXATK1_1,        // holdatkstate
                S_NULL                  // flashstate
        },
        { // Mace
                am_mace,                // ammo
                USE_MACE_AMMO_1,
                S_MACEUP,               // upstate
                S_MACEDOWN,             // downstate
                S_MACEREADY,            // readystate
                S_MACEATK1_1,           // atkstate
                S_MACEATK1_2,           // holdatkstate
                S_NULL                  // flashstate
        },
        { // Gauntlets
                am_noammo,              // ammo
                0,
                S_GAUNTLETUP,           // upstate
                S_GAUNTLETDOWN,         // downstate
                S_GAUNTLETREADY,        // readystate
                S_GAUNTLETATK1_1,       // atkstate
                S_GAUNTLETATK1_3,       // holdatkstate
                S_NULL                  // flashstate
        },
        { // Beak
                am_noammo,              // ammo
                0,
                S_BEAKUP,               // upstate
                S_BEAKDOWN,             // downstate
                S_BEAKREADY,            // readystate
                S_BEAKATK1_1,           // atkstate
                S_BEAKATK1_1,           // holdatkstate
                S_NULL                  // flashstate
        }
};

weaponinfo_t wpnlev2info[NUMWEAPONS] =
{
        { // Staff
                am_noammo,              // ammo
                0,
                S_STAFFUP2,             // upstate
                S_STAFFDOWN2,           // downstate
                S_STAFFREADY2_1,        // readystate
                S_STAFFATK2_1,          // atkstate
                S_STAFFATK2_1,          // holdatkstate
                S_NULL                  // flashstate
        },
        { // Gold wand
                am_goldwand,            // ammo
                USE_GWND_AMMO_2,
                S_GOLDWANDUP,           // upstate
                S_GOLDWANDDOWN,         // downstate
                S_GOLDWANDREADY,        // readystate
                S_GOLDWANDATK2_1,       // atkstate
                S_GOLDWANDATK2_1,       // holdatkstate
                S_NULL                  // flashstate
        },
        { // Crossbow
                am_crossbow,            // ammo
                USE_CBOW_AMMO_2,
                S_CRBOWUP,              // upstate
                S_CRBOWDOWN,            // downstate
                S_CRBOW1,               // readystate
                S_CRBOWATK2_1,          // atkstate
                S_CRBOWATK2_1,          // holdatkstate
                S_NULL                  // flashstate
        },
        { // Blaster
                am_blaster,             // ammo
                USE_BLSR_AMMO_2,
                S_BLASTERUP,            // upstate
                S_BLASTERDOWN,          // downstate
                S_BLASTERREADY,         // readystate
                S_BLASTERATK2_1,        // atkstate
                S_BLASTERATK2_3,        // holdatkstate
                S_NULL                  // flashstate
        },
        { // Skull rod
                am_skullrod,            // ammo
                USE_SKRD_AMMO_2,
                S_HORNRODUP,            // upstate
                S_HORNRODDOWN,          // downstate
                S_HORNRODREADY,         // readystae
                S_HORNRODATK2_1,        // atkstate
                S_HORNRODATK2_1,        // holdatkstate
                S_NULL                  // flashstate
        },
        { // Phoenix rod
                am_phoenixrod,          // ammo
                USE_PHRD_AMMO_2,
                S_PHOENIXUP,            // upstate
                S_PHOENIXDOWN,          // downstate
                S_PHOENIXREADY,         // readystate
                S_PHOENIXATK2_1,        // atkstate
                S_PHOENIXATK2_2,        // holdatkstate
                S_NULL                  // flashstate
        },
        { // Mace
                am_mace,                // ammo
                USE_MACE_AMMO_2,
                S_MACEUP,               // upstate
                S_MACEDOWN,             // downstate
                S_MACEREADY,            // readystate
                S_MACEATK2_1,           // atkstate
                S_MACEATK2_1,           // holdatkstate
                S_NULL                  // flashstate
        },
        { // Gauntlets
                am_noammo,              // ammo
                0,
                S_GAUNTLETUP2,          // upstate
                S_GAUNTLETDOWN2,        // downstate
                S_GAUNTLETREADY2_1,     // readystate
                S_GAUNTLETATK2_1,       // atkstate
                S_GAUNTLETATK2_3,       // holdatkstate
                S_NULL                  // flashstate
        },
        { // Beak
                am_noammo,              // ammo
                0,
                S_BEAKUP,               // upstate
                S_BEAKDOWN,             // downstate
                S_BEAKREADY,            // readystate
                S_BEAKATK2_1,           // atkstate
                S_BEAKATK2_1,           // holdatkstate
                S_NULL                  // flashstate
        }
};

//---------------------------------------------------------------------------
//
// PROC P_OpenWeapons
//
// Called at level load before things are loaded.
//
//---------------------------------------------------------------------------

void P_OpenWeapons(void)
{
        MaceSpotCount = 0;
}

//---------------------------------------------------------------------------
//
// PROC P_AddMaceSpot
//
//---------------------------------------------------------------------------

void P_AddMaceSpot(mapthing_t *mthing)
{
        if(MaceSpotCount == MAX_MACE_SPOTS)
        {
                I_Error("Too many mace spots.");
        }
        MaceSpots[MaceSpotCount].x = mthing->x<<FRACBITS;
        MaceSpots[MaceSpotCount].y = mthing->y<<FRACBITS;
        MaceSpotCount++;
}

//---------------------------------------------------------------------------
//
// PROC P_RepositionMace
//
// Chooses the next spot to place the mace.
//
//---------------------------------------------------------------------------

void P_RepositionMace(mobj_t *mo)
{
        int spot;
        subsector_t *ss;

        P_UnsetThingPosition(mo);
        spot = P_Random()%MaceSpotCount;
        mo->x = MaceSpots[spot].x;
        mo->y = MaceSpots[spot].y;
        ss = R_PointInSubsector(mo->x, mo->y);
        mo->z = mo->floorz = ss->sector->floorheight;
        mo->ceilingz = ss->sector->ceilingheight;
        P_SetThingPosition(mo);
}

//---------------------------------------------------------------------------
//
// PROC P_CloseWeapons
//
// Called at level load after things are loaded.
//
//---------------------------------------------------------------------------

void P_CloseWeapons(void)
{
        int spot;

        if(!MaceSpotCount)
        { // No maces placed
                return;
        }
        if(!cv_deathmatch.value && P_Random() < 64)
        { // Sometimes doesn't show up if not in deathmatch
                return;
        }
        spot = P_Random()%MaceSpotCount;
        P_SpawnMobj(MaceSpots[spot].x, MaceSpots[spot].y, ONFLOORZ, MT_WMACE);
}

//---------------------------------------------------------------------------
//
// PROC P_ActivateBeak
//
//---------------------------------------------------------------------------

void P_ActivateBeak(player_t *player)
{
        player->pendingweapon = wp_nochange;
        player->readyweapon = wp_beak;
        player->psprites[ps_weapon].sy = WEAPONTOP;
        P_SetPsprite(player, ps_weapon, S_BEAKREADY);
}

//---------------------------------------------------------------------------
//
// PROC P_PostChickenWeapon
//
//---------------------------------------------------------------------------

void P_PostChickenWeapon(player_t *player, weapontype_t weapon)
{
        if(weapon == wp_beak)
        { // Should never happen
                weapon = wp_staff;
        }
        player->pendingweapon = wp_nochange;
        player->readyweapon = weapon;
        player->psprites[ps_weapon].sy = WEAPONBOTTOM;
        P_SetPsprite(player, ps_weapon, wpnlev1info[weapon].upstate);
}

//---------------------------------------------------------------------------
//
// PROC P_UpdateBeak
//
//---------------------------------------------------------------------------

void P_UpdateBeak(player_t *player, pspdef_t *psp)
{
        psp->sy = WEAPONTOP+(player->chickenPeck<<(FRACBITS-1));
}

//---------------------------------------------------------------------------
//
// PROC A_BeakReady
//
//---------------------------------------------------------------------------

void A_BeakReady(player_t *player, pspdef_t *psp)
{
        if(player->cmd.buttons&BT_ATTACK)
        { // Chicken beak attack
                player->attackdown = true;
                P_SetMobjState(player->mo, S_CHICPLAY_ATK1);
                if(player->powers[pw_weaponlevel2])
                {
                        P_SetPsprite(player, ps_weapon, S_BEAKATK2_1);
                }
                else
                {
                        P_SetPsprite(player, ps_weapon, S_BEAKATK1_1);
                }
                P_NoiseAlert(player->mo, player->mo);
        }
        else
        {
                if(player->mo->state == &states[S_CHICPLAY_ATK1])
                { // Take out of attack state
                        P_SetMobjState(player->mo, S_CHICPLAY);
                }
                player->attackdown = false;
        }
}

//---------------------------------------------------------------------------
//
// PROC A_BeakRaise
//
//---------------------------------------------------------------------------

void A_BeakRaise(player_t *player, pspdef_t *psp)
{
        psp->sy = WEAPONTOP;
        P_SetPsprite(player, ps_weapon,
                wpnlev1info[player->readyweapon].readystate);
}

//****************************************************************************
//
// WEAPON ATTACKS
//
//****************************************************************************

//----------------------------------------------------------------------------
//
// PROC A_BeakAttackPL1
//
//----------------------------------------------------------------------------

void A_BeakAttackPL1(player_t *player, pspdef_t *psp)
{
        angle_t angle;
        int damage;
        int slope;

        damage = 1+(P_Random()&3);
        angle = player->mo->angle;
        slope = P_AimLineAttack(player->mo, angle, MELEERANGE);
//      PuffType = MT_BEAKPUFF;
        P_LineAttack(player->mo, angle, MELEERANGE, slope, damage);
        // lar_linetarget returned by P_LineAttack
        if(lar_linetarget)
        {
                player->mo->angle = R_PointToAngle2(player->mo->x,
                        player->mo->y, lar_linetarget->x, lar_linetarget->y);
        }
        S_StartSound(player->mo, sfx_chicpk1+(P_Random()%3));
        player->chickenPeck = 12;
        psp->tics -= P_Random()&7;
}

//----------------------------------------------------------------------------
//
// PROC A_BeakAttackPL2
//
//----------------------------------------------------------------------------

void A_BeakAttackPL2(player_t *player, pspdef_t *psp)
{
        angle_t angle;
        int damage;
        int slope;

        damage = HITDICE(4);
        angle = player->mo->angle;
        slope = P_AimLineAttack(player->mo, angle, MELEERANGE);
        PuffType = MT_BEAKPUFF;
        P_LineAttack(player->mo, angle, MELEERANGE, slope, damage);
        // lar_linetarget returned by P_LineAttack
        if(lar_linetarget)
        {
                player->mo->angle = R_PointToAngle2(player->mo->x,
                        player->mo->y, lar_linetarget->x, lar_linetarget->y);
        }
        S_StartSound(player->mo, sfx_chicpk1+(P_Random()%3));
        player->chickenPeck = 12;
        psp->tics -= P_Random()&3;
}

//----------------------------------------------------------------------------
//
// PROC A_StaffAttackPL1
//
//----------------------------------------------------------------------------

void A_StaffAttackPL1(player_t *player, pspdef_t *psp)
{
        angle_t angle;
        int damage;
        int slope;

        damage = 5+(P_Random()&15);
        angle = player->mo->angle;
        angle += P_SignedRandom()<<18;
        slope = P_AimLineAttack(player->mo, angle, MELEERANGE);
        PuffType = MT_STAFFPUFF;
        P_LineAttack(player->mo, angle, MELEERANGE, slope, damage);
        // lar_linetarget returned by P_LineAttack
        if(lar_linetarget)
        {
                //S_StartSound(player->mo, sfx_stfhit);
                // turn to face target
                player->mo->angle = R_PointToAngle2(player->mo->x,
                        player->mo->y, lar_linetarget->x, lar_linetarget->y);
        }
}

//----------------------------------------------------------------------------
//
// PROC A_StaffAttackPL2
//
//----------------------------------------------------------------------------

void A_StaffAttackPL2(player_t *player, pspdef_t *psp)
{
        angle_t angle;
        int damage;
        int slope;

        // P_inter.c:P_DamageMobj() handles target momentums
        damage = 18+(P_Random()&63);
        angle = player->mo->angle;
        angle += P_SignedRandom()<<18;
        slope = P_AimLineAttack(player->mo, angle, MELEERANGE);
        PuffType = MT_STAFFPUFF2;
        P_LineAttack(player->mo, angle, MELEERANGE, slope, damage);
        // lar_linetarget returned by P_LineAttack
        if(lar_linetarget)
        {
                //S_StartSound(player->mo, sfx_stfpow);
                // turn to face target
                player->mo->angle = R_PointToAngle2(player->mo->x,
                        player->mo->y, lar_linetarget->x, lar_linetarget->y);
        }
}

//----------------------------------------------------------------------------
//
// PROC A_FireBlasterPL1
//
//----------------------------------------------------------------------------

void A_FireBlasterPL1(player_t *player, pspdef_t *psp)
{
    mobj_t *mo;
    angle_t angle;
    int damage;
    
    mo = player->mo;
    S_StartSound(mo, sfx_gldhit);
    player->ammo[am_blaster] -= USE_BLSR_AMMO_1;
    P_BulletSlope(mo);
    damage = HITDICE(4);
    angle = mo->angle;
    if(player->refire)
        angle += P_SignedRandom()<<18;
    PuffType = MT_BLASTERPUFF1;
    P_LineAttack(mo, angle, MISSILERANGE, bulletslope, damage);
    S_StartSound(player->mo, sfx_blssht);
}

//----------------------------------------------------------------------------
//
// PROC P_BlasterMobjThinker
//
// Thinker for the ultra-fast blaster PL2 ripper-spawning missile.
//
//----------------------------------------------------------------------------

void P_BlasterMobjThinker(mobj_t *mobj)
{
        int i;
        fixed_t xfrac;
        fixed_t yfrac;
        fixed_t zfrac;
        fixed_t z;
        boolean changexy;

        // Handle movement
        if(mobj->momx || mobj->momy ||
           (mobj->z != mobj->floorz) || mobj->momz)
        {
                xfrac = mobj->momx>>3;
                yfrac = mobj->momy>>3;
                zfrac = mobj->momz>>3;
                changexy = xfrac || yfrac;
                for(i = 0; i < 8; i++)
                {
                        if(changexy)
                        {
                                if(!P_TryMove(mobj, mobj->x+xfrac, mobj->y+yfrac, true))
                                { // Blocked move
                                        P_ExplodeMissile(mobj);
                                        return;
                                }
                        }
                        mobj->z += zfrac;
                        if(mobj->z <= mobj->floorz)
                        { // Hit the floor
                                mobj->z = mobj->floorz;
                                P_HitFloor(mobj);
                                P_ExplodeMissile(mobj);
                                return;
                        }
                        if(mobj->z+mobj->height > mobj->ceilingz)
                        { // Hit the ceiling
                                mobj->z = mobj->ceilingz-mobj->height;
                                P_ExplodeMissile(mobj);
                                return;
                        }
                        if(changexy && (P_Random() < 64))
                        {
                                z = mobj->z-8*FRACUNIT;
                                if(z < mobj->floorz)
                                {
                                        z = mobj->floorz;
                                }
                                P_SpawnMobj(mobj->x, mobj->y, z, MT_BLASTERSMOKE);
                        }
                }
        }
        // Advance the state
        if(mobj->tics != -1)
        {
                mobj->tics--;
                while(!mobj->tics)
                {
                        if(!P_SetMobjState(mobj, mobj->state->nextstate))
                        { // mobj was removed
                                return;
                        }
                }
        }
}

//----------------------------------------------------------------------------
//
// PROC A_FireBlasterPL2
//
//----------------------------------------------------------------------------

void A_FireBlasterPL2(player_t *player, pspdef_t *psp)
{
        mobj_t *mo;

        player->ammo[am_blaster] -=
                cv_deathmatch.value ? USE_BLSR_AMMO_1 : USE_BLSR_AMMO_2;
        mo = P_SpawnPlayerMissile(player->mo, MT_BLASTERFX1);
        if( mo )
            mo->thinker.function.acp1 = (actionf_p1)P_BlasterMobjThinker;

        S_StartSound(player->mo, sfx_blssht);
}

//----------------------------------------------------------------------------
//
// PROC A_FireGoldWandPL1
//
//----------------------------------------------------------------------------

void A_FireGoldWandPL1(player_t *player, pspdef_t *psp)
{
    mobj_t *mo;
    angle_t angle;
    int damage;
    
    mo = player->mo;
    player->ammo[am_goldwand] -= USE_GWND_AMMO_1;
    P_BulletSlope(mo);
    damage = 7+(P_Random()&7);
    angle = mo->angle;
    if(player->refire)
        angle += P_SignedRandom()<<18;
    PuffType = MT_GOLDWANDPUFF1;
    P_LineAttack(mo, angle, MISSILERANGE, bulletslope, damage);
    S_StartSound(player->mo, sfx_gldhit);
}

//----------------------------------------------------------------------------
//
// PROC A_FireGoldWandPL2
//
//----------------------------------------------------------------------------

void A_FireGoldWandPL2(player_t *player, pspdef_t *psp)
{
        int i;
        mobj_t *mo;
        angle_t angle;
        int damage;
        fixed_t momz;

        mo = player->mo;
        player->ammo[am_goldwand] -=
                cv_deathmatch.value ? USE_GWND_AMMO_1 : USE_GWND_AMMO_2;
        PuffType = MT_GOLDWANDPUFF2;
        P_BulletSlope(mo);
        momz = FixedMul(mobjinfo[MT_GOLDWANDFX2].speed, bulletslope);
//      P_SpawnMissileAngle(mo, MT_GOLDWANDFX2, mo->angle-(ANG45/8), momz);
//      P_SpawnMissileAngle(mo, MT_GOLDWANDFX2, mo->angle+(ANG45/8), momz);
        angle = mo->angle-(ANG45/8);
        for(i = 0; i < 5; i++)
        {
                damage = 1+(P_Random()&7);
                P_LineAttack(mo, angle, MISSILERANGE, bulletslope, damage);
                angle += ((ANG45/8)*2)/4;
        }
        S_StartSound(player->mo, sfx_gldhit);
}

//----------------------------------------------------------------------------
//
// PROC A_FireMacePL1B
//
//----------------------------------------------------------------------------

void A_FireMacePL1B(player_t *player, pspdef_t *psp)
{
        mobj_t *pmo;
        mobj_t *ball;
        angle_t angle;

        if(player->ammo[am_mace] < USE_MACE_AMMO_1)
        {
                return;
        }
        player->ammo[am_mace] -= USE_MACE_AMMO_1;
        pmo = player->mo;
        ball = P_SpawnMobj(pmo->x, pmo->y, pmo->z+28*FRACUNIT
                - FOOTCLIPSIZE*((pmo->flags2&MF2_FEETARECLIPPED) != 0), MT_MACEFX2);
        ball->momz = 2*FRACUNIT+((player->aiming)<<(FRACBITS-5));
        angle = pmo->angle;
        ball->target = pmo;
        ball->angle = angle;
        ball->z += (player->aiming)<<(FRACBITS-4);
        angle >>= ANGLETOFINESHIFT;
        ball->momx = (pmo->momx>>1)
                +FixedMul(ball->info->speed, finecosine[angle]);
        ball->momy = (pmo->momy>>1)
                +FixedMul(ball->info->speed, finesine[angle]);
        S_StartSound(ball, sfx_lobsht);
        P_CheckMissileSpawn(ball);
}

//----------------------------------------------------------------------------
//
// PROC A_FireMacePL1
//
//----------------------------------------------------------------------------

void A_FireMacePL1(player_t *player, pspdef_t *psp)
{
        mobj_t *ball;

        if(P_Random() < 28)
        {
                A_FireMacePL1B(player, psp);
                return;
        }
        if(player->ammo[am_mace] < USE_MACE_AMMO_1)
        {
                return;
        }
        player->ammo[am_mace] -= USE_MACE_AMMO_1;
        psp->sx = ((P_Random()&3)-2)*FRACUNIT;
        psp->sy = WEAPONTOP+(P_Random()&3)*FRACUNIT;
        ball = P_SPMAngle(player->mo, MT_MACEFX1, player->mo->angle
                                                  +(((P_Random()&7)-4)<<24));
        if(ball)
        {
                ball->special1 = 16; // tics till dropoff
        }
}

//----------------------------------------------------------------------------
//
// PROC A_MacePL1Check
//
//----------------------------------------------------------------------------

void A_MacePL1Check(mobj_t *ball)
{
        angle_t angle;

        if(ball->special1 == 0)
        {
                return;
        }
        ball->special1 -= 4;
        if(ball->special1 > 0)
        {
                return;
        }
        ball->special1 = 0;
        ball->flags2 |= MF2_LOGRAV;
        angle = ball->angle>>ANGLETOFINESHIFT;
        ball->momx = FixedMul(7*FRACUNIT, finecosine[angle]);
        ball->momy = FixedMul(7*FRACUNIT, finesine[angle]);
        ball->momz -= ball->momz>>1;
}

//----------------------------------------------------------------------------
//
// PROC A_MaceBallImpact
//
//----------------------------------------------------------------------------

void A_MaceBallImpact(mobj_t *ball)
{
        if((ball->z <= ball->floorz) && (P_HitFloor(ball) != FLOOR_SOLID))
        { // Landed in some sort of liquid
                P_RemoveMobj(ball);
                return;
        }
        if((ball->health != MAGIC_JUNK) && (ball->z <= ball->floorz)
                && ball->momz)
        { // Bounce
                ball->health = MAGIC_JUNK;
                ball->momz = (ball->momz*192)>>8;
                ball->flags2 &= ~MF2_FLOORBOUNCE;
                P_SetMobjState(ball, ball->info->spawnstate);
                S_StartSound(ball, sfx_bounce);
        }
        else
        { // Explode
                ball->flags |= MF_NOGRAVITY;
                ball->flags2 &= ~MF2_LOGRAV;
                S_StartSound(ball, sfx_lobhit);
        }
}

//----------------------------------------------------------------------------
//
// PROC A_MaceBallImpact2
//
//----------------------------------------------------------------------------

void A_MaceBallImpact2(mobj_t *ball)
{
        mobj_t *tiny;
        angle_t angle;

        if((ball->z <= ball->floorz) && (P_HitFloor(ball) != FLOOR_SOLID))
        { // Landed in some sort of liquid
                P_RemoveMobj(ball);
                return;
        }
        if((ball->z != ball->floorz) || (ball->momz < 2*FRACUNIT))
        { // Explode
                ball->momx = ball->momy = ball->momz = 0;
                ball->flags |= MF_NOGRAVITY;
                ball->flags2 &= ~(MF2_LOGRAV|MF2_FLOORBOUNCE);
        }
        else
        { // Bounce
                ball->momz = (ball->momz*192)>>8;
                P_SetMobjState(ball, ball->info->spawnstate);

                tiny = P_SpawnMobj(ball->x, ball->y, ball->z, MT_MACEFX3);
                angle = ball->angle+ANG90;
                tiny->target = ball->target;
                tiny->angle = angle;
                angle >>= ANGLETOFINESHIFT;
                tiny->momx = (ball->momx>>1)+FixedMul(ball->momz-FRACUNIT,
                        finecosine[angle]);
                tiny->momy = (ball->momy>>1)+FixedMul(ball->momz-FRACUNIT,
                        finesine[angle]);
                tiny->momz = ball->momz;
                P_CheckMissileSpawn(tiny);

                tiny = P_SpawnMobj(ball->x, ball->y, ball->z, MT_MACEFX3);
                angle = ball->angle-ANG90;
                tiny->target = ball->target;
                tiny->angle = angle;
                angle >>= ANGLETOFINESHIFT;
                tiny->momx = (ball->momx>>1)+FixedMul(ball->momz-FRACUNIT,
                        finecosine[angle]);
                tiny->momy = (ball->momy>>1)+FixedMul(ball->momz-FRACUNIT,
                        finesine[angle]);
                tiny->momz = ball->momz;
                P_CheckMissileSpawn(tiny);
        }
}

//----------------------------------------------------------------------------
//
// PROC A_FireMacePL2
//
//----------------------------------------------------------------------------

void A_FireMacePL2(player_t *player, pspdef_t *psp)
{
        mobj_t *mo;

        player->ammo[am_mace] -=
                cv_deathmatch.value ? USE_MACE_AMMO_1 : USE_MACE_AMMO_2;
        mo = P_SpawnPlayerMissile(player->mo, MT_MACEFX4);
        if(mo)
        {
                mo->momx += player->mo->momx;
                mo->momy += player->mo->momy;
                mo->momz = 2*FRACUNIT+((player->aiming)<<(FRACBITS-5));
	        // lar_linetarget returned by P_AimLineAttack, via P_SPMAngle
                if(lar_linetarget)
                {
                        mo->tracer = lar_linetarget;
                }
        }
        S_StartSound(player->mo, sfx_lobsht);
}

//----------------------------------------------------------------------------
//
// PROC A_DeathBallImpact
//
//----------------------------------------------------------------------------

void A_DeathBallImpact(mobj_t *ball)
{
        int i;
        mobj_t *target;
        angle_t angle = 0;
        boolean newAngle;

        if((ball->z <= ball->floorz) && (P_HitFloor(ball) != FLOOR_SOLID))
        { // Landed in some sort of liquid
                P_RemoveMobj(ball);
                return;
        }
        if((ball->z <= ball->floorz) && ball->momz)
        { // Bounce
                newAngle = false;
                target = ball->tracer;
                if(target)
                {
                        if(!(target->flags&MF_SHOOTABLE))
                        { // Target died
                                ball->tracer = 0;
                        }
                        else
                        { // Seek
                                angle = R_PointToAngle2(ball->x, ball->y,
                                        target->x, target->y);
                                newAngle = true;
                        }
                }
                else
                { // Find new target
                        for(i = 0; i < 16; i++)
                        {
                                P_AimLineAttack(ball, angle, 10*64*FRACUNIT);
			        // lar_linetarget returned by P_AimLineAttack
                                if(lar_linetarget && ball->target != lar_linetarget)
                                {
                                        ball->tracer = lar_linetarget;
                                        angle = R_PointToAngle2(ball->x, ball->y,
                                                lar_linetarget->x, lar_linetarget->y);
                                        newAngle = true;
                                        break;
                                }
                                angle += ANG45/2;
                        }
                }
                if(newAngle)
                {
                        ball->angle = angle;
                        angle >>= ANGLETOFINESHIFT;
                        ball->momx = FixedMul(ball->info->speed, finecosine[angle]);
                        ball->momy = FixedMul(ball->info->speed, finesine[angle]);
                }
                P_SetMobjState(ball, ball->info->spawnstate);
                S_StartSound(ball, sfx_pstop);
        }
        else
        { // Explode
                ball->flags |= MF_NOGRAVITY;
                ball->flags2 &= ~MF2_LOGRAV;
                S_StartSound(ball, sfx_phohit);
        }
}

//----------------------------------------------------------------------------
//
// PROC A_SpawnRippers
//
//----------------------------------------------------------------------------

void A_SpawnRippers(mobj_t *actor)
{
        int i;
        angle_t angle;
        mobj_t *ripper;

        for(i = 0; i < 8; i++)
        {
                ripper = P_SpawnMobj(actor->x, actor->y, actor->z, MT_RIPPER);
                angle = i*ANG45;
                ripper->target = actor->target;
                ripper->angle = angle;
                angle >>= ANGLETOFINESHIFT;
                ripper->momx = FixedMul(ripper->info->speed, finecosine[angle]);
                ripper->momy = FixedMul(ripper->info->speed, finesine[angle]);
                P_CheckMissileSpawn(ripper);
        }
}

//----------------------------------------------------------------------------
//
// PROC A_FireCrossbowPL1
//
//----------------------------------------------------------------------------

void A_FireCrossbowPL1(player_t *player, pspdef_t *psp)
{
        mobj_t *pmo;

        pmo = player->mo;
        player->ammo[am_crossbow] -= USE_CBOW_AMMO_1;
        P_SpawnPlayerMissile(pmo, MT_CRBOWFX1);
        P_SPMAngle(pmo, MT_CRBOWFX3, pmo->angle-(ANG45/10));
        P_SPMAngle(pmo, MT_CRBOWFX3, pmo->angle+(ANG45/10));
}

//----------------------------------------------------------------------------
//
// PROC A_FireCrossbowPL2
//
//----------------------------------------------------------------------------

void A_FireCrossbowPL2(player_t *player, pspdef_t *psp)
{
        mobj_t *pmo;

        pmo = player->mo;
        player->ammo[am_crossbow] -=
                cv_deathmatch.value ? USE_CBOW_AMMO_1 : USE_CBOW_AMMO_2;
        P_SpawnPlayerMissile(pmo, MT_CRBOWFX2);
        P_SPMAngle(pmo, MT_CRBOWFX2, pmo->angle-(ANG45/10));
        P_SPMAngle(pmo, MT_CRBOWFX2, pmo->angle+(ANG45/10));
        P_SPMAngle(pmo, MT_CRBOWFX3, pmo->angle-(ANG45/5));
        P_SPMAngle(pmo, MT_CRBOWFX3, pmo->angle+(ANG45/5));
}

//----------------------------------------------------------------------------
//
// PROC A_BoltSpark
//
//----------------------------------------------------------------------------

void A_BoltSpark(mobj_t *bolt)
{
    mobj_t *spark;
    
    if(P_Random() > 50)
    {
        spark = P_SpawnMobj(bolt->x, bolt->y, bolt->z, MT_CRBOWFX4);
        spark->x += P_SignedRandom()<<10;
        spark->y += P_SignedRandom()<<10;
    }
}

//----------------------------------------------------------------------------
//
// PROC A_FireSkullRodPL1
//
//----------------------------------------------------------------------------

void A_FireSkullRodPL1(player_t *player, pspdef_t *psp)
{
        mobj_t *mo;

        if(player->ammo[am_skullrod] < USE_SKRD_AMMO_1)
        {
                return;
        }
        player->ammo[am_skullrod] -= USE_SKRD_AMMO_1;
        mo = P_SpawnPlayerMissile(player->mo, MT_HORNRODFX1);
        // Randomize the first frame
        if(mo && P_Random() > 128)
        {
                P_SetMobjState(mo, S_HRODFX1_2);
        }
}

//----------------------------------------------------------------------------
//
// PROC A_FireSkullRodPL2
//
// The special2 field holds the player number that shot the rain missile.
// The tracer field is used for the seeking routines, then as a counter
// for the sound looping.
//
//----------------------------------------------------------------------------

void A_FireSkullRodPL2(player_t *player, pspdef_t *psp)
{
    mobj_t *MissileMobj;

    player->ammo[am_skullrod] -=
        cv_deathmatch.value ? USE_SKRD_AMMO_1 : USE_SKRD_AMMO_2;
    MissileMobj = P_SpawnPlayerMissile(player->mo, MT_HORNRODFX2);
    // Use MissileMobj instead of the return value from
    // P_SpawnPlayerMissile because we need to give info to the mobj
    // even if it exploded immediately.
    if( MissileMobj )
    {
        if(multiplayer)
        { // Multi-player game
            MissileMobj->special2 = player-players;
        }
        else
        { // Always use red missiles in single player games
            MissileMobj->special2 = 2;
        }
        // lar_linetarget returned by P_AimLineAttack, via P_SPMAngle
        if(lar_linetarget)
            MissileMobj->tracer = lar_linetarget;
        
        S_StartSound(MissileMobj, sfx_hrnpow);
    }
}

//----------------------------------------------------------------------------
//
// PROC A_SkullRodPL2Seek
//
//----------------------------------------------------------------------------

void A_SkullRodPL2Seek(mobj_t *actor)
{
        P_SeekerMissile(actor, ANGLE_1*10, ANGLE_1*30);
}

//----------------------------------------------------------------------------
//
// PROC A_AddPlayerRain
//
//----------------------------------------------------------------------------

void A_AddPlayerRain(mobj_t *actor)
{
        int playerNum;
        player_t *player;

        playerNum = multiplayer ? actor->special2 : 0;
        if(!playeringame[playerNum])
        { // Player left the game
                return;
        }
        player = &players[playerNum];
        if(player->health <= 0)
        { // Player is dead
                return;
        }
        if(player->rain1 && player->rain2)
        { // Terminate an active rain
                if(player->rain1->health < player->rain2->health)
                {
                        if(player->rain1->health > 16)
                        {
                                player->rain1->health = 16;
                        }
                        player->rain1 = NULL;
                }
                else
                {
                        if(player->rain2->health > 16)
                        {
                                player->rain2->health = 16;
                        }
                        player->rain2 = NULL;
                }
        }
        // Add rain mobj to list
        if(player->rain1)
        {
                player->rain2 = actor;
        }
        else
        {
                player->rain1 = actor;
        }
}

//----------------------------------------------------------------------------
//
// PROC A_SkullRodStorm
//
//----------------------------------------------------------------------------

void A_SkullRodStorm(mobj_t *actor)
{
        fixed_t x;
        fixed_t y;
        mobj_t *mo;
        int playerNum;
        player_t *player;

        if(actor->health-- == 0)
        {
                P_SetMobjState(actor, S_NULL);
                playerNum = multiplayer ? actor->special2 : 0;
                if(!playeringame[playerNum])
                { // Player left the game
                        return;
                }
                player = &players[playerNum];
                if(player->health <= 0)
                { // Player is dead
                        return;
                }
                if(player->rain1 == actor)
                {
                        player->rain1 = NULL;
                }
                else if(player->rain2 == actor)
                {
                        player->rain2 = NULL;
                }
                return;
        }
        if(P_Random() < 25)
        { // Fudge rain frequency
                return;
        }
        x = actor->x+((P_Random()&127)-64)*FRACUNIT;
        y = actor->y+((P_Random()&127)-64)*FRACUNIT;
        mo = P_SpawnMobj(x, y, ONCEILINGZ, MT_RAINPLR1+actor->special2);
        mo->target = actor->target;
        mo->momx = 1; // Force collision detection
        mo->momz = -mo->info->speed;
        mo->special2 = actor->special2; // Transfer player number
        P_CheckMissileSpawn(mo);
        if(!(actor->special1&31))
        {
                S_StartSound(actor, sfx_ramrain);
        }
        actor->special1++;
}

//----------------------------------------------------------------------------
//
// PROC A_RainImpact
//
//----------------------------------------------------------------------------

void A_RainImpact(mobj_t *actor)
{
        if(actor->z > actor->floorz)
        {
                P_SetMobjState(actor, S_RAINAIRXPLR1_1+actor->special2);
        }
        else if(P_Random() < 40)
        {
                P_HitFloor(actor);
        }
}

//----------------------------------------------------------------------------
//
// PROC A_HideInCeiling
//
//----------------------------------------------------------------------------

void A_HideInCeiling(mobj_t *actor)
{
        actor->z = actor->ceilingz+4*FRACUNIT;
}

//----------------------------------------------------------------------------
//
// PROC A_FirePhoenixPL1
//
//----------------------------------------------------------------------------

void A_FirePhoenixPL1(player_t *player, pspdef_t *psp)
{
        angle_t angle;

        player->ammo[am_phoenixrod] -= USE_PHRD_AMMO_1;
        P_SpawnPlayerMissile(player->mo, MT_PHOENIXFX1);
        //P_SpawnPlayerMissile(player->mo, MT_MNTRFX2);
        angle = player->mo->angle+ANG180;
        angle >>= ANGLETOFINESHIFT;
        player->mo->momx += FixedMul(4*FRACUNIT, finecosine[angle]);
        player->mo->momy += FixedMul(4*FRACUNIT, finesine[angle]);
}

//----------------------------------------------------------------------------
//
// PROC A_PhoenixPuff
//
//----------------------------------------------------------------------------

void A_PhoenixPuff(mobj_t *actor)
{
        mobj_t *puff;
        angle_t angle;

        P_SeekerMissile(actor, ANGLE_1*5, ANGLE_1*10);
        puff = P_SpawnMobj(actor->x, actor->y, actor->z, MT_PHOENIXPUFF);
        angle = actor->angle+ANG90;
        angle >>= ANGLETOFINESHIFT;
        puff->momx = FixedMul(FRACUNIT*1.3, finecosine[angle]);
        puff->momy = FixedMul(FRACUNIT*1.3, finesine[angle]);
        puff->momz = 0;
        puff = P_SpawnMobj(actor->x, actor->y, actor->z, MT_PHOENIXPUFF);
        angle = actor->angle-ANG90;
        angle >>= ANGLETOFINESHIFT;
        puff->momx = FixedMul(FRACUNIT*1.3, finecosine[angle]);
        puff->momy = FixedMul(FRACUNIT*1.3, finesine[angle]);
        puff->momz = 0;
}

//----------------------------------------------------------------------------
//
// PROC A_InitPhoenixPL2
//
//----------------------------------------------------------------------------

void A_InitPhoenixPL2(player_t *player, pspdef_t *psp)
{
        player->flamecount = FLAME_THROWER_TICS;
}

//----------------------------------------------------------------------------
//
// PROC A_FirePhoenixPL2
//
// Flame thrower effect.
//
//----------------------------------------------------------------------------

void A_FirePhoenixPL2(player_t *player, pspdef_t *psp)
{
        mobj_t *mo;
        mobj_t *pmo;
        angle_t angle;
        fixed_t x, y, z;
        fixed_t slope;

        if(--player->flamecount == 0)
        { // Out of flame
                P_SetPsprite(player, ps_weapon, S_PHOENIXATK2_4);
                player->refire = 0;
                return;
        }
        pmo = player->mo;
        angle = pmo->angle;
        x = pmo->x+(P_SignedRandom()<<9);
        y = pmo->y+(P_SignedRandom()<<9);
        z = pmo->z+26*FRACUNIT+((player->aiming)<<FRACBITS)/173;
        if(pmo->flags2&MF2_FEETARECLIPPED)
        {
                z -= FOOTCLIPSIZE;
        }
        slope = AIMINGTOSLOPE(player->aiming);
        mo = P_SpawnMobj(x, y, z, MT_PHOENIXFX2);
        mo->target = pmo;
        mo->angle = angle;
        mo->momx = pmo->momx+FixedMul(mo->info->speed,
                finecosine[angle>>ANGLETOFINESHIFT]);
        mo->momy = pmo->momy+FixedMul(mo->info->speed,
                finesine[angle>>ANGLETOFINESHIFT]);
        mo->momz = FixedMul(mo->info->speed, slope);
        if(!player->refire || !(leveltime%38))
        {
                S_StartSound(player->mo, sfx_phopow);
        }
        P_CheckMissileSpawn(mo);
}

//----------------------------------------------------------------------------
//
// PROC A_ShutdownPhoenixPL2
//
//----------------------------------------------------------------------------

void A_ShutdownPhoenixPL2(player_t *player, pspdef_t *psp)
{
        player->ammo[am_phoenixrod] -= USE_PHRD_AMMO_2;
}

//----------------------------------------------------------------------------
//
// PROC A_FlameEnd
//
//----------------------------------------------------------------------------

void A_FlameEnd(mobj_t *actor)
{
        actor->momz += 1.5*FRACUNIT;
}

//----------------------------------------------------------------------------
//
// PROC A_FloatPuff
//
//----------------------------------------------------------------------------

void A_FloatPuff(mobj_t *puff)
{
        puff->momz += 1.8*FRACUNIT;
}

//---------------------------------------------------------------------------
//
// PROC A_GauntletAttack
//
//---------------------------------------------------------------------------

void A_GauntletAttack(player_t *player, pspdef_t *psp)
{
        angle_t angle;
        int damage;
        int slope;
        int randVal;
        fixed_t dist;

        psp->sx = ((P_Random()&3)-2)*FRACUNIT;
        psp->sy = WEAPONTOP+(P_Random()&3)*FRACUNIT;
        angle = player->mo->angle;
        if(player->powers[pw_weaponlevel2])
        {
                damage = HITDICE(2);
                dist = 4*MELEERANGE;
                angle += P_SignedRandom()<<17;
                PuffType = MT_GAUNTLETPUFF2;
        }
        else
        {
                damage = HITDICE(2);
                dist = MELEERANGE+1;
                angle += P_SignedRandom()<<18;
                PuffType = MT_GAUNTLETPUFF1;
        }
        slope = P_AimLineAttack(player->mo, angle, dist);
        P_LineAttack(player->mo, angle, dist, slope, damage);
        // lar_linetarget returned by P_LineAttack, P_AimLineAttack
        if(!lar_linetarget)
        {
                if(P_Random() > 64)
                {
                        player->extralight = !player->extralight;
                }
                S_StartSound(player->mo, sfx_gntful);
                return;
        }
        randVal = P_Random();
        if(randVal < 64)
        {
                player->extralight = 0;
        }
        else if(randVal < 160)
        {
                player->extralight = 1;
        }
        else
        {
                player->extralight = 2;
        }
        if(player->powers[pw_weaponlevel2])
        {
                P_GiveBody(player, damage>>1);
                S_StartSound(player->mo, sfx_gntpow);
        }
        else
        {
                S_StartSound(player->mo, sfx_gnthit);
        }
        // lar_linetarget returned by P_AimLineAttack, P_LineAttack
        // turn to face target
        angle = R_PointToAngle2(player->mo->x, player->mo->y,
                lar_linetarget->x, lar_linetarget->y);
        if(angle-player->mo->angle > ANG180)
        {
                if(angle-player->mo->angle < -ANG90/20)
                        player->mo->angle = angle+ANG90/21;
                else
                        player->mo->angle -= ANG90/20;
        }
        else
        {
                if(angle-player->mo->angle > ANG90/20)
                        player->mo->angle = angle-ANG90/21;
                else
                        player->mo->angle += ANG90/20;
        }
        player->mo->flags |= MF_JUSTATTACKED;
}