- Add header guards

- Bring the CTF files over
This commit is contained in:
Yamagi Burmeister 2011-10-05 16:33:04 +00:00
parent 56b41dd705
commit a729ad3701
7 changed files with 6128 additions and 0 deletions

5420
src/game/baseq2/g_ctf.c Normal file

File diff suppressed because it is too large Load diff

209
src/game/baseq2/g_ctf.h Normal file
View file

@ -0,0 +1,209 @@
/*
* Copyright (C) 1997-2001 Id Software, 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.
*
* =======================================================================
*
* Header file for the CTF code. Included at the end of g_local.h.
*
* =======================================================================
*/
#ifdef CTF
#ifndef G_CTF_H
#define G_CTF_H
#define CTF_VERSION 1.52
#define CTF_VSTRING2(x) # x
#define CTF_VSTRING(x) CTF_VSTRING2(x)
#define CTF_STRING_VERSION CTF_VSTRING(CTF_VERSION)
#define STAT_CTF_TEAM1_PIC 17
#define STAT_CTF_TEAM1_CAPS 18
#define STAT_CTF_TEAM2_PIC 19
#define STAT_CTF_TEAM2_CAPS 20
#define STAT_CTF_FLAG_PIC 21
#define STAT_CTF_JOINED_TEAM1_PIC 22
#define STAT_CTF_JOINED_TEAM2_PIC 23
#define STAT_CTF_TEAM1_HEADER 24
#define STAT_CTF_TEAM2_HEADER 25
#define STAT_CTF_TECH 26
#define STAT_CTF_ID_VIEW 27
#define STAT_CTF_MATCH 28
#define STAT_CTF_ID_VIEW_COLOR 29
#define STAT_CTF_TEAMINFO 30
#define CONFIG_CTF_MATCH (CS_AIRACCEL - 1)
#define CONFIG_CTF_TEAMINFO (CS_AIRACCEL - 2)
typedef enum
{
CTF_NOTEAM,
CTF_TEAM1,
CTF_TEAM2
} ctfteam_t;
typedef enum
{
CTF_GRAPPLE_STATE_FLY,
CTF_GRAPPLE_STATE_PULL,
CTF_GRAPPLE_STATE_HANG
} ctfgrapplestate_t;
typedef struct ghost_s
{
char netname[16];
int number;
/* stats */
int deaths;
int kills;
int caps;
int basedef;
int carrierdef;
int code; /* ghost code */
int team; /* team */
int score; /* frags at time of disconnect */
edict_t *ent;
} ghost_t;
extern cvar_t *ctf;
#define CTF_TEAM1_SKIN "ctf_r"
#define CTF_TEAM2_SKIN "ctf_b"
#define DF_CTF_FORCEJOIN 131072
#define DF_ARMOR_PROTECT 262144
#define DF_CTF_NO_TECH 524288
#define CTF_CAPTURE_BONUS 15 /* what you get for capture */
#define CTF_TEAM_BONUS 10 /* what your team gets for capture */
#define CTF_RECOVERY_BONUS 1 /* what you get for recovery */
#define CTF_FLAG_BONUS 0 /* what you get for picking up enemy flag */
#define CTF_FRAG_CARRIER_BONUS 2 /* what you get for fragging enemy flag carrier */
#define CTF_FLAG_RETURN_TIME 40 /* seconds until auto return */
#define CTF_CARRIER_DANGER_PROTECT_BONUS 2 /* bonus for fraggin someone who has recently hurt your flag carrier */
#define CTF_CARRIER_PROTECT_BONUS 1 /* bonus for fraggin someone while either you or your target are near your flag carrier */
#define CTF_FLAG_DEFENSE_BONUS 1 /* bonus for fraggin someone while either you or your target are near your flag */
#define CTF_RETURN_FLAG_ASSIST_BONUS 1 /* awarded for returning a flag that causes a capture to happen almost immediately */
#define CTF_FRAG_CARRIER_ASSIST_BONUS 2 /* award for fragging a flag carrier if a capture happens almost immediately */
#define CTF_TARGET_PROTECT_RADIUS 400 /* the radius around an object being defended where a target will be worth extra frags */
#define CTF_ATTACKER_PROTECT_RADIUS 400 /* the radius around an object being defended where an attacker will get extra frags when making kills */
#define CTF_CARRIER_DANGER_PROTECT_TIMEOUT 8
#define CTF_FRAG_CARRIER_ASSIST_TIMEOUT 10
#define CTF_RETURN_FLAG_ASSIST_TIMEOUT 10
#define CTF_AUTO_FLAG_RETURN_TIMEOUT 30 /* number of seconds before dropped flag auto-returns */
#define CTF_TECH_TIMEOUT 60 /* seconds before techs spawn again */
#define CTF_GRAPPLE_SPEED 650 /* speed of grapple in flight */
#define CTF_GRAPPLE_PULL_SPEED 650 /* speed player is pulled at */
void CTFInit(void);
void CTFSpawn(void);
void CTFPrecache(void);
void SP_info_player_team1(edict_t *self);
void SP_info_player_team2(edict_t *self);
char *CTFTeamName(int team);
char *CTFOtherTeamName(int team);
void CTFAssignSkin(edict_t *ent, char *s);
void CTFAssignTeam(gclient_t *who);
edict_t *SelectCTFSpawnPoint(edict_t *ent);
qboolean CTFPickup_Flag(edict_t *ent, edict_t *other);
void CTFDrop_Flag(edict_t *ent, gitem_t *item);
void CTFEffects(edict_t *player);
void CTFCalcScores(void);
void SetCTFStats(edict_t *ent);
void CTFDeadDropFlag(edict_t *self);
void CTFScoreboardMessage(edict_t *ent, edict_t *killer);
void CTFTeam_f(edict_t *ent);
void CTFID_f(edict_t *ent);
void CTFSay_Team(edict_t *who, char *msg);
void CTFFlagSetup(edict_t *ent);
void CTFResetFlag(int ctf_team);
void CTFFragBonuses(edict_t *targ, edict_t *inflictor, edict_t *attacker);
void CTFCheckHurtCarrier(edict_t *targ, edict_t *attacker);
/* GRAPPLE */
void CTFWeapon_Grapple(edict_t *ent);
void CTFPlayerResetGrapple(edict_t *ent);
void CTFGrapplePull(edict_t *self);
void CTFResetGrapple(edict_t *self);
/* TECH */
gitem_t *CTFWhat_Tech(edict_t *ent);
qboolean CTFPickup_Tech(edict_t *ent, edict_t *other);
void CTFDrop_Tech(edict_t *ent, gitem_t *item);
void CTFDeadDropTech(edict_t *ent);
void CTFSetupTechSpawn(void);
int CTFApplyResistance(edict_t *ent, int dmg);
int CTFApplyStrength(edict_t *ent, int dmg);
qboolean CTFApplyStrengthSound(edict_t *ent);
qboolean CTFApplyHaste(edict_t *ent);
void CTFApplyHasteSound(edict_t *ent);
void CTFApplyRegeneration(edict_t *ent);
qboolean CTFHasRegeneration(edict_t *ent);
void CTFRespawnTech(edict_t *ent);
void CTFResetTech(void);
void CTFOpenJoinMenu(edict_t *ent);
qboolean CTFStartClient(edict_t *ent);
void CTFVoteYes(edict_t *ent);
void CTFVoteNo(edict_t *ent);
void CTFReady(edict_t *ent);
void CTFNotReady(edict_t *ent);
qboolean CTFNextMap(void);
qboolean CTFMatchSetup(void);
qboolean CTFMatchOn(void);
void CTFGhost(edict_t *ent);
void CTFAdmin(edict_t *ent);
qboolean CTFInMatch(void);
void CTFStats(edict_t *ent);
void CTFWarp(edict_t *ent);
void CTFBoot(edict_t *ent);
void CTFPlayerList(edict_t *ent);
qboolean CTFCheckRules(void);
void SP_misc_ctf_banner(edict_t *ent);
void SP_misc_ctf_small_banner(edict_t *ent);
extern char *ctf_statusbar;
void UpdateChaseCam(edict_t *ent);
void ChaseNext(edict_t *ent);
void ChasePrev(edict_t *ent);
void CTFObserver(edict_t *ent);
void SP_trigger_teleport(edict_t *ent);
void SP_info_teleport_destination(edict_t *ent);
void CTFSetPowerUpEffect(edict_t *ent, int def);
#endif /* G_CTF_H */
#endif /* CTF */

