game: merge ctf

This commit is contained in:
Denis Pauk 2023-11-04 21:03:05 +02:00
parent f0155f0163
commit 172e8b743e
7 changed files with 41 additions and 1964 deletions

136
Makefile
View file

@ -380,12 +380,12 @@ endif
# ----------
# Phony targets
.PHONY : all client game icon server ref_gl1 ref_gl3 ref_gles3 ref_soft ref_vk ref_gl4 ctf
.PHONY : all client game icon server ref_gl1 ref_gl3 ref_gles3 ref_soft ref_vk ref_gl4
# ----------
# Builds everything
all: config client server game ref_gl1 ref_gl3 ref_gles3 ref_soft ref_vk ref_gl4 ctf
all: config client server game ref_gl1 ref_gl3 ref_gles3 ref_soft ref_vk ref_gl4
# ----------
@ -1446,135 +1446,3 @@ release/baseq2/game.so : $(GAME_OBJS)
endif
# ----------
# The ctf game
ifeq ($(YQ2_OSTYPE), Windows)
ctf:
@echo "===> Building ctf/game.dll"
${Q}mkdir -p release/ctf
$(MAKE) release/ctf/game.dll
else ifeq ($(YQ2_OSTYPE), Darwin)
ctf:
@echo "===> Building ctf/game.dylib"
${Q}mkdir -p release/ctf
$(MAKE) release/ctf/game.dylib
else
ctf:
@echo "===> Building ctf/game.so"
${Q}mkdir -p release/ctf
$(MAKE) release/ctf/game.so
release/ctf/game.so : CFLAGS += -fPIC -Wno-unused-result
release/ctf/game.so : LDFLAGS += -shared
endif
build/ctf/%.o: %.c
@echo "===> CC $<"
${Q}mkdir -p $(@D)
${Q}$(CC) -c $(CFLAGS) -o $@ $<
# ----------
CTF_OBJS_ = \
src/common/shared/flash.o \
src/common/shared/rand.o \
src/common/shared/shared.o \
src/game/g_ai.o \
src/game/g_chase.o \
src/game/g_cmds.o \
src/ctf/g_combat.o \
src/game/g_ctf.o \
src/game/g_func.o \
src/game/g_items.o \
src/game/g_newai.o \
src/game/g_newdm.o \
src/game/g_newfnc.o \
src/game/g_newtarg.o \
src/game/g_newtrig.o \
src/game/g_newweap.o \
src/ctf/g_main.o \
src/game/g_misc.o \
src/game/g_monster.o \
src/game/g_phys.o \
src/game/g_sphere.o \
src/game/g_spawn.o \
src/game/g_svcmds.o \
src/game/g_target.o \
src/game/g_trigger.o \
src/game/g_turret.o \
src/game/g_utils.o \
src/game/g_weapon.o \
src/game/menu/menu.o \
src/game/dm/ball.o \
src/game/dm/tag.o \
src/game/monster/berserker/berserker.o \
src/game/monster/boss2/boss2.o \
src/game/monster/boss3/boss3.o \
src/game/monster/boss3/boss31.o \
src/game/monster/boss3/boss32.o \
src/game/monster/boss5/boss5.o \
src/game/monster/brain/brain.o \
src/game/monster/carrier/carrier.o \
src/game/monster/chick/chick.o \
src/game/monster/fixbot/fixbot.o \
src/game/monster/flipper/flipper.o \
src/game/monster/float/float.o \
src/game/monster/flyer/flyer.o \
src/game/monster/gekk/gekk.o \
src/game/monster/gladiator/gladb.o \
src/game/monster/gladiator/gladiator.o \
src/game/monster/gunner/gunner.o \
src/game/monster/hover/hover.o \
src/game/monster/infantry/infantry.o \
src/game/monster/insane/insane.o \
src/game/monster/medic/medic.o \
src/game/monster/misc/move.o \
src/game/monster/mutant/mutant.o \
src/game/monster/parasite/parasite.o \
src/game/monster/soldier/soldier.o \
src/game/monster/stalker/stalker.o \
src/game/monster/supertank/supertank.o \
src/game/monster/tank/tank.o \
src/game/monster/turret/turret.o \
src/game/monster/widow/widow2.o \
src/game/monster/widow/widow.o \
src/game/player/client.o \
src/game/player/hud.o \
src/game/player/trail.o \
src/game/player/view.o \
src/game/player/weapon.o \
src/game/savegame/savegame.o
# ----------
# Rewrite paths to our object directory
CTF_OBJS = $(patsubst %,build/ctf/%,$(CTF_OBJS_))
# ----------
# Generate header dependencies
CTF_DEPS= $(CTF_OBJS:.o=.d)
# ----------
# Suck header dependencies in
-include $(CTF_DEPS)
# ----------
ifeq ($(YQ2_OSTYPE), Windows)
release/ctf/game.dll : $(CTF_OBJS)
@echo "===> LD $@"
${Q}$(CC) $(LDFLAGS) $(CTF_OBJS) $(LDLIBS) -o $@
else ifeq ($(YQ2_OSTYPE), Darwin)
release/ctf/game.dylib : $(CTF_OBJS)
@echo "===> LD $@"
${Q}$(CC) $(LDFLAGS) $(CTF_OBJS) $(LDLIBS) -o $@
else
release/ctf/game.so : $(CTF_OBJS)
@echo "===> LD $@"
${Q}$(CC) $(LDFLAGS) $(CTF_OBJS) $(LDLIBS) -o $@
endif
# ----------

