diff --git a/src/player.c b/src/player.c
index 7a693ac959eb2829f5bb0166e194f7e452b063da..6a803a151b1588e206a404e9e5fcb57b66608c83 100644 (file)
--- a/src/player.c
+++ b/src/player.c
-/*
- Copyright (C) Prikol Software 1996-1997
- Copyright (C) Aleksey Volynskov 1996-1997
- Copyright (C) <ARembo@gmail.com> 2011
-
- This file is part of the Doom2D:Rembo project.
-
- Doom2D:Rembo is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License version 2 as
- published by the Free Software Foundation.
-
- Doom2D:Rembo 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, see <http://www.gnu.org/licenses/> or
- write to the Free Software Foundation, Inc.,
- 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+/* Copyright (C) 1996-1997 Aleksey Volynskov
+ * Copyright (C) 2011 Rambo
+ * Copyright (C) 2020 SovietPony
+ *
+ * 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, version 3 of the License ONLY.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
#include "glob.h"
#include <stdlib.h>
#include <string.h>
#include "glob.h"
#include <stdlib.h>
#include <string.h>
-#include "keyb.h"
#include "view.h"
#include "dots.h"
#include "smoke.h"
#include "view.h"
#include "dots.h"
#include "smoke.h"
#include "player.h"
#include "misc.h"
#include "my.h"
#include "player.h"
#include "misc.h"
#include "my.h"
-
-extern int hit_xv,hit_yv;
+#include "game.h"
+#include "input.h"
#define PL_RAD 8
#define PL_HT 26
#define PL_RAD 8
#define PL_HT 26
#define PL_AQUA_AIR 1091
#define PL_AQUA_AIR 1091
-byte p_immortal=0,p_fly=0;
+byte p_immortal;
+byte p_fly;
-int PL_JUMP=10,PL_RUN=8;
+int PL_JUMP=10;
+int PL_RUN=8;
-int wp_it[11]={0,I_CSAW,0,I_SGUN,I_SGUN2,I_MGUN,I_LAUN,I_PLAS,I_BFG,I_GUN2,0};
+static int wp_it[11]={0,I_CSAW,0,I_SGUN,I_SGUN2,I_MGUN,I_LAUN,I_PLAS,I_BFG,I_GUN2,0};
enum{STAND,GO,DIE,SLOP,DEAD,MESS,OUT,FALL};
typedef void fire_f(int,int,int,int,int);
enum{STAND,GO,DIE,SLOP,DEAD,MESS,OUT,FALL};
typedef void fire_f(int,int,int,int,int);
-player_t pl1,pl2;
+player_t pl1;
+player_t pl2;
static int aitime;
static void *aisnd[3];
static void *pdsnd[5];
static void *snd[11];
static int aitime;
static void *aisnd[3];
static void *pdsnd[5];
static void *snd[11];
-byte plr_goanim[]="BDACDA",
- plr_dieanim[]="HHHHIIIIJJJJKKKKLLLLMMMM",
- plr_slopanim[]="OOPPQQRRSSTTUUVVWW";
-
-
-#pragma pack(1)
-struct {
- int ku,kd,kl,kr,kf,kj,kwl,kwr,kp;
-} _keys;
-#pragma pack()
-
-void PL_save_player (player_t *p, FILE *h) {
- myfwrite32(p->o.x, h);
- myfwrite32(p->o.y, h);
- myfwrite32(p->o.xv, h);
- myfwrite32(p->o.yv, h);
- myfwrite32(p->o.vx, h);
- myfwrite32(p->o.vy, h);
- myfwrite32(p->o.r, h);
- myfwrite32(p->o.h, h);
- myfwrite32(p->looky, h);
- myfwrite32(p->st, h);
- myfwrite32(p->s, h);
- myfwrite32(p->life, h);
- myfwrite32(p->armor, h);
- myfwrite32(p->hit, h);
- myfwrite32(p->hito, h);
- myfwrite32(p->pain, h);
- myfwrite32(p->air, h);
- myfwrite32(p->invl, h);
- myfwrite32(p->suit, h);
- myfwrite8(p->d, h);
- myfwrite32(p->frag, h);
- myfwrite32(p->ammo, h);
- myfwrite32(p->shel, h);
- myfwrite32(p->rock, h);
- myfwrite32(p->cell, h);
- myfwrite32(p->fuel, h);
- myfwrite32(p->kills, h);
- myfwrite32(p->secrets, h);
- myfwrite8(p->fire, h);
- myfwrite8(p->cwpn, h);
- myfwrite8(p->csnd, h);
- myfwrite8(p->amul, h);
- myfwrite16(p->wpns, h);
- myfwrite8(p->wpn, h);
- myfwrite8(p->f, h);
- myfwrite8(p->drawst, h);
- myfwrite8(p->color, h);
- myfwrite32(p->id, h);
- myfwrite8(p->keys, h);
- myfwrite8(p->lives, h);
- // k* not saved
-}
+byte plr_goanim[]="BDACDA";
+byte plr_dieanim[]="HHHHIIIIJJJJKKKKLLLLMMMM";
+byte plr_slopanim[]="OOPPQQRRSSTTUUVVWW";
-void PL_savegame (FILE *h) {
- PL_save_player(&pl1, h);
- if (_2pl) {
- PL_save_player(&pl2, h);
- }
- myfwrite32(PL_JUMP, h);
- myfwrite32(PL_RUN, h);
- myfwrite8(p_immortal, h);
+static int nonz (int a) {
+ return a ? a : 1;
}
}
-void PL_load_player (player_t *p, FILE *h) {
- p->o.x = myfread32(h);
- p->o.y = myfread32(h);
- p->o.xv = myfread32(h);
- p->o.yv = myfread32(h);
- p->o.vx = myfread32(h);
- p->o.vy = myfread32(h);
- p->o.r = myfread32(h);
- p->o.h = myfread32(h);
- p->looky = myfread32(h);
- p->st = myfread32(h);
- p->s = myfread32(h);
- p->life = myfread32(h);
- p->armor = myfread32(h);
- p->hit = myfread32(h);
- p->hito = myfread32(h);
- p->pain = myfread32(h);
- p->air = myfread32(h);
- p->invl = myfread32(h);
- p->suit = myfread32(h);
- p->d = myfread8(h);
- p->frag = myfread32(h);
- p->ammo = myfread32(h);
- p->shel = myfread32(h);
- p->rock = myfread32(h);
- p->cell = myfread32(h);
- p->fuel = myfread32(h);
- p->kills = myfread32(h);
- p->secrets = myfread32(h);
- p->fire = myfread8(h);
- p->cwpn = myfread8(h);
- p->csnd = myfread8(h);
- p->amul = myfread8(h);
- p->wpns = myfread16(h);
- p->wpn = myfread8(h);
- p->f = myfread8(h);
- p->drawst = myfread8(h);
- p->color = myfread8(h);
- p->id = myfread32(h);
- p->keys = myfread8(h);
- p->lives = myfread8(h);
- // k* not saved
-}
-
-void PL_loadgame (FILE *h) {
- PL_load_player(&pl1, h);
- if (_2pl) {
- PL_load_player(&pl2, h);
- }
- PL_JUMP = myfread32(h);
- PL_RUN = myfread32(h);
- p_immortal = myfread8(h);
-}
-
-static int nonz(int a) {return (a)?a:1;}
-
static int firediry(player_t *p) {
if(p->f&PLF_UP) return -42;
if(p->f&PLF_DOWN) return 19;
static int firediry(player_t *p) {
if(p->f&PLF_UP) return -42;
if(p->f&PLF_DOWN) return 19;
if(p->cwpn) return;
if(p->wpn==8) {
if(!p->fire)
if(p->cwpn) return;
if(p->wpn==8) {
if(!p->fire)
- if(keys[p->kf] && p->cell>=40)
+ if(I_pressed(p->kf) && p->cell>=40)
{Z_sound(snd[5],128);p->fire=21;p->cell-=40;p->drawst|=PL_DRAWWPN;return;}
else return;
if(p->fire==1) p->cwpn=12;
else return;
}else if(p->wpn==1) {
if(!p->csnd) {
{Z_sound(snd[5],128);p->fire=21;p->cell-=40;p->drawst|=PL_DRAWWPN;return;}
else return;
if(p->fire==1) p->cwpn=12;
else return;
}else if(p->wpn==1) {
if(!p->csnd) {
- if(!keys[p->kf]) {Z_sound(snd[7],128);p->csnd=13;return;}
+ if(!I_pressed(p->kf)) {Z_sound(snd[7],128);p->csnd=13;return;}
}
}
- if(keys[p->kf] && !p->fire) {
+ if(I_pressed(p->kf) && !p->fire) {
p->fire=2;
WP_chainsaw(p->o.x+((p->d)?4:-4),p->o.y,(g_dm)?9:3,p->id);
if(!p->csnd) {Z_sound(snd[8],128);p->csnd=29;}
}return;
}else if(p->fire) return;
p->fire=2;
WP_chainsaw(p->o.x+((p->d)?4:-4),p->o.y,(g_dm)?9:3,p->id);
if(!p->csnd) {Z_sound(snd[8],128);p->csnd=29;}
}return;
}else if(p->fire) return;
- if(keys[p->kf] || p->wpn==8) {
+ if(I_pressed(p->kf) || p->wpn==8) {
switch(p->wpn) {
case 2: case 5:
if(!p->ammo) return;
switch(p->wpn) {
case 2: case 5:
if(!p->ammo) return;
static void chgwpn(player_t *p) {
if(p->cwpn) return;
if(p->fire && p->wpn!=1) return;
static void chgwpn(player_t *p) {
if(p->cwpn) return;
if(p->fire && p->wpn!=1) return;
- if(keys[p->kwl]) {
+ if(I_pressed(p->kwl)) {
do{ if(--p->wpn<0) p->wpn=10; }while(!(p->wpns&(1<<p->wpn)));
p->cwpn=3;
do{ if(--p->wpn<0) p->wpn=10; }while(!(p->wpns&(1<<p->wpn)));
p->cwpn=3;
- }else if(keys[p->kwr]) {
+ }else if(I_pressed(p->kwr)) {
do{ if(++p->wpn>10) p->wpn=0; }while(!(p->wpns&(1<<p->wpn)));
p->cwpn=3;
}
do{ if(++p->wpn>10) p->wpn=0; }while(!(p->wpns&(1<<p->wpn)));
p->cwpn=3;
}
}
p->drawst|=PL_DRAWAIR;
}
}
p->drawst|=PL_DRAWAIR;
}
- if(keys[p->kj]) {
+ if(I_pressed(p->kj)) {
if(p_fly) {
p->o.yv=-PL_FLYUP;
}else{
if(p_fly) {
p->o.yv=-PL_FLYUP;
}else{
}
}
}
}
-int PL_isdead(player_t *p) {
+int PL_isdead (player_t *p) {
switch(p->st) {
case DEAD: case MESS:
case OUT:
switch(p->st) {
case DEAD: case MESS:
case OUT:
return 0;
}
return 0;
}
-void PL_init(void) {
- p_immortal=0;
- PL_JUMP=10;PL_RUN=8;
- aitime=0;
+void PL_init (void) {
+ pl1.id = -1;
+ pl2.id = -2;
+ p_immortal = 0;
+ PL_JUMP = 10;
+ PL_RUN = 8;
+ aitime = 0;
}
void PL_alloc(void) {
}
void PL_alloc(void) {
}
}
}
}
-void PL_restore(player_t *p) {
+static void PL_restore(player_t *p) {
p->o.xv=p->o.yv=p->o.vx=p->o.vy=0;
p->o.r=PL_RAD;p->o.h=PL_HT;
p->pain=0;
p->o.xv=p->o.yv=p->o.vx=p->o.vy=0;
p->o.r=PL_RAD;p->o.h=PL_HT;
p->pain=0;
p->keys=(g_dm)?0x70:0;
}
p->keys=(g_dm)?0x70:0;
}
-void PL_reset(void) {
+void PL_reset (void) {
pl1.st=pl2.st=DEAD;
pl1.frag=pl2.frag=0;
}
pl1.st=pl2.st=DEAD;
pl1.frag=pl2.frag=0;
}
-void PL_spawn(player_t *p,int x,int y,char d) {
+void PL_spawn (player_t *p,int x,int y,char d) {
PL_restore(p);
p->o.x=x;p->o.y=y;p->d=d;
p->kills=p->secrets=0;
}
PL_restore(p);
p->o.x=x;p->o.y=y;p->d=d;
p->kills=p->secrets=0;
}
-int PL_hit(player_t *p,int d,int o,int t) {
+int PL_hit (player_t *p,int d,int o,int t) {
if(!d) return 0;
switch(p->st) {
case DIE: case SLOP:
if(!d) return 0;
switch(p->st) {
case DIE: case SLOP:
return 1;
}
return 1;
}
-void PL_damage(player_t *p) {
+void PL_damage (player_t *p) {
int i;
if(!p->hit && p->life>0) return;
int i;
if(!p->hit && p->life>0) return;
return;
}
return;
}
-void PL_cry(player_t *p) {
+void PL_cry (player_t *p) {
Z_sound(snd[(p->pain>20)?1:0],128);
p->f|=PLF_PNSND;
}
Z_sound(snd[(p->pain>20)?1:0],128);
p->f|=PLF_PNSND;
}
-int PL_give(player_t *p,int t) {
+int PL_give (player_t *p, int t) {
int i;
switch(p->st) {
int i;
switch(p->st) {
}
}
}
}
-void PL_act(player_t *p) {
+void PL_act (player_t *p) {
int st;
if(--aitime<0) aitime=0;
int st;
if(--aitime<0) aitime=0;
}else st=0;
if(st&Z_HITWATER) Z_splash(&p->o,PL_RAD+PL_HT);
if(p->f&PLF_FIRE) if(p->fire!=2) p->f-=PLF_FIRE;
}else st=0;
if(st&Z_HITWATER) Z_splash(&p->o,PL_RAD+PL_HT);
if(p->f&PLF_FIRE) if(p->fire!=2) p->f-=PLF_FIRE;
- if(keys[p->ku]) {p->f|=PLF_UP;p->looky-=5;}
+ if(I_pressed(p->ku)) {p->f|=PLF_UP;p->looky-=5;}
else{
p->f&=0xFFFF-PLF_UP;
else{
p->f&=0xFFFF-PLF_UP;
- if(keys[p->kd])
+ if(I_pressed(p->kd))
{p->f|=PLF_DOWN;p->looky+=5;}
else {p->f&=0xFFFF-PLF_DOWN;p->looky=Z_dec(p->looky,5);}
}
{p->f|=PLF_DOWN;p->looky+=5;}
else {p->f&=0xFFFF-PLF_DOWN;p->looky=Z_dec(p->looky,5);}
}
- if(keys[p->kp]) SW_press(p->o.x,p->o.y,p->o.r,p->o.h,1|p->keys,p->id);
+ if(I_pressed(p->kp)) SW_press(p->o.x,p->o.y,p->o.r,p->o.h,1|p->keys,p->id);
if(p->fire) --p->fire;
if(p->cwpn) --p->cwpn;
if(p->csnd) --p->csnd;
if(p->fire) --p->fire;
if(p->cwpn) --p->cwpn;
if(p->csnd) --p->csnd;
if(p_fly)
SMK_gas(p->o.x,p->o.y-2,2,3,p->o.xv+p->o.vx,p->o.yv+p->o.vy,128);
if((p->s+=abs(p->o.xv)/2) >= 24) p->s%=24;
if(p_fly)
SMK_gas(p->o.x,p->o.y-2,2,3,p->o.xv+p->o.vx,p->o.yv+p->o.vy,128);
if((p->s+=abs(p->o.xv)/2) >= 24) p->s%=24;
- if(!keys[p->kl] && !keys[p->kr]) {
+ if(!I_pressed(p->kl) && !I_pressed(p->kr)) {
if(p->o.xv) p->o.xv=Z_dec(p->o.xv,1);
else p->st=STAND;
break;
}
if(p->o.xv) p->o.xv=Z_dec(p->o.xv,1);
else p->st=STAND;
break;
}
- if(p->o.xv<PL_RUN && keys[p->kr]) {p->o.xv+=PL_RUN>>3;p->d=1;}
+ if(p->o.xv<PL_RUN && I_pressed(p->kr)) {p->o.xv+=PL_RUN>>3;p->d=1;}
else if(PL_RUN>8)
SMK_gas(p->o.x,p->o.y-2,2,3,p->o.xv+p->o.vx,p->o.yv+p->o.vy,32);
else if(PL_RUN>8)
SMK_gas(p->o.x,p->o.y-2,2,3,p->o.xv+p->o.vx,p->o.yv+p->o.vy,32);
- if(p->o.xv>-PL_RUN && keys[p->kl]) {p->o.xv-=PL_RUN>>3;p->d=0;}
+ if(p->o.xv>-PL_RUN && I_pressed(p->kl)) {p->o.xv-=PL_RUN>>3;p->d=0;}
else if(PL_RUN>8)
SMK_gas(p->o.x,p->o.y-2,2,3,p->o.xv+p->o.vx,p->o.yv+p->o.vy,32);
break;
else if(PL_RUN>8)
SMK_gas(p->o.x,p->o.y-2,2,3,p->o.xv+p->o.vx,p->o.yv+p->o.vy,32);
break;
chgwpn(p);fire(p);jump(p,st);
if(p_fly)
SMK_gas(p->o.x,p->o.y-2,2,3,p->o.xv+p->o.vx,p->o.yv+p->o.vy,128);
chgwpn(p);fire(p);jump(p,st);
if(p_fly)
SMK_gas(p->o.x,p->o.y-2,2,3,p->o.xv+p->o.vx,p->o.yv+p->o.vy,128);
- if(keys[p->kl]) {p->st=GO;p->s=0;p->d=0;}
- else if(keys[p->kr]) {p->st=GO;p->s=0;p->d=1;}
+ if(I_pressed(p->kl)) {p->st=GO;p->s=0;p->d=0;}
+ else if(I_pressed(p->kr)) {p->st=GO;p->s=0;p->d=1;}
break;
case DEAD:
case MESS:
case OUT:
p->o.xv=Z_dec(p->o.xv,1);
break;
case DEAD:
case MESS:
case OUT:
p->o.xv=Z_dec(p->o.xv,1);
- if(keys[p->ku] || keys[p->kd] || keys[p->kl] || keys[p->kr] ||
- keys[p->kf] || keys[p->kj] || keys[p->kp] || keys[p->kwl] || keys[p->kwr]) {
+ if(I_pressed(p->ku) || I_pressed(p->kd) || I_pressed(p->kl) || I_pressed(p->kr) ||
+ I_pressed(p->kf) || I_pressed(p->kj) || I_pressed(p->kp) || I_pressed(p->kwl) || I_pressed(p->kwr)) {
if(p->st!=OUT) MN_spawn_deadpl(&p->o,p->color,(p->st==MESS)?1:0);
PL_restore(p);
if(g_dm) {G_respawn_player(p);break;}
if(p->st!=OUT) MN_spawn_deadpl(&p->o,p->color,(p->st==MESS)?1:0);
PL_restore(p);
if(g_dm) {G_respawn_player(p);break;}
}
}
}
}
-void bfg_fly(int x,int y,int o) {
+void bfg_fly (int x,int y,int o) {
// if(!g_dm) return;
if(o!=-1) chk_bfg(&pl1,x,y);
if(_2pl) if(o!=-2) chk_bfg(&pl2,x,y);
// if(!g_dm) return;
if(o!=-1) chk_bfg(&pl1,x,y);
if(_2pl) if(o!=-2) chk_bfg(&pl2,x,y);