Merge pull request #37 from protocultor/general_update

General update to reach Yamagi features
This commit is contained in:
Yamagi 2023-09-14 21:17:16 +02:00 committed by GitHub
commit 5f60bc3cb9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 387 additions and 131 deletions

View file

@ -1105,6 +1105,264 @@ void Cmd_Say_f (edict_t *ent, qboolean team, qboolean arg0)
} }
} }
/* Yamagi's cycleweap / prefweap */
static gitem_t *
cycle_weapon(edict_t *ent)
{
gclient_t *cl;
gitem_t *noammo_fallback;
gitem_t *noweap_fallback;
gitem_t *weap;
gitem_t *ammo;
int i;
int start;
int num_weaps;
const char *weapname = NULL;
if (!ent)
{
return NULL;
}
cl = ent->client;
if (!cl)
{
return NULL;
}
num_weaps = gi.argc();
/* find where we want to start the search for the next eligible weapon */
if (cl->newweapon)
{
weapname = cl->newweapon->classname;
}
else if (cl->pers.weapon)
{
weapname = cl->pers.weapon->classname;
}
if (weapname)
{
for (i = 1; i < num_weaps; i++)
{
if (Q_stricmp(weapname, gi.argv(i)) == 0)
{
break;
}
}
i++;
if (i >= num_weaps)
{
i = 1;
}
}
else
{
i = 1;
}
start = i;
noammo_fallback = NULL;
noweap_fallback = NULL;
/* find the first eligible weapon in the list we can switch to */
do
{
weap = FindItemByClassname(gi.argv(i));
if (weap && weap != cl->pers.weapon && (weap->flags & IT_WEAPON) && weap->use)
{
if (cl->pers.inventory[ITEM_INDEX(weap)] > 0)
{
if (weap->ammo)
{
ammo = FindItem(weap->ammo);
if (ammo)
{
if (cl->pers.inventory[ITEM_INDEX(ammo)] >= get_ammo_usage(weap))
{
return weap;
}
if (!noammo_fallback)
{
noammo_fallback = weap;
}
}
}
else
{
return weap;
}
}
else if (!noweap_fallback)
{
noweap_fallback = weap;
}
}
i++;
if (i >= num_weaps)
{
i = 1;
}
} while (i != start);
/* if no weapon was found, the fallbacks will be used for
printing the appropriate error message to the console
*/
if (noammo_fallback)
{
return noammo_fallback;
}
return noweap_fallback;
}
static void
Cmd_CycleWeap_f(edict_t *ent)
{
gitem_t *weap;
if (!ent)
{
return;
}
if (gi.argc() <= 1)
{
gi.cprintf(ent, PRINT_HIGH, "Usage: cycleweap classname1 classname2 .. classnameN\n");
return;
}
weap = cycle_weapon(ent);
if (weap)
{
if (ent->client->pers.inventory[ITEM_INDEX(weap)] <= 0)
{
gi.cprintf(ent, PRINT_HIGH, "Out of item: %s\n", weap->pickup_name);
}
else
{
weap->use(ent, weap);
}
}
}
static gitem_t *
preferred_weapon(edict_t *ent)
{
gclient_t *cl;
gitem_t *noammo_fallback;
gitem_t *noweap_fallback;
gitem_t *weap;
gitem_t *ammo;
int i;
int num_weaps;
if (!ent)
{
return NULL;
}
cl = ent->client;
if (!cl)
{
return NULL;
}
num_weaps = gi.argc();
noammo_fallback = NULL;
noweap_fallback = NULL;
/* find the first eligible weapon in the list we can switch to */
for (i = 1; i < num_weaps; i++)
{
weap = FindItemByClassname(gi.argv(i));
if (weap && (weap->flags & IT_WEAPON) && weap->use)
{
if (cl->pers.inventory[ITEM_INDEX(weap)] > 0)
{
if (weap->ammo)
{
ammo = FindItem(weap->ammo);
if (ammo)
{
if (cl->pers.inventory[ITEM_INDEX(ammo)] >= get_ammo_usage(weap))
{
return weap;
}
if (!noammo_fallback)
{
noammo_fallback = weap;
}
}
}
else
{
return weap;
}
}
else if (!noweap_fallback)
{
noweap_fallback = weap;
}
}
}
/* if no weapon was found, the fallbacks will be used for
printing the appropriate error message to the console
*/
if (noammo_fallback)
{
return noammo_fallback;
}
return noweap_fallback;
}
static void
Cmd_PrefWeap_f(edict_t *ent)
{
gitem_t *weap;
if (!ent)
{
return;
}
if (gi.argc() <= 1)
{
gi.cprintf(ent, PRINT_HIGH, "Usage: prefweap classname1 classname2 .. classnameN\n");
return;
}
weap = preferred_weapon(ent);
if (weap)
{
if (ent->client->pers.inventory[ITEM_INDEX(weap)] <= 0)
{
gi.cprintf(ent, PRINT_HIGH, "Out of item: %s\n", weap->pickup_name);
}
else
{
weap->use(ent, weap);
}
}
}
/* /*
================= =================
ClientCommand ClientCommand
@ -1248,7 +1506,14 @@ void ClientCommand (edict_t *ent)
else if(Q_stricmp (cmd, "anim") == 0) else if(Q_stricmp (cmd, "anim") == 0)
anim_player_cmd(ent); anim_player_cmd(ent);
#endif #endif
else if (Q_stricmp(cmd, "cycleweap") == 0)
{
Cmd_CycleWeap_f(ent);
}
else if (Q_stricmp(cmd, "prefweap") == 0)
{
Cmd_PrefWeap_f(ent);
}
else // anything that doesn't match a command will be a chat else // anything that doesn't match a command will be a chat
Cmd_Say_f (ent, false, true); Cmd_Say_f (ent, false, true);
} }

View file

@ -46,6 +46,8 @@ cvar_t *gamedir;
cvar_t *sv_cheats; cvar_t *sv_cheats;
cvar_t *aimfix; cvar_t *aimfix;
cvar_t *g_machinegun_norecoil;
cvar_t *g_swap_speed;
void SpawnEntities (char *mapname, char *entities, char *spawnpoint); void SpawnEntities (char *mapname, char *entities, char *spawnpoint);
void ClientThink (edict_t *ent, usercmd_t *cmd); void ClientThink (edict_t *ent, usercmd_t *cmd);
@ -357,4 +359,3 @@ void G_RunFrame (void)
// build the playerstate_t structures for all players // build the playerstate_t structures for all players
ClientEndServerFrames (); ClientEndServerFrames ();
} }

View file

@ -1018,4 +1018,3 @@ void fire_bfg (edict_t *self, vec3_t start, vec3_t dir, int damage, int speed, f
gi.linkentity (bfg); gi.linkentity (bfg);
} }

View file

@ -610,6 +610,8 @@ extern cvar_t *grenadeammo;
extern cvar_t *bettyammo; extern cvar_t *bettyammo;
extern cvar_t *aimfix; extern cvar_t *aimfix;
extern cvar_t *g_machinegun_norecoil;
extern cvar_t *g_swap_speed;
#define world (&g_edicts[0]) #define world (&g_edicts[0])
@ -850,6 +852,7 @@ void DeathmatchScoreboardMessage (edict_t *client, edict_t *killer);
// g_pweapon.c // g_pweapon.c
// //
void PlayerNoise(edict_t *who, vec3_t where, int type); void PlayerNoise(edict_t *who, vec3_t where, int type);
int get_ammo_usage(gitem_t *weap);
// //
// m_move.c // m_move.c
@ -905,7 +908,7 @@ void ai_schoolSideStepLeft (edict_t *self, float dist);
#define ANIM_PAIN 3 #define ANIM_PAIN 3
#define ANIM_ATTACK 4 #define ANIM_ATTACK 4
#define ANIM_DEATH 5 #define ANIM_DEATH 5
#define ANIM_REVERSE 6
// client data that stays across multiple level loads // client data that stays across multiple level loads
typedef struct typedef struct

View file

@ -996,7 +996,15 @@ void G_SetClientFrame (edict_t *ent)
if (!ent->groundentity && client->anim_priority <= ANIM_WAVE) if (!ent->groundentity && client->anim_priority <= ANIM_WAVE)
goto newanim; goto newanim;
if (ent->s.frame < client->anim_end) if (client->anim_priority == ANIM_REVERSE)
{
if (ent->s.frame > client->anim_end)
{
ent->s.frame--;
return;
}
}
else if (ent->s.frame < client->anim_end)
{ // continue an animation { // continue an animation
ent->s.frame++; ent->s.frame++;
return; return;

View file

@ -244,6 +244,19 @@ void ChangeWeapon (edict_t *ent)
ent->client->weaponstate = WEAPON_ACTIVATING; ent->client->weaponstate = WEAPON_ACTIVATING;
ent->client->ps.gunframe = 0; ent->client->ps.gunframe = 0;
ent->client->ps.gunindex = gi.modelindex(ent->client->pers.weapon->view_model); ent->client->ps.gunindex = gi.modelindex(ent->client->pers.weapon->view_model);
ent->client->anim_priority = ANIM_PAIN;
if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
{
ent->s.frame = FRAME_crpain1;
ent->client->anim_end = FRAME_crpain4;
}
else
{
ent->s.frame = FRAME_pain301;
ent->client->anim_end = FRAME_pain304;
}
} }
/* /*
@ -425,6 +438,52 @@ void Drop_Weapon (edict_t *ent, gitem_t *item)
ent->client->pers.inventory[index]--; ent->client->pers.inventory[index]--;
} }
/*
* Returns ammo used on a single shot for the given weapon
*/
int
get_ammo_usage(gitem_t *weap)
{
if (!weap)
{
return 0;
}
/* handles grenades and tesla which only use 1 ammo per shot */
/* have to check this because they don't store their ammo usage in weap->quantity */
if (weap->flags & IT_AMMO)
{
return 1;
}
/* weapons store their ammo usage in the quantity field */
return weap->quantity;
}
/*
* Client (player) animation for changing weapon
*/
static void
Change_Weap_Animation(edict_t *ent)
{
if (!ent)
{
return;
}
ent->client->anim_priority = ANIM_REVERSE;
if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
{
ent->s.frame = FRAME_crpain4 + 1;
ent->client->anim_end = FRAME_crpain1;
}
else
{
ent->s.frame = FRAME_pain304 + 1;
ent->client->anim_end = FRAME_pain301;
}
}
/* /*
================ ================
@ -440,6 +499,9 @@ A generic function to handle the basics of weapon thinking
void Weapon_Generic (edict_t *ent, int FRAME_ACTIVATE_LAST, int FRAME_FIRE_LAST, int FRAME_IDLE_LAST, int FRAME_DEACTIVATE_LAST, int *pause_frames, int *fire_frames, void (*fire)(edict_t *ent)) void Weapon_Generic (edict_t *ent, int FRAME_ACTIVATE_LAST, int FRAME_FIRE_LAST, int FRAME_IDLE_LAST, int FRAME_DEACTIVATE_LAST, int *pause_frames, int *fire_frames, void (*fire)(edict_t *ent))
{ {
int n; int n;
const unsigned short int change_speed = (g_swap_speed->value > 1)?
(g_swap_speed->value < USHRT_MAX)? (unsigned short int)g_swap_speed->value : 1
: 1;
if (!ent) if (!ent)
{ {
@ -448,26 +510,36 @@ void Weapon_Generic (edict_t *ent, int FRAME_ACTIVATE_LAST, int FRAME_FIRE_LAST,
if (ent->client->weaponstate == WEAPON_DROPPING) if (ent->client->weaponstate == WEAPON_DROPPING)
{ {
if (ent->client->ps.gunframe == FRAME_DEACTIVATE_LAST) if (ent->client->ps.gunframe >= FRAME_DEACTIVATE_LAST - change_speed + 1)
{ {
ChangeWeapon (ent); ChangeWeapon (ent);
return; return;
} }
else if ( (FRAME_DEACTIVATE_LAST - FRAME_DEACTIVATE_FIRST) >= (4 * change_speed) )
{
unsigned short int remainder = FRAME_DEACTIVATE_LAST - ent->client->ps.gunframe;
// "if (remainder == 4)" at change_speed == 1
if ( ( remainder <= (4 * change_speed) )
&& ( remainder > (3 * change_speed) ) )
{
Change_Weap_Animation(ent);
}
}
ent->client->ps.gunframe++; ent->client->ps.gunframe += change_speed;
return; return;
} }
if (ent->client->weaponstate == WEAPON_ACTIVATING) if (ent->client->weaponstate == WEAPON_ACTIVATING)
{ {
if (ent->client->ps.gunframe == FRAME_ACTIVATE_LAST) if (ent->client->ps.gunframe >= FRAME_ACTIVATE_LAST - change_speed + 1)
{ {
ent->client->weaponstate = WEAPON_READY; ent->client->weaponstate = WEAPON_READY;
ent->client->ps.gunframe = FRAME_IDLE_FIRST; ent->client->ps.gunframe = FRAME_IDLE_FIRST;
return; return;
} }
ent->client->ps.gunframe++; ent->client->ps.gunframe += change_speed;
return; return;
} }
@ -475,6 +547,10 @@ void Weapon_Generic (edict_t *ent, int FRAME_ACTIVATE_LAST, int FRAME_FIRE_LAST,
{ {
ent->client->weaponstate = WEAPON_DROPPING; ent->client->weaponstate = WEAPON_DROPPING;
ent->client->ps.gunframe = FRAME_DEACTIVATE_FIRST; ent->client->ps.gunframe = FRAME_DEACTIVATE_FIRST;
if ( (FRAME_DEACTIVATE_LAST - FRAME_DEACTIVATE_FIRST) < (4 * change_speed) )
{
Change_Weap_Animation(ent);
}
return; return;
} }
@ -484,7 +560,7 @@ void Weapon_Generic (edict_t *ent, int FRAME_ACTIVATE_LAST, int FRAME_FIRE_LAST,
{ {
ent->client->latched_buttons &= ~BUTTON_ATTACK; ent->client->latched_buttons &= ~BUTTON_ATTACK;
if ((!ent->client->ammo_index) || if ((!ent->client->ammo_index) ||
( ent->client->pers.inventory[ent->client->ammo_index] >= ent->client->pers.weapon->quantity)) ( ent->client->pers.inventory[ent->client->ammo_index] >= get_ammo_usage(ent->client->pers.weapon) ))
{ {
ent->client->ps.gunframe = FRAME_FIRE_FIRST; ent->client->ps.gunframe = FRAME_FIRE_FIRST;
ent->client->weaponstate = WEAPON_FIRING; ent->client->weaponstate = WEAPON_FIRING;
@ -603,6 +679,24 @@ void weapon_grenade_fire (edict_t *ent, qboolean held)
// play quad damage sound // play quad damage sound
playQuadSound(ent); playQuadSound(ent);
if (ent->deadflag || ent->health <= 0 || ent->s.modelindex != 255)
{
return; // VWep animations screw up corpses
}
if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
{
ent->client->anim_priority = ANIM_ATTACK;
ent->s.frame = FRAME_crattak1 - 1;
ent->client->anim_end = FRAME_crattak3;
}
else
{
ent->client->anim_priority = ANIM_REVERSE;
ent->s.frame = FRAME_wave08;
ent->client->anim_end = FRAME_wave01;
}
} }
void Weapon_Grenade (edict_t *ent) void Weapon_Grenade (edict_t *ent)
@ -1094,12 +1188,14 @@ void Machinegun_Fire (edict_t *ent)
ent->client->kick_angles[0] = ent->client->machinegun_shots * -1.5; ent->client->kick_angles[0] = ent->client->machinegun_shots * -1.5;
// raise the gun as it is firing // raise the gun as it is firing
if (!deathmatch->value) if (!(deathmatch->value || g_machinegun_norecoil->value))
{ {
ent->client->machinegun_shots++; ent->client->machinegun_shots++;
if (ent->client->machinegun_shots > 9) if (ent->client->machinegun_shots > 9)
{
ent->client->machinegun_shots = 9; ent->client->machinegun_shots = 9;
} }
}
// get start / end positions // get start / end positions
VectorAdd (ent->client->v_angle, ent->client->kick_angles, angles); VectorAdd (ent->client->v_angle, ent->client->kick_angles, angles);

View file

@ -236,6 +236,8 @@ InitGame(void)
/* others */ /* others */
aimfix = gi.cvar("aimfix", "0", CVAR_ARCHIVE); aimfix = gi.cvar("aimfix", "0", CVAR_ARCHIVE);
g_machinegun_norecoil = gi.cvar("g_machinegun_norecoil", "0", CVAR_ARCHIVE);
g_swap_speed = gi.cvar("g_swap_speed", "1", 0);
/* items */ /* items */
InitItems (); InitItems ();
@ -1156,4 +1158,3 @@ ReadLevel(const char *filename)
} }
} }
} }