View file

@ -24,6 +24,9 @@
* =======================================================================
*/
#ifndef G_LOCAL_H
#define G_LOCAL_H
#include "q_shared.h"
/* define GAME_INCLUDE so that game.h does not define the
@ -1124,3 +1127,5 @@ struct edict_s
#include "g_ctf.h"
#endif
#endif /* G_LOCAL_H */

View file

@ -34,6 +34,9 @@
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*/
#ifndef GAME_H
#define GAME_H
#define GAME_API_VERSION 3
#define SVF_NOCLIENT 0x00000001 /* don't send entity to clients, even if it has effects */
@ -242,3 +245,5 @@ typedef struct
game_export_t *GetGameApi(game_import_t *import);
#endif /* GAME_H */

415
src/game/baseq2/p_menu.c Normal file
View file

@ -0,0 +1,415 @@
/*
* Copyright (C) 1997-2001 Id Software, 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.
*
* =======================================================================
*
* The CTF menu.
*
* =======================================================================
*/
#ifdef CTF
#include "g_local.h"
/*
* Note that the pmenu entries are duplicated
* this is so that a static set of pmenu entries
* can be used for multiple clients and changed
* without interference. Note that arg will be
* freed when the menu is closed, it must be
* allocated memory.
*/
pmenuhnd_t *
PMenu_Open(edict_t *ent, pmenu_t *entries, int cur, int num, void *arg)
{
pmenuhnd_t *hnd;
pmenu_t *p;
int i;
if (!ent || !entries || !arg)
{
return NULL;
}
if (!ent->client)
{
return NULL;
}
if (ent->client->menu)
{
gi.dprintf("warning, ent already has a menu\n");
PMenu_Close(ent);
}
hnd = malloc(sizeof(*hnd));
hnd->arg = arg;
hnd->entries = malloc(sizeof(pmenu_t) * num);
memcpy(hnd->entries, entries, sizeof(pmenu_t) * num);
/* duplicate the strings since they may be from static memory */
for (i = 0; i < num; i++)
{
if (entries[i].text)
{
hnd->entries[i].text = strdup(entries[i].text);
}
}
hnd->num = num;
if ((cur < 0) || !entries[cur].SelectFunc)
{
for (i = 0, p = entries; i < num; i++, p++)
{
if (p->SelectFunc)
{
break;
}
}
}
else
{
i = cur;
}
if (i >= num)
{
hnd->cur = -1;
}
else
{
hnd->cur = i;
}
ent->client->showscores = true;
ent->client->inmenu = true;
ent->client->menu = hnd;
PMenu_Do_Update(ent);
gi.unicast(ent, true);
return hnd;
}
void
PMenu_Close(edict_t *ent)
{
int i;
pmenuhnd_t *hnd;
if (!ent)
{
return;
}
if (!ent->client->menu)
{
return;
}
hnd = ent->client->menu;
for (i = 0; i < hnd->num; i++)
{
if (hnd->entries[i].text)
{
free(hnd->entries[i].text);
}
}
free(hnd->entries);
if (hnd->arg)
{
free(hnd->arg);
}
free(hnd);
ent->client->menu = NULL;
ent->client->showscores = false;
}
/*
* only use on pmenu's that have
* been called with PMenu_Open
* */
void
PMenu_UpdateEntry(pmenu_t *entry, const char *text,
int align, SelectFunc_t SelectFunc)
{
if (!entry || !text)
{
return;
}
if (entry->text)
{
free(entry->text);
}
entry->text = strdup(text);
entry->align = align;
entry->SelectFunc = SelectFunc;
}
void
PMenu_Do_Update(edict_t *ent)
{
char string[1400];
int i;
pmenu_t *p;
int x;
pmenuhnd_t *hnd;
char *t;
qboolean alt = false;
if (!ent)
{
return;
}
if (!ent->client->menu)
{
gi.dprintf("warning: ent has no menu\n");
return;
}
hnd = ent->client->menu;
strcpy(string, "xv 32 yv 8 picn inventory ");
for (i = 0, p = hnd->entries; i < hnd->num; i++, p++)
{
if (!p->text || !*(p->text))
{
continue; /* blank line */
}
t = p->text;
if (*t == '*')
{
alt = true;
t++;
}
sprintf(string + strlen(string), "yv %d ", 32 + i * 8);
if (p->align == PMENU_ALIGN_CENTER)
{
x = 196 / 2 - strlen(t) * 4 + 64;
}
else if (p->align == PMENU_ALIGN_RIGHT)
{
x = 64 + (196 - strlen(t) * 8);
}
else
{
x = 64;
}
sprintf(string + strlen(string), "xv %d ",
x - ((hnd->cur == i) ? 8 : 0));
if (hnd->cur == i)
{
sprintf(string + strlen(string), "string2 \"\x0d%s\" ", t);
}
else if (alt)
{
sprintf(string + strlen(string), "string2 \"%s\" ", t);
}
else
{
sprintf(string + strlen(string), "string \"%s\" ", t);
}
alt = false;
}
gi.WriteByte(svc_layout);
gi.WriteString(string);
}
void
PMenu_Update(edict_t *ent)
{
if (!ent)
{
return;
}
if (!ent->client->menu)
{
gi.dprintf("warning: ent has no menu\n");
return;
}
if (level.time - ent->client->menutime >= 1.0)
{
/* been a second or more since
last update, update now */
PMenu_Do_Update(ent);
gi.unicast(ent, true);
ent->client->menutime = level.time;
ent->client->menudirty = false;
}
ent->client->menutime = level.time + 0.2;
ent->client->menudirty = true;
}
void
PMenu_Next(edict_t *ent)
{
pmenuhnd_t *hnd;
int i;
pmenu_t *p;
if (!ent)
{
return;
}
if (!ent->client->menu)
{
gi.dprintf("warning: ent has no menu\n");
return;
}
hnd = ent->client->menu;
if (hnd->cur < 0)
{
return; /* no selectable entries */
}
i = hnd->cur;
p = hnd->entries + hnd->cur;
do
{
i++, p++;
if (i == hnd->num)
{
i = 0, p = hnd->entries;
}
if (p->SelectFunc)
{
break;
}
}
while (i != hnd->cur);
hnd->cur = i;
PMenu_Update(ent);
}
void
PMenu_Prev(edict_t *ent)
{
pmenuhnd_t *hnd;
int i;
pmenu_t *p;
if (!ent)
{
return;
}
if (!ent->client->menu)
{
gi.dprintf("warning: ent has no menu\n");
return;
}
hnd = ent->client->menu;
if (hnd->cur < 0)
{
return; /* no selectable entries */
}
i = hnd->cur;
p = hnd->entries + hnd->cur;
do
{
if (i == 0)
{
i = hnd->num - 1;
p = hnd->entries + i;
}
else
{
i--, p--;
}
if (p->SelectFunc)
{
break;
}
}
while (i != hnd->cur);
hnd->cur = i;
PMenu_Update(ent);
}
void
PMenu_Select(edict_t *ent)
{
pmenuhnd_t *hnd;
pmenu_t *p;
if (!ent)
{
return;
}
if (!ent->client->menu)
{
gi.dprintf("warning: ent has no menu\n");
return;
}
hnd = ent->client->menu;
if (hnd->cur < 0)
{
return; /* no selectable entries */
}
p = hnd->entries + hnd->cur;
if (p->SelectFunc)
{
p->SelectFunc(ent, hnd);
}
}
#endif /* CTF */

