| 1 |
// |
| 2 |
// Copyright(C) 2022 by Ryan Krafnick |
| 3 |
// |
| 4 |
// This program is free software; you can redistribute it and/or |
| 5 |
// modify it under the terms of the GNU General Public License |
| 6 |
// as published by the Free Software Foundation; either version 2 |
| 7 |
// of the License, or (at your option) any later version. |
| 8 |
// |
| 9 |
// This program is distributed in the hope that it will be useful, |
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
// GNU General Public License for more details. |
| 13 |
// |
| 14 |
// DESCRIPTION: |
| 15 |
// DSDA Quake |
| 16 |
// |
| 17 |
|
| 18 |
#include "doomstat.h" |
| 19 |
#include "m_random.h" |
| 20 |
#include "p_maputl.h" |
| 21 |
#include "p_inter.h" |
| 22 |
#include "p_spec.h" |
| 23 |
#include "p_tick.h" |
| 24 |
|
| 25 |
#include "dsda/global.h" |
| 26 |
|
| 27 |
// TODO: move here |
| 28 |
extern int localQuakeHappening[MAX_MAXPLAYERS]; |
| 29 |
|
| 30 |
// The unit of quake distance is 64 (2^6) |
| 31 |
#define DISTBITS 6 |
| 32 |
|
| 33 |
void dsda_ResetQuakes(void) { |
| 34 |
memset(localQuakeHappening, 0, g_maxplayers * sizeof(*localQuakeHappening)); |
| 35 |
} |
| 36 |
|
| 37 |
void dsda_UpdateQuakeIntensity(int player_num, int intensity) { |
| 38 |
localQuakeHappening[player_num] = intensity; |
| 39 |
} |
| 40 |
|
| 41 |
void dsda_UpdateQuake(quake_t* quake) { |
| 42 |
int i; |
| 43 |
|
| 44 |
for (i = 0; i < g_maxplayers; ++i) { |
| 45 |
mobj_t* mo; |
| 46 |
fixed_t dist; |
| 47 |
|
| 48 |
if (!playeringame[i] || players[i].cheats & CF_NOCLIP) |
| 49 |
continue; |
| 50 |
|
| 51 |
mo = players[i].mo; |
| 52 |
dist = P_AproxDistance(quake->location->x - mo->x, |
| 53 |
quake->location->y - mo->y) >> (FRACBITS + DISTBITS); |
| 54 |
|
| 55 |
// TODO: This won't get changed until a quake ends if we leave the radius |
| 56 |
if (dist < quake->tremor_radius) |
| 57 |
dsda_UpdateQuakeIntensity(i, quake->intensity); |
| 58 |
|
| 59 |
if (dist < quake->damage_radius && mo->z <= mo->floorz) { |
| 60 |
angle_t an; |
| 61 |
|
| 62 |
if (P_Random(pr_hexen) < 50) |
| 63 |
P_DamageMobj(mo, NULL, NULL, HITDICE(1)); |
| 64 |
|
| 65 |
an = P_Random(pr_hexen) << 24; |
| 66 |
P_ThrustMobj(mo, an, quake->intensity << (FRACBITS - 1)); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
--quake->duration; |
| 71 |
if (quake->duration <= 0) { |
| 72 |
dsda_ResetQuakes(); |
| 73 |
P_RemoveThinker(&quake->thinker); |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
void dsda_SpawnQuake(mobj_t* location, int intensity, int duration, |
| 78 |
int damage_radius, int tremor_radius) { |
| 79 |
quake_t* quake; |
| 80 |
|
| 81 |
quake = Z_MallocLevel(sizeof(*quake)); |
| 82 |
memset(quake, 0, sizeof(*quake)); |
| 83 |
P_AddThinker(&quake->thinker); |
| 84 |
quake->thinker.function = dsda_UpdateQuake; |
| 85 |
P_SetTarget(&quake->location, location); |
| 86 |
quake->intensity = intensity; |
| 87 |
quake->duration = duration; |
| 88 |
quake->damage_radius = damage_radius; |
| 89 |
quake->tremor_radius = tremor_radius; |
| 90 |
} |