File diff suppressed because it is too large Load diff

View file

@ -1,518 +0,0 @@
/*
* Copyright (C) 1997-2001 Id Software, Inc.
* Copyright (c) ZeniMax Media Inc.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* =======================================================================
*
* Jump in into the game.so and support functions.
*
* =======================================================================
*/
#include "header/local.h"
game_locals_t game;
level_locals_t level;
game_import_t gi;
game_export_t globals;
spawn_temp_t st;
int sm_meat_index;
int snd_fry;
int meansOfDeath;
edict_t *g_edicts;
cvar_t *deathmatch;
cvar_t *coop;
cvar_t *coop_baseq2; /* treat spawnflags according to baseq2 rules */
cvar_t *coop_pickup_weapons;
cvar_t *coop_elevator_delay;
cvar_t *dmflags;
cvar_t *skill;
cvar_t *fraglimit;
cvar_t *timelimit;
cvar_t *capturelimit;
cvar_t *instantweap;
cvar_t *password;
cvar_t *spectator_password;
cvar_t *needpass;
cvar_t *maxclients;
cvar_t *maxspectators;
cvar_t *maxentities;
cvar_t *g_select_empty;
cvar_t *dedicated;
cvar_t *g_footsteps;
cvar_t *g_monsterfootsteps;
cvar_t *g_fix_triggered;
cvar_t *g_commanderbody_nogod;
cvar_t *filterban;
cvar_t *sv_maxvelocity;
cvar_t *sv_gravity;
cvar_t *sv_rollspeed;
cvar_t *sv_rollangle;
cvar_t *gun_x;
cvar_t *gun_y;
cvar_t *gun_z;
cvar_t *run_pitch;
cvar_t *run_roll;
cvar_t *bob_up;
cvar_t *bob_pitch;
cvar_t *bob_roll;
cvar_t *sv_cheats;
cvar_t *flood_msgs;
cvar_t *flood_persecond;
cvar_t *flood_waitdelay;
cvar_t *sv_maplist;
cvar_t *sv_stopspeed;
cvar_t *gib_on;
cvar_t *g_showlogic;
cvar_t *gamerules;
cvar_t *huntercam;
cvar_t *strong_mines;
cvar_t *randomrespawn;
cvar_t *g_disruptor;
cvar_t *aimfix;
cvar_t *g_machinegun_norecoil;
cvar_t *g_swap_speed;
void G_RunFrame(void);
/* =================================================================== */
void
ShutdownGame(void)
{
gi.dprintf("==== ShutdownGame ====\n");
gi.FreeTags(TAG_LEVEL);
gi.FreeTags(TAG_GAME);
}
/*
* Returns a pointer to the structure
* with all entry points and global
* variables
*/
Q2_DLL_EXPORTED game_export_t *
GetGameAPI(game_import_t *import)
{
gi = *import;
globals.apiversion = GAME_API_VERSION;
globals.Init = InitGame;
globals.Shutdown = ShutdownGame;
globals.SpawnEntities = SpawnEntities;
globals.WriteGame = WriteGame;
globals.ReadGame = ReadGame;
globals.WriteLevel = WriteLevel;
globals.ReadLevel = ReadLevel;
globals.ClientThink = ClientThink;
globals.ClientConnect = ClientConnect;
globals.ClientUserinfoChanged = ClientUserinfoChanged;
globals.ClientDisconnect = ClientDisconnect;
globals.ClientBegin = ClientBegin;
globals.ClientCommand = ClientCommand;
globals.RunFrame = G_RunFrame;
globals.ServerCommand = ServerCommand;
globals.edict_size = sizeof(edict_t);
/* Initalize the PRNG */
randk_seed();
return &globals;
}
/*
* this is only here so the functions
* in shared source files can link
*/
void
Sys_Error(const char *error, ...)
{
va_list argptr;
char text[1024];
va_start(argptr, error);
vsnprintf(text, sizeof(text), error, argptr);
va_end(argptr);
gi.error("%s", text);
}
void
Com_Printf(const char *msg, ...)
{
va_list argptr;
char text[1024];
va_start(argptr, msg);
vsnprintf(text, sizeof(text), msg, argptr);
va_end(argptr);
gi.dprintf("%s", text);
}
/* ====================================================================== */
void
ClientEndServerFrames(void)
{
int i;
edict_t *ent;
/* calc the player views now that all
pushing and damage has been added */
for (i = 0; i < maxclients->value; i++)
{
ent = g_edicts + 1 + i;
if (!ent->inuse || !ent->client)
{
continue;
}
ClientEndServerFrame(ent);
}
}
/*
* Returns the created target changelevel
*/
edict_t *
CreateTargetChangeLevel(char *map)
{
edict_t *ent;
if (!map)
{
return NULL;
}
ent = G_Spawn();
ent->classname = "target_changelevel";
Com_sprintf(level.nextmap, sizeof(level.nextmap), "%s", map);
ent->map = level.nextmap;
return ent;
}
/*
* The timelimit or fraglimit has been exceeded
*/
void
EndDMLevel(void)
{
edict_t *ent;
char *s, *t, *f;
static const char *seps = " ,\n\r";
/* stay on same level flag */
if ((int)dmflags->value & DF_SAME_LEVEL)
{
BeginIntermission(CreateTargetChangeLevel(level.mapname));
return;
}
if (*level.forcemap)
{
BeginIntermission(CreateTargetChangeLevel(level.forcemap));
return;
}
/* see if it's in the map list */
if (*sv_maplist->string)
{
s = strdup(sv_maplist->string);
f = NULL;
t = strtok(s, seps);
while (t != NULL)
{
if (Q_stricmp(t, level.mapname) == 0)
{
/* it's in the list, go to the next one */
t = strtok(NULL, seps);
if (t == NULL) /* end of list, go to first one */
{
if (f == NULL) /* there isn't a first one, same level */
{
BeginIntermission(CreateTargetChangeLevel(level.mapname));
}
else
{
BeginIntermission(CreateTargetChangeLevel(f));
}
}
else
{
BeginIntermission(CreateTargetChangeLevel(t));
}
free(s);
return;
}
if (!f)
{
f = t;
}
t = strtok(NULL, seps);
}
free(s);
}
if (level.nextmap[0]) /* go to a specific map */
{
BeginIntermission(CreateTargetChangeLevel(level.nextmap));
}
else /* search for a changelevel */
{
ent = G_Find(NULL, FOFS(classname), "target_changelevel");
if (!ent)
{
/* the map designer didn't include a changelevel,
so create a fake ent that goes back to the same
level */
BeginIntermission(CreateTargetChangeLevel(level.mapname));
return;
}
BeginIntermission(ent);
}
}
void
CheckNeedPass(void)
{
int need;
/* if password or spectator_password has
changed, update needpass as needed */
if (password->modified || spectator_password->modified)
{
password->modified = spectator_password->modified = false;
need = 0;
if (*password->string && Q_stricmp(password->string, "none"))
{
need |= 1;
}
if (*spectator_password->string &&
Q_stricmp(spectator_password->string, "none"))
{
need |= 2;
}
gi.cvar_set("needpass", va("%d", need));
}
}
void
CheckDMRules(void)
{
int i;
gclient_t *cl;
if (level.intermissiontime)
{
return;
}
if (!deathmatch->value)
{
return;
}
if (ctf->value && CTFCheckRules())
{
EndDMLevel();
return;
}
if (CTFInMatch())
{
return; /* no checking in match mode */
}
if (timelimit->value)
{
if (level.time >= timelimit->value * 60)
{
gi.bprintf(PRINT_HIGH, "Timelimit hit.\n");
EndDMLevel();
return;
}
}
if (fraglimit->value)
{
for (i = 0; i < maxclients->value; i++)
{
cl = game.clients + i;
if (!g_edicts[i + 1].inuse)
{
continue;
}
if (cl->resp.score >= fraglimit->value)
{
gi.bprintf(PRINT_HIGH, "Fraglimit hit.\n");
EndDMLevel();
return;
}
}
}
}
void
ExitLevel(void)
{
int i;
edict_t *ent;
char command[256];
level.exitintermission = 0;
level.intermissiontime = 0;
if (CTFNextMap())
{
return;
}
Com_sprintf(command, sizeof(command), "gamemap \"%s\"\n", level.changemap);
gi.AddCommandString(command);
level.changemap = NULL;
level.exitintermission = 0;
level.intermissiontime = 0;
ClientEndServerFrames();
/* clear some things before going to next level */
for (i = 0; i < maxclients->value; i++)
{
ent = g_edicts + 1 + i;
if (!ent->inuse)
{
continue;
}
if (ent->health > ent->client->pers.max_health)
{
ent->health = ent->client->pers.max_health;
}
}
debristhisframe = 0;
gibsthisframe = 0;
}
/*
* Advances the world by 0.1 seconds
*/
void
G_RunFrame(void)
{
int i;
edict_t *ent;
level.framenum++;
level.time = level.framenum * FRAMETIME;
gibsthisframe = 0;
debristhisframe = 0;
/* choose a client for monsters to target this frame */
AI_SetSightClient();
/* exit intermissions */
if (level.exitintermission)
{
ExitLevel();
return;
}
/* treat each object in turn
even the world gets a chance
to think */
ent = &g_edicts[0];
for (i = 0; i < globals.num_edicts; i++, ent++)
{
if (!ent->inuse)
{
continue;
}
level.current_entity = ent;
VectorCopy(ent->s.origin, ent->s.old_origin);
/* if the ground entity moved, make sure we are still on it */
if ((ent->groundentity) &&
(ent->groundentity->linkcount != ent->groundentity_linkcount))
{
ent->groundentity = NULL;
if (!(ent->flags & (FL_SWIM | FL_FLY)) &&
(ent->svflags & SVF_MONSTER))
{
M_CheckGround(ent);
}
}
if ((i > 0) && (i <= maxclients->value))
{
ClientBeginServerFrame(ent);
continue;
}
G_RunEntity(ent);
}
/* see if it is time to end a deathmatch */
CheckDMRules();
/* see if needpass needs updated */
CheckNeedPass();
/* build the playerstate_t structures for all players */
ClientEndServerFrames();
}