69
src/game/baseq2/p_menu.h Normal file
View file

@ -0,0 +1,69 @@
/*
* Copyright (C) 1997-2001 Id Software, 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.
*
* =======================================================================
*
* Header file for the CTF menu.
*
* =======================================================================
*/
#ifdef CTF
#ifndef P_MENU_H
#define P_MENU_H
enum
{
PMENU_ALIGN_LEFT,
PMENU_ALIGN_CENTER,
PMENU_ALIGN_RIGHT
};
typedef struct pmenuhnd_s
{
struct pmenu_s *entries;
int cur;
int num;
void *arg;
} pmenuhnd_t;
typedef void (*SelectFunc_t)(edict_t *ent, pmenuhnd_t *hnd);
typedef struct pmenu_s
{
char *text;
int align;
SelectFunc_t SelectFunc;
} pmenu_t;
pmenuhnd_t *PMenu_Open(edict_t *ent, pmenu_t *entries, int cur,
int num, void *arg);
void PMenu_Close(edict_t *ent);
void PMenu_UpdateEntry(pmenu_t *entry, const char *text, int align,
SelectFunc_t SelectFunc);
void PMenu_Do_Update(edict_t *ent);
void PMenu_Update(edict_t *ent);
void PMenu_Next(edict_t *ent);
void PMenu_Prev(edict_t *ent);
void PMenu_Select(edict_t *ent);
#endif /* P_MENU_H */
#endif /* CTF */

View file

@ -25,6 +25,9 @@
* =======================================================================
*/
#ifndef QSHARED_H
#define QSHARED_H
#include <assert.h>
#include <math.h>
#include <stdio.h>
@ -1077,3 +1080,5 @@ extern int vidref_val;
size_t verify_fread(void *, size_t, size_t, FILE *);
size_t verify_fwrite(void *, size_t, size_t, FILE *);
#endif /* QSHARED_H */