From d5f86389a16472f4df8b4d0e82cd54d6da8561a7 Mon Sep 17 00:00:00 2001 From: driAn Date: Thu, 16 Mar 2006 15:08:01 +0000 Subject: [PATCH] fixed win compatibility problems git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@221 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/client.cpp | 4 +- source/src/menus.cpp | 666 ++++++++++----- source/src/renderextras.cpp | 2 +- source/src/rendergl.cpp | 4 +- source/src/weapon.cpp | 1549 +++++++++++++++++++++++------------ 5 files changed, 1484 insertions(+), 741 deletions(-) diff --git a/source/src/client.cpp b/source/src/client.cpp index 6e3a549e..b992bcbf 100644 --- a/source/src/client.cpp +++ b/source/src/client.cpp @@ -51,11 +51,11 @@ void connects(char *servername) disconnect(1); // reset state addserver(servername); - conoutf("attempting to connect to %s", servername); + conoutf("attempting to connect to %s", (int)servername); ENetAddress address = { ENET_HOST_ANY, CUBE_SERVER_PORT }; if(enet_address_set_host(&address, servername) < 0) { - conoutf("could not resolve server %s", servername); + conoutf("could not resolve server %s", (int) servername); return; }; diff --git a/source/src/menus.cpp b/source/src/menus.cpp index c12a4e47..aca6b1f0 100644 --- a/source/src/menus.cpp +++ b/source/src/menus.cpp @@ -1,222 +1,444 @@ -// menus.cpp: ingame menu system (also used for scores and serverlist) - -#include "cube.h" - -#define FIRSTMENU 120 - -struct mitem { char *text, *action, *hoveraction; }; - -struct gmenu -{ - char *name; - vector items; - int mwidth; - int menusel; - int tex; // (optional) bg tex - char *mdl; // (optional) md2 mdl - int frame, range, rotspeed, scale; -}; - -vector menus; - -int vmenu = -1; - -ivector menustack; - -void menuset(int menu) -{ - if((vmenu = menu)>=1) resetmovement(player1); - if(vmenu==1) menus[1].menusel = 0; -}; - -void showmenu(char *name) -{ - loopv(menus) if(i>1 && strcmp(menus[i].name, name)==0) - { - menuset(i); - return; - }; -}; - -int menucompare(mitem *a, mitem *b) -{ - int x = atoi(a->text); - int y = atoi(b->text); - if(x>y) return -1; - if(x1 ? "[ %s menu ]" : "%s", m.name); - int mdisp = m.items.length(); - int w = 0; - loopi(mdisp) - { - int x = text_width(m.items[i].text); - if(x>w) w = x; - }; - int tw = text_width(title); - if(tw>w) w = tw; - int step = FONTH/4*5; - int h = (mdisp+2)*step; - int y = (VIRTH-h)/2; - int x = (VIRTW-w)/2; - blendbox(x-FONTH/2*3, y-FONTH, x+w+FONTH/2*3, y+h+FONTH, true, m.tex >= 0 ? FIRSTMENU + m.tex : -1); - draw_text(title, x, y,2); - y += FONTH*2; - if(vmenu) - { - int bh = y+m.menusel*step; - blendbox(x-FONTH, bh-10, x+w+FONTH, bh+FONTH+10, false); - }; - loopj(mdisp) - { - draw_text(m.items[j].text, x, y, 2); - y += step; - }; - return true; -}; - -void rendermenumdl() // nasty s*** -{ - if(vmenu<0) { menustack.setsize(0); return false; }; - if(vmenu==1) refreshservers(); - gmenu &m = menus[vmenu]; - if(!m.mdl) return; - - glPushMatrix (); - - glTranslatef(player1->o.x, player1->o.z, player1->o.y); - glRotatef(player1->yaw+90+180, 0, -1, 0); - glRotatef(player1->pitch, 0, 0, 1); - - glTranslatef(2, 0, 0); - if(m.rotspeed) glRotatef(lastmillis/5.0f/100.0f*m.rotspeed, 0, 1, 0); - - rendermodel(m.mdl, m.frame, m.range, 0, 5.0f, 0, 0, 0, 0, 0, false, (float)(m.scale ? m.scale/25.0f : 1), 100, 0, 0); - glPopMatrix(); -} - -void newmenu(char *name) -{ - gmenu &menu = menus.add(); - menu.name = newstring(name); - menu.menusel = 0; - menu.tex = -1; - menu.mdl = NULL; -}; - -void menumanual(int m, int n, char *text) -{ - if(!n) menus[m].items.setsize(0); - mitem &mitem = menus[m].items.add(); - mitem.text = text; - mitem.action = ""; -} - -void menuitem(char *text, char *action, char *hoveraction) -{ - gmenu &menu = menus.last(); - mitem &mi = menu.items.add(); - mi.text = newstring(text); - mi.action = action[0] ? newstring(action) : mi.text; - if(hoveraction) mi.hoveraction = newstring(hoveraction); - else mi.hoveraction = NULL; -}; - -void menubg(char *tex) -{ - gmenu &menu = menus.last(); - int curmtex = 0; - loopv(menus) curmtex = max(curmtex, menus[i].tex); - if(curmtex>=100) return; - sprintf_sd(path)("packages/%s", tex); - int xs, ys; - if(installtex(FIRSTMENU + curmtex, path, xs, ys, false, true)) - menu.tex = curmtex; -}; - -void menumdl(char *mdl, char *frame, char *range, char *rotspeed, char *scale) -{ - if(!mdl || !frame || !range) return; - gmenu &menu = menus.last(); - menu.mdl = newstring(mdl, _MAXDEFSTR); - menu.frame = max(0, atoi(frame)); - menu.range = max(1, atoi(range)); - menu.rotspeed = max(0, min(atoi(rotspeed), 100)); - menu.scale = max(0, min(atoi(scale), 100)); -}; - -void chmenumdl(char *menu, char *mdl, char *frame, char *range, char *rotspeed, char *scale) -{ - if(!menu || !mdl) return; - loopv(menus) - { - gmenu &m = menus[i]; - if(strcmp(m.name, menu) == 0) - { - if(m.mdl) strcpy_s(m.mdl, mdl); - else m.mdl = newstring(mdl, _MAXDEFSTR); - m.frame = atoi(frame); - m.range = atoi(range); - m.rotspeed = max(0, min(atoi(rotspeed), 100)); - m.scale = max(0, min(atoi(scale), 100)); - return; - }; - }; -}; - - -COMMAND(menuitem, ARG_3STR); -COMMAND(showmenu, ARG_1STR); -COMMAND(newmenu, ARG_1STR); -COMMAND(menubg, ARG_1STR); -COMMAND(menumdl, ARG_5STR); -COMMAND(chmenumdl, ARG_6STR); - -bool menukey(int code, bool isdown) -{ - if(vmenu<=0) return false; - int menusel = menus[vmenu].menusel; - if(isdown) - { - int oldmenusel = menusel; - if(code==SDLK_ESCAPE) - { - menuset(-1); - if(!menustack.empty()) menuset(menustack.pop()); - return true; - } - else if(code==SDLK_UP || code==-4) menusel--; - else if(code==SDLK_DOWN || code==-5) menusel++; - int n = menus[vmenu].items.length(); - if(menusel<0) menusel = n-1; - else if(menusel>=n) menusel = 0; - menus[vmenu].menusel = menusel; - if(menusel != oldmenusel)execute(menus[vmenu].items[menusel].hoveraction, true); - } - else - { - if(code==SDLK_RETURN || code==-2) - { - char *action = menus[vmenu].items[menusel].action; - if(vmenu==1) connects(getservername(menusel)); - menustack.add(vmenu); - menuset(-1); - execute(action, true); - }; - }; - return true; -}; +// menus.cpp: ingame menu system (also used for scores and serverlist) + + + +#include "cube.h" + + + +#define FIRSTMENU 120 + + + +struct mitem { char *text, *action, *hoveraction; }; + + + +struct gmenu + +{ + + char *name; + + vector items; + + int mwidth; + + int menusel; + + int tex; // (optional) bg tex + + char *mdl; // (optional) md2 mdl + + int frame, range, rotspeed, scale; + +}; + + + +vector menus; + + + +int vmenu = -1; + + + +ivector menustack; + + + +void menuset(int menu) + +{ + + if((vmenu = menu)>=1) resetmovement(player1); + + if(vmenu==1) menus[1].menusel = 0; + +}; + + + +void showmenu(char *name) + +{ + + loopv(menus) if(i>1 && strcmp(menus[i].name, name)==0) + + { + + menuset(i); + + return; + + }; + +}; + + + +int menucompare(mitem *a, mitem *b) + +{ + + int x = atoi(a->text); + + int y = atoi(b->text); + + if(x>y) return -1; + + if(x1 ? "[ %s menu ]" : "%s", m.name); + + int mdisp = m.items.length(); + + int w = 0; + + loopi(mdisp) + + { + + int x = text_width(m.items[i].text); + + if(x>w) w = x; + + }; + + int tw = text_width(title); + + if(tw>w) w = tw; + + int step = FONTH/4*5; + + int h = (mdisp+2)*step; + + int y = (VIRTH-h)/2; + + int x = (VIRTW-w)/2; + + blendbox(x-FONTH/2*3, y-FONTH, x+w+FONTH/2*3, y+h+FONTH, true, m.tex >= 0 ? FIRSTMENU + m.tex : -1); + + draw_text(title, x, y,2); + + y += FONTH*2; + + if(vmenu) + + { + + int bh = y+m.menusel*step; + + blendbox(x-FONTH, bh-10, x+w+FONTH, bh+FONTH+10, false); + + }; + + loopj(mdisp) + + { + + draw_text(m.items[j].text, x, y, 2); + + y += step; + + }; + + return true; + +}; + + + +void rendermenumdl() // nasty s*** + +{ + + if(vmenu<0) { menustack.setsize(0); return; }; + + if(vmenu==1) refreshservers(); + + gmenu &m = menus[vmenu]; + + if(!m.mdl) return; + + + + glPushMatrix (); + + + + glTranslatef(player1->o.x, player1->o.z, player1->o.y); + + glRotatef(player1->yaw+90+180, 0, -1, 0); + + glRotatef(player1->pitch, 0, 0, 1); + + + + glTranslatef(2, 0, 0); + + if(m.rotspeed) glRotatef(lastmillis/5.0f/100.0f*m.rotspeed, 0, 1, 0); + + + + rendermodel(m.mdl, m.frame, m.range, 0, 5.0f, 0, 0, 0, 0, 0, false, (float)(m.scale ? m.scale/25.0f : 1), 100, 0, 0); + + glPopMatrix(); + +} + + + +void newmenu(char *name) + +{ + + gmenu &menu = menus.add(); + + menu.name = newstring(name); + + menu.menusel = 0; + + menu.tex = -1; + + menu.mdl = NULL; + +}; + + + +void menumanual(int m, int n, char *text) + +{ + + if(!n) menus[m].items.setsize(0); + + mitem &mitem = menus[m].items.add(); + + mitem.text = text; + + mitem.action = ""; + +} + + + +void menuitem(char *text, char *action, char *hoveraction) + +{ + + gmenu &menu = menus.last(); + + mitem &mi = menu.items.add(); + + mi.text = newstring(text); + + mi.action = action[0] ? newstring(action) : mi.text; + + if(hoveraction) mi.hoveraction = newstring(hoveraction); + + else mi.hoveraction = NULL; + +}; + + + +void menubg(char *tex) + +{ + + gmenu &menu = menus.last(); + + int curmtex = 0; + + loopv(menus) curmtex = max(curmtex, menus[i].tex); + + if(curmtex>=100) return; + + sprintf_sd(path)("packages/%s", tex); + + int xs, ys; + + if(installtex(FIRSTMENU + curmtex, path, xs, ys, false, true)) + + menu.tex = curmtex; + +}; + + + +void menumdl(char *mdl, char *frame, char *range, char *rotspeed, char *scale) + +{ + + if(!mdl || !frame || !range) return; + + gmenu &menu = menus.last(); + + menu.mdl = newstring(mdl, _MAXDEFSTR); + + menu.frame = max(0, atoi(frame)); + + menu.range = max(1, atoi(range)); + + menu.rotspeed = max(0, min(atoi(rotspeed), 100)); + + menu.scale = max(0, min(atoi(scale), 100)); + +}; + + + +void chmenumdl(char *menu, char *mdl, char *frame, char *range, char *rotspeed, char *scale) + +{ + + if(!menu || !mdl) return; + + loopv(menus) + + { + + gmenu &m = menus[i]; + + if(strcmp(m.name, menu) == 0) + + { + + if(m.mdl) strcpy_s(m.mdl, mdl); + + else m.mdl = newstring(mdl, _MAXDEFSTR); + + m.frame = atoi(frame); + + m.range = atoi(range); + + m.rotspeed = max(0, min(atoi(rotspeed), 100)); + + m.scale = max(0, min(atoi(scale), 100)); + + return; + + }; + + }; + +}; + + + + + +COMMAND(menuitem, ARG_3STR); + +COMMAND(showmenu, ARG_1STR); + +COMMAND(newmenu, ARG_1STR); + +COMMAND(menubg, ARG_1STR); + +COMMAND(menumdl, ARG_5STR); + +COMMAND(chmenumdl, ARG_6STR); + + + +bool menukey(int code, bool isdown) + +{ + + if(vmenu<=0) return false; + + int menusel = menus[vmenu].menusel; + + if(isdown) + + { + + int oldmenusel = menusel; + + if(code==SDLK_ESCAPE) + + { + + menuset(-1); + + if(!menustack.empty()) menuset(menustack.pop()); + + return true; + + } + + else if(code==SDLK_UP || code==-4) menusel--; + + else if(code==SDLK_DOWN || code==-5) menusel++; + + int n = menus[vmenu].items.length(); + + if(menusel<0) menusel = n-1; + + else if(menusel>=n) menusel = 0; + + menus[vmenu].menusel = menusel; + + if(menusel != oldmenusel)execute(menus[vmenu].items[menusel].hoveraction, true); + + } + + else + + { + + if(code==SDLK_RETURN || code==-2) + + { + + char *action = menus[vmenu].items[menusel].action; + + if(vmenu==1) connects(getservername(menusel)); + + menustack.add(vmenu); + + menuset(-1); + + execute(action, true); + + }; + + }; + + return true; + +}; + diff --git a/source/src/renderextras.cpp b/source/src/renderextras.cpp index 1cac439a..c4c931fd 100644 --- a/source/src/renderextras.cpp +++ b/source/src/renderextras.cpp @@ -42,7 +42,7 @@ void dot(int x, int y, float z) xtraverts += 4; }; -void blendbox(int x1, int y1, int x2, int y2, bool border, int tex=-1) +void blendbox(int x1, int y1, int x2, int y2, bool border, int tex) { glDepthMask(GL_FALSE); glDisable(GL_TEXTURE_2D); diff --git a/source/src/rendergl.cpp b/source/src/rendergl.cpp index 76701c5d..a8a93ff0 100644 --- a/source/src/rendergl.cpp +++ b/source/src/rendergl.cpp @@ -1,4 +1,4 @@ -// rendergl.cpp: core opengl rendering stuff +// rendergl.cpp: core opengl rendering stuff #include "cube.h" @@ -67,7 +67,7 @@ void cleangl() if(qsphere) gluDeleteQuadric(qsphere); }; -bool installtex(int tnum, char *texname, int &xs, int &ys, bool clamp, bool highqual=false) +bool installtex(int tnum, char *texname, int &xs, int &ys, bool clamp, bool highqual) { SDL_Surface *s = IMG_Load(texname); if(!s) { conoutf("couldn't load texture %s", (int)texname); return false; }; diff --git a/source/src/weapon.cpp b/source/src/weapon.cpp index 05780437..d6fd32fe 100644 --- a/source/src/weapon.cpp +++ b/source/src/weapon.cpp @@ -1,508 +1,981 @@ -// weapon.cpp: all shooting and effects code - -#include "cube.h" - -struct guninfo { short sound, reload, reloadtime, attackdelay, damage, projspeed, part, spread, recoil, magsize, mdl_kick_rot, mdl_kick_back; char *name; }; - -const int SGRAYS = 20; //down from 20 (defualt) -const float SGSPREAD = 2; -vec sg[SGRAYS]; - -//change the particales -guninfo guns[NUMGUNS] = -{ - { S_KNIFE, S_NULL, 0, 500, 50, 0, 0, 1, 1, 1, 0, 0, "knife" }, - - { S_PISTOL, S_RPISTOL, 1400, 170, 20, 0, 0, 80, 10, 8, 6, 5, "pistol" }, // *SGRAYS - - { S_SHOTGUN, S_RSHOTGUN, 2400, 1000, 6, 0, 0, 1, 35, 7, 9, 9, "shotgun" }, //reload time is for 1 shell from 7 too powerful to 6 - - { S_SUBGUN, S_RSUBGUN, 1650, 80, 17, 0, 0, 70, 15, 30, 1, 2, "subgun" }, - - { S_SNIPER, S_RSNIPER, 1950, 1500, 72, 0, 0, 60, 50, 5, 4, 4, "sniper" }, - - { S_ASSULT, S_RASSULT, 2000, 130, 20, 0, 0, 20, 40, 20, 0, 2, "assult" }, //recoil was 44 - - { S_GRENADE, S_NULL, 1000, 2000, 150, 20, 6, 1, 1, 1, 3, 1, "grenade" }, -}; - +// weapon.cpp: all shooting and effects code + + + +#include "cube.h" + + + +struct guninfo { short sound, reload, reloadtime, attackdelay, damage, projspeed, part, spread, recoil, magsize, mdl_kick_rot, mdl_kick_back; char *name; }; + + + +const int SGRAYS = 20; //down from 20 (defualt) + +const float SGSPREAD = 2; + +vec sg[SGRAYS]; + + + +//change the particales + +guninfo guns[NUMGUNS] = + +{ + + { S_KNIFE, S_NULL, 0, 500, 50, 0, 0, 1, 1, 1, 0, 0, "knife" }, + + + + { S_PISTOL, S_RPISTOL, 1400, 170, 20, 0, 0, 80, 10, 8, 6, 5, "pistol" }, // *SGRAYS + + + + { S_SHOTGUN, S_RSHOTGUN, 2400, 1000, 6, 0, 0, 1, 35, 7, 9, 9, "shotgun" }, //reload time is for 1 shell from 7 too powerful to 6 + + + + { S_SUBGUN, S_RSUBGUN, 1650, 80, 17, 0, 0, 70, 15, 30, 1, 2, "subgun" }, + + + + { S_SNIPER, S_RSNIPER, 1950, 1500, 72, 0, 0, 60, 50, 5, 4, 4, "sniper" }, + + + + { S_ASSULT, S_RASSULT, 2000, 130, 20, 0, 0, 20, 40, 20, 0, 2, "assult" }, //recoil was 44 + + + + { S_GRENADE, S_NULL, 1000, 2000, 150, 20, 6, 1, 1, 1, 3, 1, "grenade" }, + +}; + + + bool gun_changed = false; - -//weapon selection -void wup() -{ - if(player1->gunselect==GUN_KNIFE) - player1->gunselect = GUN_PISTOL; - else if(player1->gunselect==GUN_PISTOL && player1->primary!=GUN_PISTOL) - player1->gunselect = player1->primary; - else if(player1->gunselect==player1->primary) - player1->gunselect=GUN_KNIFE; - + + +//weapon selection + +void wup() + +{ + + if(player1->gunselect==GUN_KNIFE) + + player1->gunselect = GUN_PISTOL; + + else if(player1->gunselect==GUN_PISTOL && player1->primary!=GUN_PISTOL) + + player1->gunselect = player1->primary; + + else if(player1->gunselect==player1->primary) + + player1->gunselect=GUN_KNIFE; + + + conoutf("%s selected", (int)guns[player1->gunselect].name); - gun_changed = true; -}; - -void wdw() -{ - if(player1->gunselect==GUN_KNIFE) - player1->gunselect = player1->primary; - else if(player1->gunselect==player1->primary && player1->primary!=GUN_PISTOL) - player1->gunselect = GUN_PISTOL; - else if(player1->gunselect==GUN_PISTOL) - player1->gunselect=GUN_KNIFE; - + gun_changed = true; + +}; + + + +void wdw() + +{ + + if(player1->gunselect==GUN_KNIFE) + + player1->gunselect = player1->primary; + + else if(player1->gunselect==player1->primary && player1->primary!=GUN_PISTOL) + + player1->gunselect = GUN_PISTOL; + + else if(player1->gunselect==GUN_PISTOL) + + player1->gunselect=GUN_KNIFE; + + + conoutf("%s selected", (int)guns[player1->gunselect].name); - gun_changed = true; -}; - -void primary() -{ + gun_changed = true; + +}; + + + +void primary() + +{ + player1->gunselect=player1->primary; - gun_changed = true; -}; - -void secondary() -{ + gun_changed = true; + +}; + + + +void secondary() + +{ + player1->gunselect=GUN_PISTOL; - gun_changed = true; -}; - -void melee() -{ + gun_changed = true; + +}; + + + +void melee() + +{ + player1->gunselect=GUN_KNIFE; - gun_changed = true; -}; - -COMMAND(primary,ARG_NONE); - -COMMAND(secondary,ARG_NONE); - -COMMAND(melee,ARG_NONE); -COMMAND(wup,ARG_NONE); -COMMAND(wdw,ARG_NONE); - -void reload() -{ - if(player1->gunselect==GUN_KNIFE) return; - if(player1->mag[player1->gunselect]>=guns[player1->gunselect].magsize) return; - if(player1->ammo[player1->gunselect]<=0) return; - if(player1->reloading) return; - - player1->reloading = true; - player1->lastaction = lastmillis; - - player1->gunwait = guns[player1->gunselect].reloadtime; - - //temp hack in drawhudgun() so no guns drawn while reloading, needs fixed - - int a = guns[player1->gunselect].magsize - player1->mag[player1->gunselect]; - if (a >= player1->ammo[player1->gunselect]) - { - player1->mag[player1->gunselect] += player1->ammo[player1->gunselect]; - player1->ammo[player1->gunselect] = 0; - } - else - { - player1->mag[player1->gunselect] += a; - player1->ammo[player1->gunselect] -= a; - } - - playsoundc(guns[player1->gunselect].reload); -}; - -COMMAND(reload,ARG_NONE); - -int reloadtime(int gun) { return guns[gun].reloadtime; }; -int attackdelay(int gun) { return guns[gun].attackdelay; }; -int magsize(int gun) { return guns[gun].magsize; }; -int kick_rot(int gun) { return guns[gun].mdl_kick_rot; }; -int kick_back(int gun) { return guns[gun].mdl_kick_back; }; - - -void createrays(vec &from, vec &to) // create random spread of rays for the shotgun -{ - vdist(dist, dvec, from, to); - float f = dist*SGSPREAD/1000; - loopi(SGRAYS) - { - #define RNDD (rnd(101)-50)*f - vec r = { RNDD, RNDD, RNDD }; - sg[i] = to; - vadd(sg[i], r); - }; -}; - -bool intersect(dynent *d, vec &from, vec &to) // if lineseg hits entity bounding box -{ - vec v = to, w = d->o, *p; - vsub(v, from); - vsub(w, from); - float c1 = dotprod(w, v); - - if(c1<=0) p = &from; - else - { - float c2 = dotprod(v, v); - if(c2<=c1) p = &to; - else - { - float f = c1/c2; - vmul(v, f); - vadd(v, from); - p = &v; - }; - }; - - return p->x <= d->o.x+d->radius - && p->x >= d->o.x-d->radius - && p->y <= d->o.y+d->radius - && p->y >= d->o.y-d->radius - && p->z <= d->o.z+d->aboveeye - && p->z >= d->o.z-d->eyeheight; -}; - -dynent *playerincrosshair() -{ - if(demoplayback) return NULL; - loopv(players) - { - dynent *o = players[i]; - if(!o) continue; - if(intersect(o, player1->o, worldpos)) return o; - }; - return NULL; -}; - -const int MAXPROJ = 100; -struct projectile { vec o, to; float speed; dynent *owner; int gun; bool inuse, local; }; -projectile projs[MAXPROJ]; - -void projreset() { loopi(MAXPROJ) projs[i].inuse = false; }; - -void newprojectile(vec &from, vec &to, float speed, bool local, dynent *owner, int gun) -{ - loopi(MAXPROJ) - { - projectile *p = &projs[i]; - if(p->inuse) continue; - p->inuse = true; - p->o = from; - p->to = to; - p->speed = speed; - p->local = local; - p->owner = owner; - p->gun = gun; - return; - }; -}; - -void hit(int target, int damage, dynent *d, dynent *at) -{ - if(d==player1) selfdamage(damage, at==player1 ? -1 : -2, at); - else { addmsg(1, 4, SV_DAMAGE, target, damage, d->lifesequence); playsound(S_PAIN1+rnd(5), &d->o); }; - particle_splash(3, damage, 1000, d->o); - demodamage(damage, d->o); -}; - -const float RL_RADIUS = 7; -const float RL_DAMRAD = 10; // hack - -void radialeffect(dynent *o, vec &v, int cn, int qdam, dynent *at) -{ - if(o->state!=CS_ALIVE) return; - vdist(dist, temp, v, o->o); - dist -= 2; // account for eye distance imprecision - if(distvel, temp); - }; -}; - -void splash(projectile *p, vec &v, vec &vold, int notthisplayer, int notthismonster, int qdam) -{ - particle_splash(0, 50, 300, v); - p->inuse = false; - if(p->gun!=GUN_GRENADE) - { - playsound(S_FEXPLODE, &v); - // no push? - } - else - { - //playsound(S_RLHIT, &v); - newsphere(v, RL_RADIUS, 0); - dodynlight(vold, v, 0, 0, p->owner); - if(!p->local) return; - radialeffect(player1, v, -1, qdam, p->owner); - loopv(players) - { - if(i==notthisplayer) continue; - dynent *o = players[i]; - if(!o) continue; - radialeffect(o, v, i, qdam, p->owner); - }; - }; -}; - -inline void projdamage(dynent *o, projectile *p, vec &v, int i, int im, int qdam) -{ - if(o->state!=CS_ALIVE) return; - if(intersect(o, p->o, v)) - { - splash(p, v, p->o, i, im, qdam); - hit(i, qdam, o, p->owner); - }; -}; - -void moveprojectiles(float time) -{ - loopi(MAXPROJ) - { - projectile *p = &projs[i]; - if(!p->inuse) continue; - //int qdam = guns[p->gun].damage*(p->owner->quadmillis ? 4 : 1); - int qdam = guns[p->gun].damage; - vdist(dist, v, p->o, p->to); - float dtime = dist*1000/p->speed; - if(time>dtime) dtime = time; - vmul(v, time/dtime); - vadd(v, p->o) - if(p->local) - { - loopv(players) - { - dynent *o = players[i]; - if(!o) continue; - projdamage(o, p, v, i, -1, qdam); - }; - if(p->owner!=player1) projdamage(player1, p, v, -1, -1, qdam); - }; - if(p->inuse) - { - if(time==dtime) splash(p, v, p->o, -1, -1, qdam); - else - { - if(p->gun==GUN_GRENADE) { dodynlight(p->o, v, 0, 255, p->owner); particle_splash(5, 2, 200, v); } - else { particle_splash(1, 1, 200, v); particle_splash(guns[p->gun].part, 1, 1, v); }; - }; - }; - p->o = v; - }; -}; - -extern float rad(float x); - -physent *curnade = NULL; - -void throw_nade(dynent *d, vec &to, physent *p) + gun_changed = true; + +}; + + + +COMMAND(primary,ARG_NONE); + + + +COMMAND(secondary,ARG_NONE); + + + +COMMAND(melee,ARG_NONE); + +COMMAND(wup,ARG_NONE); + +COMMAND(wdw,ARG_NONE); + + + +void reload() + +{ + + if(player1->gunselect==GUN_KNIFE) return; + + if(player1->mag[player1->gunselect]>=guns[player1->gunselect].magsize) return; + + if(player1->ammo[player1->gunselect]<=0) return; + + if(player1->reloading) return; + + + + player1->reloading = true; + + player1->lastaction = lastmillis; + + + + player1->gunwait = guns[player1->gunselect].reloadtime; + + + + //temp hack in drawhudgun() so no guns drawn while reloading, needs fixed + + + + int a = guns[player1->gunselect].magsize - player1->mag[player1->gunselect]; + + if (a >= player1->ammo[player1->gunselect]) + + { + + player1->mag[player1->gunselect] += player1->ammo[player1->gunselect]; + + player1->ammo[player1->gunselect] = 0; + + } + + else + + { + + player1->mag[player1->gunselect] += a; + + player1->ammo[player1->gunselect] -= a; + + } + + + + playsoundc(guns[player1->gunselect].reload); + +}; + + + +COMMAND(reload,ARG_NONE); + + + +int reloadtime(int gun) { return guns[gun].reloadtime; }; + +int attackdelay(int gun) { return guns[gun].attackdelay; }; + +int magsize(int gun) { return guns[gun].magsize; }; + +int kick_rot(int gun) { return guns[gun].mdl_kick_rot; }; + +int kick_back(int gun) { return guns[gun].mdl_kick_back; }; + + + + + +void createrays(vec &from, vec &to) // create random spread of rays for the shotgun + +{ + + vdist(dist, dvec, from, to); + + float f = dist*SGSPREAD/1000; + + loopi(SGRAYS) + + { + + #define RNDD (rnd(101)-50)*f + + vec r = { RNDD, RNDD, RNDD }; + + sg[i] = to; + + vadd(sg[i], r); + + }; + +}; + + + +bool intersect(dynent *d, vec &from, vec &to) // if lineseg hits entity bounding box + +{ + + vec v = to, w = d->o, *p; + + vsub(v, from); + + vsub(w, from); + + float c1 = dotprod(w, v); + + + + if(c1<=0) p = &from; + + else + + { + + float c2 = dotprod(v, v); + + if(c2<=c1) p = &to; + + else + + { + + float f = c1/c2; + + vmul(v, f); + + vadd(v, from); + + p = &v; + + }; + + }; + + + + return p->x <= d->o.x+d->radius + + && p->x >= d->o.x-d->radius + + && p->y <= d->o.y+d->radius + + && p->y >= d->o.y-d->radius + + && p->z <= d->o.z+d->aboveeye + + && p->z >= d->o.z-d->eyeheight; + +}; + + + +dynent *playerincrosshair() + +{ + + if(demoplayback) return NULL; + + loopv(players) + + { + + dynent *o = players[i]; + + if(!o) continue; + + if(intersect(o, player1->o, worldpos)) return o; + + }; + + return NULL; + +}; + + + +const int MAXPROJ = 100; + +struct projectile { vec o, to; float speed; dynent *owner; int gun; bool inuse, local; }; + +projectile projs[MAXPROJ]; + + + +void projreset() { loopi(MAXPROJ) projs[i].inuse = false; }; + + + +void newprojectile(vec &from, vec &to, float speed, bool local, dynent *owner, int gun) + +{ + + loopi(MAXPROJ) + + { + + projectile *p = &projs[i]; + + if(p->inuse) continue; + + p->inuse = true; + + p->o = from; + + p->to = to; + + p->speed = speed; + + p->local = local; + + p->owner = owner; + + p->gun = gun; + + return; + + }; + +}; + + + +void hit(int target, int damage, dynent *d, dynent *at) + +{ + + if(d==player1) selfdamage(damage, at==player1 ? -1 : -2, at); + + else { addmsg(1, 4, SV_DAMAGE, target, damage, d->lifesequence); playsound(S_PAIN1+rnd(5), &d->o); }; + + particle_splash(3, damage, 1000, d->o); + + demodamage(damage, d->o); + +}; + + + +const float RL_RADIUS = 7; + +const float RL_DAMRAD = 10; // hack + + + +void radialeffect(dynent *o, vec &v, int cn, int qdam, dynent *at) + +{ + + if(o->state!=CS_ALIVE) return; + + vdist(dist, temp, v, o->o); + + dist -= 2; // account for eye distance imprecision + + if(distvel, temp); + + }; + +}; + + + +void splash(projectile *p, vec &v, vec &vold, int notthisplayer, int notthismonster, int qdam) + +{ + + particle_splash(0, 50, 300, v); + + p->inuse = false; + + if(p->gun!=GUN_GRENADE) + + { + + playsound(S_FEXPLODE, &v); + + // no push? + + } + + else + + { + + //playsound(S_RLHIT, &v); + + newsphere(v, RL_RADIUS, 0); + + dodynlight(vold, v, 0, 0, p->owner); + + if(!p->local) return; + + radialeffect(player1, v, -1, qdam, p->owner); + + loopv(players) + + { + + if(i==notthisplayer) continue; + + dynent *o = players[i]; + + if(!o) continue; + + radialeffect(o, v, i, qdam, p->owner); + + }; + + }; + +}; + + + +inline void projdamage(dynent *o, projectile *p, vec &v, int i, int im, int qdam) + +{ + + if(o->state!=CS_ALIVE) return; + + if(intersect(o, p->o, v)) + + { + + splash(p, v, p->o, i, im, qdam); + + hit(i, qdam, o, p->owner); + + }; + +}; + + + +void moveprojectiles(float time) + +{ + + loopi(MAXPROJ) + + { + + projectile *p = &projs[i]; + + if(!p->inuse) continue; + + //int qdam = guns[p->gun].damage*(p->owner->quadmillis ? 4 : 1); + + int qdam = guns[p->gun].damage; + + vdist(dist, v, p->o, p->to); + + float dtime = dist*1000/p->speed; + + if(time>dtime) dtime = time; + + vmul(v, time/dtime); + + vadd(v, p->o) + + if(p->local) + + { + + loopv(players) + + { + + dynent *o = players[i]; + + if(!o) continue; + + projdamage(o, p, v, i, -1, qdam); + + }; + + if(p->owner!=player1) projdamage(player1, p, v, -1, -1, qdam); + + }; + + if(p->inuse) + + { + + if(time==dtime) splash(p, v, p->o, -1, -1, qdam); + + else + + { + + if(p->gun==GUN_GRENADE) { dodynlight(p->o, v, 0, 255, p->owner); particle_splash(5, 2, 200, v); } + + else { particle_splash(1, 1, 200, v); particle_splash(guns[p->gun].part, 1, 1, v); }; + + }; + + }; + + p->o = v; + + }; + +}; + + + +extern float rad(float x); + + + +physent *curnade = NULL; + + + +void throw_nade(dynent *d, vec &to, physent *p) + { if(!p || !d) return; - printf("thrownade\n"); - - p->isphysent = true; + printf("thrownade\n"); + + + + p->isphysent = true; + p->gravity = 20; - p->state = NADE_THROWED; - - p->timeinair = 0; - p->onfloor = false; - - p->o = d->o; - p->vel.z = sin(rad(d->pitch)); - float speed = cos(rad(d->pitch)); - p->vel.x = sin(rad(d->yaw))*speed; - p->vel.y = -cos(rad(d->yaw))*speed; - - vmul(p->vel, 1.7f); - - vec throwdir = p->vel; - vmul(throwdir, d->radius); - vadd(p->o, throwdir); - vadd(p->o, throwdir); + p->state = NADE_THROWED; + + + + p->timeinair = 0; + + p->onfloor = false; + + + + p->o = d->o; + + p->vel.z = sin(rad(d->pitch)); + + float speed = cos(rad(d->pitch)); + + p->vel.x = sin(rad(d->yaw))*speed; + + p->vel.y = -cos(rad(d->yaw))*speed; + + + + vmul(p->vel, 1.7f); + + + + vec throwdir = p->vel; + + vmul(throwdir, d->radius); + + vadd(p->o, throwdir); + + vadd(p->o, throwdir); + vec &from = d->o; addmsg(1, 9, SV_SHOT, d->gunselect, (int)(from.x*DMF), (int)(from.y*DMF), (int)(from.z*DMF), (int)(to.x*DMF), (int)(to.y*DMF), (int)(to.z*DMF), (int)((lastmillis-p->millis)/100)); printf("grenade: %i\n", (lastmillis-curnade->millis)/100); - if(curnade) curnade = NULL; -}; + if(curnade) curnade = NULL; -void *new_physent() +}; + + +physent *new_physent() { physent *p = (physent *)gp()->alloc(sizeof(physent)); - p->yaw = 270; - p->pitch = 0; + p->yaw = 270; + + p->pitch = 0; + p->roll = 0; p->isphysent = true; - - p->maxspeed = 40; - p->outsidemap = false; - p->inwater = false; - p->radius = 0.2f; - p->eyeheight = 0.3f; - p->aboveeye = 0.0f; - p->frags = 0; - p->plag = 0; - p->ping = 0; - p->lastupdate = lastmillis; - p->enemy = NULL; - p->monsterstate = 0; - p->name[0] = p->team[0] = 0; - p->blocked = false; - p->lifesequence = 0; + + + p->maxspeed = 40; + + p->outsidemap = false; + + p->inwater = false; + + p->radius = 0.2f; + + p->eyeheight = 0.3f; + + p->aboveeye = 0.0f; + + p->frags = 0; + + p->plag = 0; + + p->ping = 0; + + p->lastupdate = lastmillis; + + p->enemy = NULL; + + p->monsterstate = 0; + + p->name[0] = p->team[0] = 0; + + p->blocked = false; + + p->lifesequence = 0; + p->dynent::state = CS_ALIVE; - p->state = PHYSENT_NONE; - p->shots = 0; - p->reloading = false; - p->nextprimary = 1; - p->hasarmour = false; - - p->k_left = false; - p->k_right = false; - p->k_up = false; - p->k_down = false; - p->jumpnext = false; - p->strafe = 0; + p->state = PHYSENT_NONE; + + p->shots = 0; + + p->reloading = false; + + p->nextprimary = 1; + + p->hasarmour = false; + + + + p->k_left = false; + + p->k_right = false; + + p->k_up = false; + + p->k_down = false; + + p->jumpnext = false; + + p->strafe = 0; + p->move = 0; physents.add(p); return p; } - -physent *new_nade(dynent *d, int millis = 0) + + +physent *new_nade(dynent *d, int millis = 0) + { - printf("newnade\n"); - physent *p = new_physent(); - p->owner = d; - p->millis = lastmillis; - p->timetolife = 2000-millis; - p->state = NADE_ACTIVATED; + printf("newnade\n"); + + physent *p = new_physent(); + + p->owner = d; + + p->millis = lastmillis; + + p->timetolife = 2000-millis; + + p->state = NADE_ACTIVATED; + if(d==player1) curnade = p; - return p; -}; - void explode_nade(physent *i) -{ + return p; + +}; + + +void explode_nade(physent *i) + +{ + if(!i) return; - printf("explode\n"); + printf("explode\n"); + - if(i->state != NADE_THROWED) - { - vec o = i->owner->o; - vec dist = { 0.1f, 0.1f, 0.1f }; - vadd(o, dist); - throw_nade(i->owner, o, i); - }; - newprojectile(i->o, i->o, 1, true, i->owner, GUN_GRENADE); -}; - -void shootv(int gun, vec &from, vec &to, dynent *d, bool local, int nademillis) // create visual effect from a shot -{ - playsound(guns[gun].sound, d==player1 ? NULL : &d->o); - int pspeed = 25; - switch(gun) - { - case GUN_KNIFE: - break; - - case GUN_SHOTGUN: - { - loopi(SGRAYS) particle_splash(0, 5, 200, sg[i]); - break; - }; - - case GUN_PISTOL: - case GUN_SUBGUN: - case GUN_ASSULT: - addshotline(d, from, to); - particle_splash(9, 5, 250, to); - //particle_trail(1, 10, from, to); - break; - - case GUN_GRENADE: - //pspeed = guns[gun].projspeed; - //newprojectile(from, to, (float)pspeed, local, d, gun); + if(i->state != NADE_THROWED) + + { + + vec o = i->owner->o; + + vec dist = { 0.1f, 0.1f, 0.1f }; + + vadd(o, dist); + + throw_nade(i->owner, o, i); + + }; + + newprojectile(i->o, i->o, 1, true, i->owner, GUN_GRENADE); + +}; + + + +void shootv(int gun, vec &from, vec &to, dynent *d, bool local, int nademillis) // create visual effect from a shot + +{ + + playsound(guns[gun].sound, d==player1 ? NULL : &d->o); + + int pspeed = 25; + + switch(gun) + + { + + case GUN_KNIFE: + + break; + + + + case GUN_SHOTGUN: + + { + + loopi(SGRAYS) particle_splash(0, 5, 200, sg[i]); + + break; + + }; + + + + case GUN_PISTOL: + + case GUN_SUBGUN: + + case GUN_ASSULT: + + addshotline(d, from, to); + + particle_splash(9, 5, 250, to); + + //particle_trail(1, 10, from, to); + + break; + + + + case GUN_GRENADE: + + //pspeed = guns[gun].projspeed; + + //newprojectile(from, to, (float)pspeed, local, d, gun); + if(d!=player1) { physent *p = new_nade(d, nademillis); throw_nade(d, to, p); } - - break; - - case GUN_SNIPER: - addshotline(d, from, to); - particle_splash(0, 50, 200, to); - particle_trail(1, 500, from, to); - break; - }; -}; - -void hitpush(int target, int damage, dynent *d, dynent *at, vec &from, vec &to) -{ - hit(target, damage, d, at); - vdist(dist, v, from, to); - vmul(v, damage/dist/50); - vadd(d->vel, v); -}; - -void raydamage(dynent *o, vec &from, vec &to, dynent *d, int i) -{ - if(o->state!=CS_ALIVE) return; - int qdam = guns[d->gunselect].damage; - //if(d->quadmillis) qdam *= 4; - if(d->gunselect==GUN_SHOTGUN) - { - int damage = 0; - loop(r, SGRAYS) if(intersect(o, from, sg[r])) damage += qdam; - if(damage) hitpush(i, damage, o, d, from, to); - } - else if(intersect(o, from, to)) hitpush(i, qdam, o, d, from, to); -}; -void spreadandrecoil(vec & from, vec & to, dynent * d) -{ - //nothing special for a knife - if (d->gunselect==GUN_KNIFE || d->gunselect==GUN_GRENADE) return; - - //spread - vdist(dist, unitv, from, to); - float f = dist/1000; - int spd = guns[d->gunselect].spread; - //recoil - int rcl = guns[d->gunselect].recoil*-0.01f; - if (d->gunselect==GUN_ASSULT) - { - if(d->shots > 3) - spd = 70; - rcl += (rnd(8)*-0.01f); - }; - if ((d->gunselect==GUN_SNIPER) && (d->vel.x<.25f && d->vel.y<.25f)) - { - spd = 1; - rcl = rcl / 3; - }; - if (d->gunselect!=GUN_SHOTGUN) //no spread on shotgun - { - #define RNDD (rnd(spd)-spd/2)*f - vec r = { RNDD, RNDD, RNDD }; - vadd(to, r); - }; - //increase pitch for recoil - vdiv(unitv, dist); - vec recoil = unitv; - vmul(recoil, rcl); - vadd(d->vel, recoil); - if(d->pitch<80.0f) d->pitch += guns[d->gunselect].recoil*0.05f; -}; - -void shoot(dynent *d, vec &targ) -{ + + + break; + + + + case GUN_SNIPER: + + addshotline(d, from, to); + + particle_splash(0, 50, 200, to); + + particle_trail(1, 500, from, to); + + break; + + }; + +}; + + + +void hitpush(int target, int damage, dynent *d, dynent *at, vec &from, vec &to) + +{ + + hit(target, damage, d, at); + + vdist(dist, v, from, to); + + vmul(v, damage/dist/50); + + vadd(d->vel, v); + +}; + + + +void raydamage(dynent *o, vec &from, vec &to, dynent *d, int i) + +{ + + if(o->state!=CS_ALIVE) return; + + int qdam = guns[d->gunselect].damage; + + //if(d->quadmillis) qdam *= 4; + + if(d->gunselect==GUN_SHOTGUN) + + { + + int damage = 0; + + loop(r, SGRAYS) if(intersect(o, from, sg[r])) damage += qdam; + + if(damage) hitpush(i, damage, o, d, from, to); + + } + + else if(intersect(o, from, to)) hitpush(i, qdam, o, d, from, to); + +}; + +void spreadandrecoil(vec & from, vec & to, dynent * d) + +{ + + //nothing special for a knife + + if (d->gunselect==GUN_KNIFE || d->gunselect==GUN_GRENADE) return; + + + + //spread + + vdist(dist, unitv, from, to); + + float f = dist/1000; + + int spd = guns[d->gunselect].spread; + + + //recoil + + int rcl = guns[d->gunselect].recoil*-0.01f; + + + if (d->gunselect==GUN_ASSULT) + + { + + if(d->shots > 3) + + spd = 70; + + rcl += (rnd(8)*-0.01f); + + }; + + + if ((d->gunselect==GUN_SNIPER) && (d->vel.x<.25f && d->vel.y<.25f)) + + { + + spd = 1; + + rcl = rcl / 3; + + }; + + + if (d->gunselect!=GUN_SHOTGUN) //no spread on shotgun + + { + + #define RNDD (rnd(spd)-spd/2)*f + + vec r = { RNDD, RNDD, RNDD }; + + vadd(to, r); + + }; + + + //increase pitch for recoil + + vdiv(unitv, dist); + + vec recoil = unitv; + + vmul(recoil, rcl); + + vadd(d->vel, recoil); + + + if(d->pitch<80.0f) d->pitch += guns[d->gunselect].recoil*0.05f; + +}; + + + +void shoot(dynent *d, vec &targ) + +{ + int attacktime = lastmillis-d->lastaction; if(!d->attacking && d->gunselect==GUN_GRENADE && curnade) // throw @@ -511,43 +984,78 @@ void shoot(dynent *d, vec &targ) return; } - if(attacktimegunwait) return; - d->gunwait = 0; - d->reloading = false; - if(!d->attacking) - { - d->shots = 0; - return; + if(attacktimegunwait) return; + + d->gunwait = 0; + + d->reloading = false; + + + if(!d->attacking) + + { + + d->shots = 0; + + return; + }; - if(d->gunselect!=GUN_SUBGUN && d->gunselect!=GUN_ASSULT && d->gunselect!=GUN_GRENADE) d->attacking = false; //makes sub/assult autos - else d->shots++; - - d->lastaction = lastmillis; - d->lastattackgun = d->gunselect; - if(!d->mag[d->gunselect]) { playsoundc(S_NOAMMO); d->gunwait = 250; d->lastattackgun = -1; return; }; - - if(d->gunselect) d->mag[d->gunselect]--; - - vec from = d->o; - vec to = targ; - from.z -= 0.2f; // below eye - - spreadandrecoil(from,to,d); - - vdist(dist, unitv, from, to); - vdiv(unitv, dist); - - if(d->gunselect==GUN_KNIFE) - { - vmul(unitv, 3); // punch range - to = from; - vadd(to, unitv); - }; - if(d->gunselect==GUN_SHOTGUN) createrays(from, to); - + if(d->gunselect!=GUN_SUBGUN && d->gunselect!=GUN_ASSULT && d->gunselect!=GUN_GRENADE) d->attacking = false; //makes sub/assult autos + + else d->shots++; + + + + d->lastaction = lastmillis; + + d->lastattackgun = d->gunselect; + + if(!d->mag[d->gunselect]) { playsoundc(S_NOAMMO); d->gunwait = 250; d->lastattackgun = -1; return; }; + + + + if(d->gunselect) d->mag[d->gunselect]--; + + + + vec from = d->o; + + vec to = targ; + + from.z -= 0.2f; // below eye + + + + spreadandrecoil(from,to,d); + + + + vdist(dist, unitv, from, to); + + vdiv(unitv, dist); + + + + if(d->gunselect==GUN_KNIFE) + + { + + vmul(unitv, 3); // punch range + + to = from; + + vadd(to, unitv); + + }; + + if(d->gunselect==GUN_SHOTGUN) createrays(from, to); + + + //if(d->quadmillis && attacktime>200) playsoundc(S_ITEMPUP); - + + d->gunwait = guns[d->gunselect].attackdelay; if(d->gunselect==GUN_GRENADE) // activate @@ -556,16 +1064,29 @@ void shoot(dynent *d, vec &targ) return; } - shootv(d->gunselect, from, to, d, 0); - addmsg(1, 9, SV_SHOT, d->gunselect, (int)(from.x*DMF), (int)(from.y*DMF), (int)(from.z*DMF), (int)(to.x*DMF), (int)(to.y*DMF), (int)(to.z*DMF), 0 ); - - if(guns[d->gunselect].projspeed) return; - - loopv(players) - { - dynent *o = players[i]; - if(!o) continue; - raydamage(o, from, to, d, i); - }; - -}; + shootv(d->gunselect, from, to, d, 0); + + addmsg(1, 9, SV_SHOT, d->gunselect, (int)(from.x*DMF), (int)(from.y*DMF), (int)(from.z*DMF), (int)(to.x*DMF), (int)(to.y*DMF), (int)(to.z*DMF), 0 ); + + + + if(guns[d->gunselect].projspeed) return; + + + + loopv(players) + + { + + dynent *o = players[i]; + + if(!o) continue; + + raydamage(o, from, to, d, i); + + }; + + + +}; +