View file

@ -1,22 +0,0 @@
/*
* Copyright (C) 1997-2001 Id Software, Inc.
* Copyright (c) ZeniMax Media Inc.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
#include "../../game/header/game.h"

View file

@ -1,22 +0,0 @@
/*
* Copyright (C) 1997-2001 Id Software, Inc.
* Copyright (c) ZeniMax Media Inc.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
#include "../../game/header/local.h"

View file

@ -812,6 +812,9 @@ T_Damage(edict_t *targ, edict_t *inflictor, edict_t *attacker, vec3_t dir,
damage *= 2;
}
/* strength tech */
damage = CTFApplyStrength(attacker, damage);
if (targ->flags & FL_NO_KNOCKBACK)
{
knockback = 0;
@ -901,6 +904,17 @@ T_Damage(edict_t *targ, edict_t *inflictor, edict_t *attacker, vec3_t dir,
}
}
/* resistance tech */
take = CTFApplyResistance(targ, take);
/* team damage avoidance */
if (!(dflags & DAMAGE_NO_PROTECTION) && CheckTeamDamage(targ, attacker))
{
return;
}
CTFCheckHurtCarrier(targ, attacker);
/* do the damage */
if (take)
{

View file

@ -244,6 +244,12 @@ EndDMLevel(void)
return;
}
if (*level.forcemap)
{
BeginIntermission(CreateTargetChangeLevel(level.forcemap));
return;
}
/* see if it's in the map list */
if (*sv_maplist->string)
{
@ -362,6 +368,17 @@ CheckDMRules(void)
}
}
if (ctf->value && CTFCheckRules())
{
EndDMLevel();
return;
}
if (CTFInMatch())
{
return; /* no checking in match mode */
}
if (timelimit->value)
{
if (level.time >= timelimit->value * 60)
@ -400,6 +417,14 @@ ExitLevel(void)
edict_t *ent;
char command[256];
level.exitintermission = 0;
level.intermissiontime = 0;
if (CTFNextMap())
{
return;
}
Com_sprintf(command, sizeof(command), "gamemap \"%s\"\n", level.changemap);
gi.AddCommandString(command);
level.changemap = NULL;