View file

@ -520,124 +520,8 @@ void Weapon_LaserTripBomb(edict_t *ent)
static int pause_frames[] = {24, 33, 43, 0}; static int pause_frames[] = {24, 33, 43, 0};
static int fire_frames[] = {6, 10, 15, 0}; static int fire_frames[] = {6, 10, 15, 0};
const int deactivateFirst = 44; Weapon_Generic(ent, 6, 15, 43, 48, pause_frames,
const int deactivateLast = 48; fire_frames, weapon_lasertripbomb_fire);
const int idleFirst = 16;
const int idleLast = 43;
const int fireFirst = 7;
const int activateLast = 6;
if (!ent)
{
return;
}
if (ent->client->weaponstate == WEAPON_DROPPING)
{
if (ent->client->ps.gunframe == deactivateLast)
{
ChangeWeapon (ent);
return;
}
ent->client->ps.gunframe++;
return;
}
if (ent->client->weaponstate == WEAPON_ACTIVATING)
{
if (ent->client->ps.gunframe == activateLast)
{
ent->client->weaponstate = WEAPON_READY;
ent->client->ps.gunframe = idleFirst;
return;
}
ent->client->ps.gunframe++;
return;
}
if ((ent->client->newweapon) && (ent->client->weaponstate != WEAPON_FIRING))
{
ent->client->weaponstate = WEAPON_DROPPING;
ent->client->ps.gunframe = deactivateFirst;
return;
}
if (ent->client->weaponstate == WEAPON_READY)
{
if ( ((ent->client->latched_buttons|ent->client->buttons) & BUTTON_ATTACK) )
{
ent->client->latched_buttons &= ~BUTTON_ATTACK;
if(ent->client->pers.inventory[ent->client->ammo_index])
{
ent->client->ps.gunframe = fireFirst;
ent->client->weaponstate = WEAPON_FIRING;
// start the animation
ent->client->anim_priority = ANIM_ATTACK;
if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
{
ent->s.frame = FRAME_crattak1-1;
ent->client->anim_end = FRAME_crattak9;
}
else
{
ent->s.frame = FRAME_attack1-1;
ent->client->anim_end = FRAME_attack8;
}
}
else
{
if (level.time >= ent->pain_debounce_time)
{
gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/noammo.wav"), 1, ATTN_NORM, 0);
ent->pain_debounce_time = level.time + 1;
}
NoAmmoWeaponChange (ent);
}
}
else
{
if (ent->client->ps.gunframe == idleLast)
{
ent->client->ps.gunframe = idleFirst;
return;
}
int n = 0;
for (n = 0; pause_frames[n]; n++)
{
if (ent->client->ps.gunframe == pause_frames[n])
{
if (rand()&15)
return;
}
}
ent->client->ps.gunframe++;
return;
}
}
if (ent->client->weaponstate == WEAPON_FIRING)
{
int n = 0;
for (n = 0; fire_frames[n]; n++)
{
if (ent->client->ps.gunframe == fire_frames[n])
{
weapon_lasertripbomb_fire(ent);
break;
}
}
if (!fire_frames[n])
ent->client->ps.gunframe++;
if (ent->client->ps.gunframe == idleFirst+1)
ent->client->weaponstate = WEAPON_READY;
}
} }
void SP_misc_lasertripbomb(edict_t *bomb) void SP_misc_lasertripbomb(edict_t *bomb)
@ -1649,4 +1533,3 @@ void Action_Push (edict_t *ent)
else else
ent->client->ps.gunframe++; ent->client->ps.gunframe++;
} }