Optimize, pass entity pointer around instead of index, this avoids expensive multiplies to index into the entity array
This commit is contained in:
parent
4966075052
commit
ff4bd68c0b
|
@ -25,9 +25,9 @@ extern U8 e_bomb_ticker;
|
|||
extern U8 e_bomb_xc;
|
||||
extern U16 e_bomb_yc;
|
||||
|
||||
extern U8 e_bomb_hit(U8);
|
||||
extern U8 e_bomb_hit(ent_t* pEnt);
|
||||
extern void e_bomb_init(U16, U16);
|
||||
extern void e_bomb_action(U8);
|
||||
extern void e_bomb_action(ent_t* pEnt);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
#include "system.h"
|
||||
|
||||
extern void e_bonus_action(U8);
|
||||
extern void e_bonus_action(ent_t*);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
#include "system.h"
|
||||
|
||||
extern void e_box_action(U8);
|
||||
extern void e_box_action(ent_t*);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ extern S16 e_bullet_offsx;
|
|||
extern S16 e_bullet_xc, e_bullet_yc;
|
||||
|
||||
extern void e_bullet_init(U16, U16);
|
||||
extern void e_bullet_action(U8);
|
||||
extern void e_bullet_action(ent_t*);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -36,9 +36,9 @@ extern S16 e_rick_stop_x, e_rick_stop_y;
|
|||
|
||||
extern void e_rick_save(void);
|
||||
extern void e_rick_restore(void);
|
||||
extern void e_rick_action(U8);
|
||||
extern void e_rick_action(ent_t*);
|
||||
extern void e_rick_gozombie(void);
|
||||
extern U8 e_rick_boxtest(U8);
|
||||
extern U8 e_rick_boxtest(ent_t*);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -20,8 +20,8 @@ extern U8 e_sbonus_counting;
|
|||
extern U8 e_sbonus_counter;
|
||||
extern U16 e_sbonus_bonus;
|
||||
|
||||
extern void e_sbonus_start(U8);
|
||||
extern void e_sbonus_stop(U8);
|
||||
extern void e_sbonus_start(ent_t*);
|
||||
extern void e_sbonus_stop(ent_t*);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -18,11 +18,11 @@
|
|||
|
||||
extern U32 e_them_rndseed;
|
||||
|
||||
extern void e_them_t1a_action(U8);
|
||||
extern void e_them_t1b_action(U8);
|
||||
extern void e_them_t2_action(U8);
|
||||
extern void e_them_t3_action(U8);
|
||||
extern void e_them_z_action(U8);
|
||||
extern void e_them_t1a_action(ent_t*);
|
||||
extern void e_them_t1b_action(ent_t*);
|
||||
extern void e_them_t2_action(ent_t*);
|
||||
extern void e_them_t3_action(ent_t*);
|
||||
extern void e_them_z_action(ent_t*);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -14,10 +14,12 @@
|
|||
#ifndef _UTIL_H
|
||||
#define _UTIL_H
|
||||
|
||||
#include "ents.h"
|
||||
|
||||
extern void u_envtest(S16, S16, U8, U8 *, U8 *);
|
||||
extern U8 u_boxtest(U8, U8);
|
||||
extern U8 u_fboxtest(U8, S16, S16);
|
||||
extern U8 u_trigbox(U8, S16, S16);
|
||||
extern U8 u_boxtest(ent_t*, ent_t*);
|
||||
extern U8 u_fboxtest(ent_t*, S16, S16);
|
||||
extern U8 u_trigbox(ent_t* pEnt, S16, S16);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
16
src/e_bomb.c
16
src/e_bomb.c
|
@ -41,15 +41,15 @@ U8 e_bomb_ticker;
|
|||
* ASM 11CD
|
||||
* returns: TRUE/hit, FALSE/not
|
||||
*/
|
||||
U8 e_bomb_hit(U8 e)
|
||||
U8 e_bomb_hit(ent_t *pEnt)
|
||||
{
|
||||
if (ent_ents[e].x > (E_BOMB_ENT.x >= 0xE0 ? 0xFF : E_BOMB_ENT.x + 0x20))
|
||||
if (pEnt->x > (E_BOMB_ENT.x >= 0xE0 ? 0xFF : E_BOMB_ENT.x + 0x20))
|
||||
return FALSE;
|
||||
if (ent_ents[e].x + ent_ents[e].w < (E_BOMB_ENT.x > 0x04 ? E_BOMB_ENT.x - 0x04 : 0))
|
||||
if (pEnt->x + pEnt->w < (E_BOMB_ENT.x > 0x04 ? E_BOMB_ENT.x - 0x04 : 0))
|
||||
return FALSE;
|
||||
if (ent_ents[e].y > (E_BOMB_ENT.y + 0x1D))
|
||||
if (pEnt->y > (E_BOMB_ENT.y + 0x1D))
|
||||
return FALSE;
|
||||
if (ent_ents[e].y + ent_ents[e].h < (E_BOMB_ENT.y > 0x0004 ? E_BOMB_ENT.y - 0x0004 : 0))
|
||||
if (pEnt->y + pEnt->h < (E_BOMB_ENT.y > 0x0004 ? E_BOMB_ENT.y - 0x0004 : 0))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ void e_bomb_init(U16 x, U16 y)
|
|||
* ASM 18CA
|
||||
*/
|
||||
void
|
||||
e_bomb_action(UNUSED(U8 e))
|
||||
e_bomb_action(UNUSED(ent_t* pEnt))
|
||||
{
|
||||
/* tick */
|
||||
e_bomb_ticker--;
|
||||
|
@ -133,7 +133,7 @@ e_bomb_action(UNUSED(U8 e))
|
|||
e_bomb_xc = E_BOMB_ENT.x + 0x0C;
|
||||
e_bomb_yc = E_BOMB_ENT.y + 0x000A;
|
||||
e_bomb_lethal = TRUE;
|
||||
if (e_bomb_hit(E_RICK_NO))
|
||||
if (e_bomb_hit(&ent_ents[E_RICK_NO]))
|
||||
e_rick_gozombie();
|
||||
}
|
||||
else
|
||||
|
@ -148,7 +148,7 @@ e_bomb_action(UNUSED(U8 e))
|
|||
E_BOMB_ENT.sprite = 0xa8 + 4 - (e_bomb_ticker >> 1);
|
||||
#endif
|
||||
/* exploding, hence lethal */
|
||||
if (e_bomb_hit(E_RICK_NO))
|
||||
if (e_bomb_hit(&ent_ents[E_RICK_NO]))
|
||||
e_rick_gozombie();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,31 +30,31 @@ segment "e";
|
|||
* ASM 242C
|
||||
*/
|
||||
void
|
||||
e_bonus_action(U8 e)
|
||||
e_bonus_action(ent_t *pEnt)
|
||||
{
|
||||
#define seq c1
|
||||
|
||||
if (ent_ents[e].seq == 0) {
|
||||
if (e_rick_boxtest(e)) {
|
||||
if (pEnt->seq == 0) {
|
||||
if (e_rick_boxtest(pEnt)) {
|
||||
game_score += 500;
|
||||
#ifdef ENABLE_SOUND
|
||||
syssnd_play(WAV_BONUS, 1);
|
||||
#endif
|
||||
map_marks[ent_ents[e].mark].ent |= MAP_MARK_NACT;
|
||||
ent_ents[e].seq = 1;
|
||||
ent_ents[e].sprite = 0xad;
|
||||
ent_ents[e].front = TRUE;
|
||||
ent_ents[e].y -= 0x08;
|
||||
map_marks[pEnt->mark].ent |= MAP_MARK_NACT;
|
||||
pEnt->seq = 1;
|
||||
pEnt->sprite = 0xad;
|
||||
pEnt->front = TRUE;
|
||||
pEnt->y -= 0x08;
|
||||
}
|
||||
}
|
||||
|
||||
else if (ent_ents[e].seq > 0 && ent_ents[e].seq < 10) {
|
||||
ent_ents[e].seq++;
|
||||
ent_ents[e].y -= 2;
|
||||
else if (pEnt->seq > 0 && pEnt->seq < 10) {
|
||||
pEnt->seq++;
|
||||
pEnt->y -= 2;
|
||||
}
|
||||
|
||||
else {
|
||||
ent_ents[e].n = 0;
|
||||
pEnt->n = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
40
src/e_box.c
40
src/e_box.c
|
@ -42,7 +42,7 @@ segment "e";
|
|||
/*
|
||||
* Prototypes
|
||||
*/
|
||||
static void explode(U8);
|
||||
static void explode(ent_t*);
|
||||
|
||||
/*
|
||||
* Entity action
|
||||
|
@ -50,49 +50,49 @@ static void explode(U8);
|
|||
* ASM 245A
|
||||
*/
|
||||
void
|
||||
e_box_action(U8 e)
|
||||
e_box_action(ent_t* pEnt)
|
||||
{
|
||||
static U8 sp[] = {0x24, 0x25, 0x26, 0x27, 0x28}; /* explosion sprites sequence */
|
||||
|
||||
if (ent_ents[e].n & ENT_LETHAL) {
|
||||
if (pEnt->n & ENT_LETHAL) {
|
||||
/*
|
||||
* box is lethal i.e. exploding
|
||||
* play sprites sequence then stop
|
||||
*/
|
||||
ent_ents[e].sprite = sp[ent_ents[e].cnt >> 1];
|
||||
if (--ent_ents[e].cnt == 0) {
|
||||
ent_ents[e].n = 0;
|
||||
map_marks[ent_ents[e].mark].ent |= MAP_MARK_NACT;
|
||||
pEnt->sprite = sp[pEnt->cnt >> 1];
|
||||
if (--pEnt->cnt == 0) {
|
||||
pEnt->n = 0;
|
||||
map_marks[pEnt->mark].ent |= MAP_MARK_NACT;
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* not lethal: check to see if triggered
|
||||
*/
|
||||
if (e_rick_boxtest(e)) {
|
||||
if (e_rick_boxtest(pEnt)) {
|
||||
/* rick: collect bombs or bullets and stop */
|
||||
#ifdef ENABLE_SOUND
|
||||
syssnd_play(WAV_BOX, 1);
|
||||
#endif
|
||||
if (ent_ents[e].n == 0x10)
|
||||
if (pEnt->n == 0x10)
|
||||
game_bombs = GAME_BOMBS_INIT;
|
||||
else /* 0x11 */
|
||||
game_bullets = GAME_BULLETS_INIT;
|
||||
ent_ents[e].n = 0;
|
||||
map_marks[ent_ents[e].mark].ent |= MAP_MARK_NACT;
|
||||
pEnt->n = 0;
|
||||
map_marks[pEnt->mark].ent |= MAP_MARK_NACT;
|
||||
}
|
||||
else if (E_RICK_STTST(E_RICK_STSTOP) &&
|
||||
u_fboxtest(e, e_rick_stop_x, e_rick_stop_y)) {
|
||||
u_fboxtest(pEnt, e_rick_stop_x, e_rick_stop_y)) {
|
||||
/* rick's stick: explode */
|
||||
explode(e);
|
||||
explode(pEnt);
|
||||
}
|
||||
else if (E_BULLET_ENT.n && u_fboxtest(e, e_bullet_xc, e_bullet_yc)) {
|
||||
else if (E_BULLET_ENT.n && u_fboxtest(pEnt, e_bullet_xc, e_bullet_yc)) {
|
||||
/* bullet: explode (and stop bullet) */
|
||||
E_BULLET_ENT.n = 0;
|
||||
explode(e);
|
||||
explode(pEnt);
|
||||
}
|
||||
else if (e_bomb_lethal && e_bomb_hit(e)) {
|
||||
else if (e_bomb_lethal && e_bomb_hit(pEnt)) {
|
||||
/* bomb: explode */
|
||||
explode(e);
|
||||
explode(pEnt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -101,10 +101,10 @@ e_box_action(U8 e)
|
|||
/*
|
||||
* Explode when
|
||||
*/
|
||||
static void explode(U8 e)
|
||||
static void explode(ent_t* pEnt)
|
||||
{
|
||||
ent_ents[e].cnt = SEQ_INIT;
|
||||
ent_ents[e].n |= ENT_LETHAL;
|
||||
pEnt->cnt = SEQ_INIT;
|
||||
pEnt->n |= ENT_LETHAL;
|
||||
#ifdef ENABLE_SOUND
|
||||
syssnd_play(WAV_EXPLODE, 1);
|
||||
#endif
|
||||
|
|
|
@ -58,7 +58,7 @@ e_bullet_init(U16 x, U16 y)
|
|||
* ASM 1883, 0F97
|
||||
*/
|
||||
void
|
||||
e_bullet_action(UNUSED(U8 e))
|
||||
e_bullet_action(UNUSED(ent_t* pEnt))
|
||||
{
|
||||
/* move bullet */
|
||||
E_BULLET_ENT.x += e_bullet_offsx;
|
||||
|
|
12
src/e_rick.c
12
src/e_rick.c
|
@ -62,17 +62,17 @@ static U16 save_x, save_y;
|
|||
* ret: TRUE/intersect, FALSE/not.
|
||||
*/
|
||||
U8
|
||||
e_rick_boxtest(U8 e)
|
||||
e_rick_boxtest(ent_t* pEnt)
|
||||
{
|
||||
/*
|
||||
* rick: x+0x05 to x+0x11, y+[0x08 if rick's crawling] to y+0x14
|
||||
* entity: x to x+w, y to y+h
|
||||
*/
|
||||
|
||||
if (E_RICK_ENT.x + 0x11 < ent_ents[e].x ||
|
||||
E_RICK_ENT.x + 0x05 > ent_ents[e].x + ent_ents[e].w ||
|
||||
E_RICK_ENT.y + 0x14 < ent_ents[e].y ||
|
||||
E_RICK_ENT.y + (E_RICK_STTST(E_RICK_STCRAWL) ? 0x08 : 0x00) > ent_ents[e].y + ent_ents[e].h - 1)
|
||||
if (E_RICK_ENT.x + 0x11 < pEnt->x ||
|
||||
E_RICK_ENT.x + 0x05 > pEnt->x + pEnt->w ||
|
||||
E_RICK_ENT.y + 0x14 < pEnt->y ||
|
||||
E_RICK_ENT.y + (E_RICK_STTST(E_RICK_STCRAWL) ? 0x08 : 0x00) > pEnt->y + pEnt->h - 1)
|
||||
return FALSE;
|
||||
else
|
||||
return TRUE;
|
||||
|
@ -449,7 +449,7 @@ e_rick_action2(void)
|
|||
*
|
||||
* ASM 12CA
|
||||
*/
|
||||
void e_rick_action(UNUSED(U8 e))
|
||||
void e_rick_action(UNUSED(ent_t* pEnt))
|
||||
{
|
||||
static U8 stopped = FALSE; /* is this the most elegant way? */
|
||||
|
||||
|
|
|
@ -39,12 +39,12 @@ U16 e_sbonus_bonus = 0;
|
|||
* ASM 2182
|
||||
*/
|
||||
void
|
||||
e_sbonus_start(U8 e)
|
||||
e_sbonus_start(ent_t* pEnt)
|
||||
{
|
||||
ent_ents[e].sprite = 0; /* invisible */
|
||||
if (u_trigbox(e, ENT_XRICK.x + 0x0C, ENT_XRICK.y + 0x0A)) {
|
||||
pEnt->sprite = 0; /* invisible */
|
||||
if (u_trigbox(pEnt, ENT_XRICK.x + 0x0C, ENT_XRICK.y + 0x0A)) {
|
||||
/* rick is within trigger box */
|
||||
ent_ents[e].n = 0;
|
||||
pEnt->n = 0;
|
||||
e_sbonus_counting = TRUE; /* 6DD5 */
|
||||
e_sbonus_counter = 0x1e; /* 6DDB */
|
||||
e_sbonus_bonus = 2000; /* 291A-291D */
|
||||
|
@ -61,23 +61,23 @@ e_sbonus_start(U8 e)
|
|||
* ASM 2143
|
||||
*/
|
||||
void
|
||||
e_sbonus_stop(U8 e)
|
||||
e_sbonus_stop(ent_t* pEnt)
|
||||
{
|
||||
ent_ents[e].sprite = 0; /* invisible */
|
||||
pEnt->sprite = 0; /* invisible */
|
||||
|
||||
if (!e_sbonus_counting)
|
||||
return;
|
||||
|
||||
if (u_trigbox(e, ENT_XRICK.x + 0x0C, ENT_XRICK.y + 0x0A)) {
|
||||
if (u_trigbox(pEnt, ENT_XRICK.x + 0x0C, ENT_XRICK.y + 0x0A)) {
|
||||
/* rick is within trigger box */
|
||||
e_sbonus_counting = FALSE; /* stop counting */
|
||||
ent_ents[e].n = 0; /* deactivate entity */
|
||||
pEnt->n = 0; /* deactivate entity */
|
||||
game_score += e_sbonus_bonus; /* add bonus to score */
|
||||
#ifdef ENABLE_SOUND
|
||||
syssnd_play(WAV_SBONUS2, 1);
|
||||
#endif
|
||||
/* make sure the entity won't be activated again */
|
||||
map_marks[ent_ents[e].mark].ent |= MAP_MARK_NACT;
|
||||
map_marks[pEnt->mark].ent |= MAP_MARK_NACT;
|
||||
}
|
||||
else {
|
||||
/* keep counting */
|
||||
|
|
368
src/e_them.c
368
src/e_them.c
|
@ -50,15 +50,15 @@ segment "e";
|
|||
* ret: TRUE/boxtests, FALSE/not
|
||||
*/
|
||||
U8
|
||||
u_themtest(U8 e)
|
||||
u_themtest(ent_t* pEnt)
|
||||
{
|
||||
U8 i;
|
||||
ent_t* pI;
|
||||
|
||||
if ((ent_ents[0].n & ENT_LETHAL) && u_boxtest(e, 0))
|
||||
if ((ent_ents[0].n & ENT_LETHAL) && u_boxtest(pEnt, ent_ents))
|
||||
return TRUE;
|
||||
|
||||
for (i = 4; i < 9; i++)
|
||||
if ((ent_ents[i].n & ENT_LETHAL) && u_boxtest(e, i))
|
||||
for (pI = &ent_ents[4]; pI < &ent_ents[9]; pI++)
|
||||
if ((pI->n & ENT_LETHAL) && u_boxtest(pEnt, pI))
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
|
@ -71,21 +71,21 @@ u_themtest(U8 e)
|
|||
* ASM 237B
|
||||
*/
|
||||
void
|
||||
e_them_gozombie(U8 e)
|
||||
e_them_gozombie(ent_t* pEnt)
|
||||
{
|
||||
#define offsx c1
|
||||
ent_ents[e].n = 0x47; /* zombie entity */
|
||||
ent_ents[e].front = TRUE;
|
||||
ent_ents[e].offsy = -0x0400;
|
||||
pEnt->n = 0x47; /* zombie entity */
|
||||
pEnt->front = TRUE;
|
||||
pEnt->offsy = -0x0400;
|
||||
#ifdef ENABLE_SOUND
|
||||
syssnd_play(WAV_DIE, 1);
|
||||
#endif
|
||||
game_score += 50;
|
||||
if (ent_ents[e].flags & ENT_FLG_ONCE) {
|
||||
if (pEnt->flags & ENT_FLG_ONCE) {
|
||||
/* make sure entity won't be activated again */
|
||||
map_marks[ent_ents[e].mark].ent |= MAP_MARK_NACT;
|
||||
map_marks[pEnt->mark].ent |= MAP_MARK_NACT;
|
||||
}
|
||||
ent_ents[e].offsx = (ent_ents[e].x >= 0x80 ? -0x02 : 0x02);
|
||||
pEnt->offsx = (pEnt->x >= 0x80 ? -0x02 : 0x02);
|
||||
#undef offsx
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,7 @@ e_them_gozombie(U8 e)
|
|||
* ASM 2242
|
||||
*/
|
||||
void
|
||||
e_them_t1_action2(U8 e, U8 type)
|
||||
e_them_t1_action2(ent_t* pEnt, U8 type)
|
||||
{
|
||||
#define offsx c1
|
||||
#define step_count c2
|
||||
|
@ -110,105 +110,105 @@ e_them_t1_action2(U8 e, U8 type)
|
|||
U8 env0, env1;
|
||||
|
||||
/* by default, try vertical move. calculate new y */
|
||||
i = (((S32)ent_ents[e].y) << 8) + ((S32)ent_ents[e].offsy) + ((U32)ent_ents[e].ylow);
|
||||
i = (((S32)pEnt->y) << 8) + ((S32)pEnt->offsy) + ((U32)pEnt->ylow);
|
||||
y = i >> 8;
|
||||
|
||||
/* deactivate if outside vertical boundaries */
|
||||
/* no need to test zero since e_them _t1a/b don't go up */
|
||||
/* FIXME what if they got scrolled out ? */
|
||||
if (y > 0x140) {
|
||||
ent_ents[e].n = 0;
|
||||
pEnt->n = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
/* test environment */
|
||||
u_envtest(ent_ents[e].x, y, FALSE, &env0, &env1);
|
||||
u_envtest(pEnt->x, y, FALSE, &env0, &env1);
|
||||
|
||||
if (!(env1 & (MAP_EFLG_VERT|MAP_EFLG_SOLID|MAP_EFLG_SPAD|MAP_EFLG_WAYUP))) {
|
||||
/* vertical move possible: falling */
|
||||
if (env1 & MAP_EFLG_LETHAL) {
|
||||
/* lethal entities kill e_them */
|
||||
e_them_gozombie(e);
|
||||
e_them_gozombie(pEnt);
|
||||
return;
|
||||
}
|
||||
/* save, cleanup and return */
|
||||
ent_ents[e].y = y;
|
||||
ent_ents[e].ylow = i;
|
||||
ent_ents[e].offsy += 0x0080;
|
||||
if (ent_ents[e].offsy > 0x0800)
|
||||
ent_ents[e].offsy = 0x0800;
|
||||
pEnt->y = y;
|
||||
pEnt->ylow = i;
|
||||
pEnt->offsy += 0x0080;
|
||||
if (pEnt->offsy > 0x0800)
|
||||
pEnt->offsy = 0x0800;
|
||||
return;
|
||||
}
|
||||
|
||||
/* vertical move not possible. calculate new sprite */
|
||||
ent_ents[e].sprite = ent_ents[e].sprbase
|
||||
+ ent_sprseq[(ent_ents[e].x & 0x1c) >> 3]
|
||||
+ (ent_ents[e].offsx < 0 ? 0x03 : 0x00);
|
||||
pEnt->sprite = pEnt->sprbase
|
||||
+ ent_sprseq[(pEnt->x & 0x1c) >> 3]
|
||||
+ (pEnt->offsx < 0 ? 0x03 : 0x00);
|
||||
|
||||
/* reset offsy */
|
||||
ent_ents[e].offsy = 0x0080;
|
||||
pEnt->offsy = 0x0080;
|
||||
|
||||
/* align to ground */
|
||||
ent_ents[e].y &= 0xfff8;
|
||||
ent_ents[e].y |= 0x0003;
|
||||
pEnt->y &= 0xfff8;
|
||||
pEnt->y |= 0x0003;
|
||||
|
||||
/* latency: if not zero then decrease and return */
|
||||
if (ent_ents[e].latency > 0) {
|
||||
ent_ents[e].latency--;
|
||||
if (pEnt->latency > 0) {
|
||||
pEnt->latency--;
|
||||
return;
|
||||
}
|
||||
|
||||
/* horizontal move. calculate new x */
|
||||
if (ent_ents[e].offsx == 0) /* not supposed to move -> don't */
|
||||
if (pEnt->offsx == 0) /* not supposed to move -> don't */
|
||||
return;
|
||||
|
||||
x = ent_ents[e].x + ent_ents[e].offsx;
|
||||
if (ent_ents[e].x < 0 || ent_ents[e].x > 0xe8) {
|
||||
x = pEnt->x + pEnt->offsx;
|
||||
if (pEnt->x < 0 || pEnt->x > 0xe8) {
|
||||
/* U-turn and return if reaching horizontal boundaries */
|
||||
ent_ents[e].step_count = 0;
|
||||
ent_ents[e].offsx = -ent_ents[e].offsx;
|
||||
pEnt->step_count = 0;
|
||||
pEnt->offsx = -pEnt->offsx;
|
||||
return;
|
||||
}
|
||||
|
||||
/* test environment */
|
||||
u_envtest(x, ent_ents[e].y, FALSE, &env0, &env1);
|
||||
u_envtest(x, pEnt->y, FALSE, &env0, &env1);
|
||||
|
||||
if (env1 & (MAP_EFLG_VERT|MAP_EFLG_SOLID|MAP_EFLG_SPAD|MAP_EFLG_WAYUP)) {
|
||||
/* horizontal move not possible: u-turn and return */
|
||||
ent_ents[e].step_count = 0;
|
||||
ent_ents[e].offsx = -ent_ents[e].offsx;
|
||||
pEnt->step_count = 0;
|
||||
pEnt->offsx = -pEnt->offsx;
|
||||
return;
|
||||
}
|
||||
|
||||
/* horizontal move possible */
|
||||
if (env1 & MAP_EFLG_LETHAL) {
|
||||
/* lethal entities kill e_them */
|
||||
e_them_gozombie(e);
|
||||
e_them_gozombie(pEnt);
|
||||
return;
|
||||
}
|
||||
|
||||
/* save */
|
||||
ent_ents[e].x = x;
|
||||
pEnt->x = x;
|
||||
|
||||
/* depending on type, */
|
||||
if (type == TYPE_1B) {
|
||||
/* set direction to move horizontally towards rick */
|
||||
if ((ent_ents[e].x & 0x1e) != 0x10) /* prevents too frequent u-turns */
|
||||
if ((pEnt->x & 0x1e) != 0x10) /* prevents too frequent u-turns */
|
||||
return;
|
||||
ent_ents[e].offsx = (ent_ents[e].x < E_RICK_ENT.x) ? 0x02 : -0x02;
|
||||
pEnt->offsx = (pEnt->x < E_RICK_ENT.x) ? 0x02 : -0x02;
|
||||
return;
|
||||
}
|
||||
else {
|
||||
/* set direction according to step counter */
|
||||
ent_ents[e].step_count++;
|
||||
pEnt->step_count++;
|
||||
/* FIXME why trig_x (b16) ?? */
|
||||
if ((ent_ents[e].trig_x >> 1) > ent_ents[e].step_count)
|
||||
if ((pEnt->trig_x >> 1) > pEnt->step_count)
|
||||
return;
|
||||
}
|
||||
|
||||
/* type is 1A and step counter reached its limit: u-turn */
|
||||
ent_ents[e].step_count = 0;
|
||||
ent_ents[e].offsx = -ent_ents[e].offsx;
|
||||
pEnt->step_count = 0;
|
||||
pEnt->offsx = -pEnt->offsx;
|
||||
#undef offsx
|
||||
#undef step_count
|
||||
}
|
||||
|
@ -218,38 +218,38 @@ e_them_t1_action2(U8 e, U8 type)
|
|||
* ASM 21CF
|
||||
*/
|
||||
void
|
||||
e_them_t1_action(U8 e, U8 type)
|
||||
e_them_t1_action(ent_t* pEnt, U8 type)
|
||||
{
|
||||
e_them_t1_action2(e, type);
|
||||
e_them_t1_action2(pEnt, type);
|
||||
|
||||
/* lethal entities kill them */
|
||||
if (u_themtest(e)) {
|
||||
e_them_gozombie(e);
|
||||
if (u_themtest(pEnt)) {
|
||||
e_them_gozombie(pEnt);
|
||||
return;
|
||||
}
|
||||
|
||||
/* bullet kills them */
|
||||
if (E_BULLET_ENT.n &&
|
||||
u_fboxtest(e, E_BULLET_ENT.x + (e_bullet_offsx < 0 ? 0 : 0x18),
|
||||
u_fboxtest(pEnt, E_BULLET_ENT.x + (e_bullet_offsx < 0 ? 0 : 0x18),
|
||||
E_BULLET_ENT.y)) {
|
||||
E_BULLET_ENT.n = 0;
|
||||
e_them_gozombie(e);
|
||||
e_them_gozombie(pEnt);
|
||||
return;
|
||||
}
|
||||
|
||||
/* bomb kills them */
|
||||
if (e_bomb_lethal && e_bomb_hit(e)) {
|
||||
e_them_gozombie(e);
|
||||
if (e_bomb_lethal && e_bomb_hit(pEnt)) {
|
||||
e_them_gozombie(pEnt);
|
||||
return;
|
||||
}
|
||||
|
||||
/* rick stops them */
|
||||
if (E_RICK_STTST(E_RICK_STSTOP) &&
|
||||
u_fboxtest(e, e_rick_stop_x, e_rick_stop_y))
|
||||
ent_ents[e].latency = 0x14;
|
||||
u_fboxtest(pEnt, e_rick_stop_x, e_rick_stop_y))
|
||||
pEnt->latency = 0x14;
|
||||
|
||||
/* they kill rick */
|
||||
if (e_rick_boxtest(e))
|
||||
if (e_rick_boxtest(pEnt))
|
||||
e_rick_gozombie();
|
||||
}
|
||||
|
||||
|
@ -260,9 +260,9 @@ e_them_t1_action(U8 e, U8 type)
|
|||
* ASM 2452
|
||||
*/
|
||||
void
|
||||
e_them_t1a_action(U8 e)
|
||||
e_them_t1a_action(ent_t* pEnt)
|
||||
{
|
||||
e_them_t1_action(e, TYPE_1A);
|
||||
e_them_t1_action(pEnt, TYPE_1A);
|
||||
}
|
||||
|
||||
|
||||
|
@ -272,9 +272,9 @@ e_them_t1a_action(U8 e)
|
|||
* ASM 21CA
|
||||
*/
|
||||
void
|
||||
e_them_t1b_action(U8 e)
|
||||
e_them_t1b_action(ent_t* pEnt)
|
||||
{
|
||||
e_them_t1_action(e, TYPE_1B);
|
||||
e_them_t1_action(pEnt, TYPE_1B);
|
||||
}
|
||||
|
||||
|
||||
|
@ -284,37 +284,37 @@ e_them_t1b_action(U8 e)
|
|||
* ASM 23B8
|
||||
*/
|
||||
void
|
||||
e_them_z_action(U8 e)
|
||||
e_them_z_action(ent_t* pEnt)
|
||||
{
|
||||
#define offsx c1
|
||||
U32 i;
|
||||
|
||||
/* calc new sprite */
|
||||
ent_ents[e].sprite = ent_ents[e].sprbase
|
||||
+ ((ent_ents[e].x & 0x04) ? 0x07 : 0x06);
|
||||
pEnt->sprite = pEnt->sprbase
|
||||
+ ((pEnt->x & 0x04) ? 0x07 : 0x06);
|
||||
|
||||
/* calc new y */
|
||||
i = (((S32)ent_ents[e].y) << 8) + ((S32)ent_ents[e].offsy) + ((U32)ent_ents[e].ylow);
|
||||
i = (((S32)pEnt->y) << 8) + ((S32)pEnt->offsy) + ((U32)pEnt->ylow);
|
||||
|
||||
/* deactivate if out of vertical boundaries */
|
||||
if (ent_ents[e].y < 0 || ent_ents[e].y > 0x0140) {
|
||||
ent_ents[e].n = 0;
|
||||
if (pEnt->y < 0 || pEnt->y > 0x0140) {
|
||||
pEnt->n = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
/* save */
|
||||
ent_ents[e].offsy += 0x0080;
|
||||
ent_ents[e].ylow = i;
|
||||
ent_ents[e].y = i >> 8;
|
||||
pEnt->offsy += 0x0080;
|
||||
pEnt->ylow = i;
|
||||
pEnt->y = i >> 8;
|
||||
|
||||
/* calc new x */
|
||||
ent_ents[e].x += ent_ents[e].offsx;
|
||||
pEnt->x += pEnt->offsx;
|
||||
|
||||
/* must stay within horizontal boundaries */
|
||||
if (ent_ents[e].x < 0)
|
||||
ent_ents[e].x = 0;
|
||||
if (ent_ents[e].x > 0xe8)
|
||||
ent_ents[e].x = 0xe8;
|
||||
if (pEnt->x < 0)
|
||||
pEnt->x = 0;
|
||||
if (pEnt->x > 0xe8)
|
||||
pEnt->x = 0xe8;
|
||||
#undef offsx
|
||||
}
|
||||
|
||||
|
@ -327,7 +327,7 @@ e_them_z_action(U8 e)
|
|||
* ASM 2792
|
||||
*/
|
||||
void
|
||||
e_them_t2_action2(U8 e)
|
||||
e_them_t2_action2(ent_t* pEnt)
|
||||
{
|
||||
#define flgclmb c1
|
||||
#define offsx c2
|
||||
|
@ -351,50 +351,50 @@ e_them_t2_action2(U8 e)
|
|||
/*sys_printf("e_them_t2 ------------------------------\n");*/
|
||||
|
||||
/* latency: if not zero then decrease */
|
||||
if (ent_ents[e].latency > 0) ent_ents[e].latency--;
|
||||
if (pEnt->latency > 0) pEnt->latency--;
|
||||
|
||||
/* climbing? */
|
||||
if (ent_ents[e].flgclmb != TRUE) goto climbing_not;
|
||||
if (pEnt->flgclmb != TRUE) goto climbing_not;
|
||||
|
||||
/* CLIMBING */
|
||||
|
||||
/*sys_printf("e_them_t2 climbing\n");*/
|
||||
|
||||
/* latency: if not zero then return */
|
||||
if (ent_ents[e].latency > 0) return;
|
||||
if (pEnt->latency > 0) return;
|
||||
|
||||
/* calc new sprite */
|
||||
ent_ents[e].sprite = ent_ents[e].sprbase + 0x08 +
|
||||
(((ent_ents[e].x ^ ent_ents[e].y) & 0x04) ? 1 : 0);
|
||||
pEnt->sprite = pEnt->sprbase + 0x08 +
|
||||
(((pEnt->x ^ pEnt->y) & 0x04) ? 1 : 0);
|
||||
|
||||
/* reached rick's level? */
|
||||
if ((ent_ents[e].y & 0xfe) != (E_RICK_ENT.y & 0xfe)) goto ymove;
|
||||
if ((pEnt->y & 0xfe) != (E_RICK_ENT.y & 0xfe)) goto ymove;
|
||||
|
||||
xmove:
|
||||
/* calc new x and test environment */
|
||||
ent_ents[e].offsx = (ent_ents[e].x < E_RICK_ENT.x) ? 0x02 : -0x02;
|
||||
x = ent_ents[e].x + ent_ents[e].offsx;
|
||||
u_envtest(x, ent_ents[e].y, FALSE, &env0, &env1);
|
||||
pEnt->offsx = (pEnt->x < E_RICK_ENT.x) ? 0x02 : -0x02;
|
||||
x = pEnt->x + pEnt->offsx;
|
||||
u_envtest(x, pEnt->y, FALSE, &env0, &env1);
|
||||
if (env1 & (MAP_EFLG_SOLID|MAP_EFLG_SPAD|MAP_EFLG_WAYUP))
|
||||
return;
|
||||
if (env1 & MAP_EFLG_LETHAL) {
|
||||
e_them_gozombie(e);
|
||||
e_them_gozombie(pEnt);
|
||||
return;
|
||||
}
|
||||
ent_ents[e].x = x;
|
||||
pEnt->x = x;
|
||||
if (env1 & (MAP_EFLG_VERT|MAP_EFLG_CLIMB)) /* still climbing */
|
||||
return;
|
||||
goto climbing_not; /* not climbing anymore */
|
||||
|
||||
ymove:
|
||||
/* calc new y and test environment */
|
||||
yd = ent_ents[e].y < E_RICK_ENT.y ? 0x02 : -0x02;
|
||||
y = ent_ents[e].y + yd;
|
||||
yd = pEnt->y < E_RICK_ENT.y ? 0x02 : -0x02;
|
||||
y = pEnt->y + yd;
|
||||
if (y < 0 || y > 0x0140) {
|
||||
ent_ents[e].n = 0;
|
||||
pEnt->n = 0;
|
||||
return;
|
||||
}
|
||||
u_envtest(ent_ents[e].x, y, FALSE, &env0, &env1);
|
||||
u_envtest(pEnt->x, y, FALSE, &env0, &env1);
|
||||
if (env1 & (MAP_EFLG_SOLID|MAP_EFLG_SPAD|MAP_EFLG_WAYUP)) {
|
||||
if (yd < 0)
|
||||
goto xmove; /* can't go up */
|
||||
|
@ -402,7 +402,7 @@ e_them_t2_action2(U8 e)
|
|||
goto climbing_not; /* can't go down */
|
||||
}
|
||||
/* can move */
|
||||
ent_ents[e].y = y;
|
||||
pEnt->y = y;
|
||||
if (env1 & (MAP_EFLG_VERT|MAP_EFLG_CLIMB)) /* still climbing */
|
||||
return;
|
||||
|
||||
|
@ -411,70 +411,70 @@ e_them_t2_action2(U8 e)
|
|||
climbing_not:
|
||||
/*sys_printf("e_them_t2 climbing NOT\n");*/
|
||||
|
||||
ent_ents[e].flgclmb = FALSE; /* not climbing */
|
||||
pEnt->flgclmb = FALSE; /* not climbing */
|
||||
|
||||
/* calc new y (falling) and test environment */
|
||||
i = (ent_ents[e].y << 8) + ent_ents[e].offsy + ent_ents[e].ylow;
|
||||
i = (pEnt->y << 8) + pEnt->offsy + pEnt->ylow;
|
||||
y = i >> 8;
|
||||
u_envtest(ent_ents[e].x, y, FALSE, &env0, &env1);
|
||||
u_envtest(pEnt->x, y, FALSE, &env0, &env1);
|
||||
if (!(env1 & (MAP_EFLG_SOLID|MAP_EFLG_SPAD|MAP_EFLG_WAYUP))) {
|
||||
/*sys_printf("e_them_t2 y move OK\n");*/
|
||||
/* can go there */
|
||||
if (env1 & MAP_EFLG_LETHAL) {
|
||||
e_them_gozombie(e);
|
||||
e_them_gozombie(pEnt);
|
||||
return;
|
||||
}
|
||||
if (y > 0x0140) { /* deactivate if outside */
|
||||
ent_ents[e].n = 0;
|
||||
pEnt->n = 0;
|
||||
return;
|
||||
}
|
||||
if (!(env1 & MAP_EFLG_VERT)) {
|
||||
/* save */
|
||||
ent_ents[e].y = y;
|
||||
ent_ents[e].ylow = i;
|
||||
ent_ents[e].offsy += 0x0080;
|
||||
if (ent_ents[e].offsy > 0x0800)
|
||||
ent_ents[e].offsy = 0x0800;
|
||||
pEnt->y = y;
|
||||
pEnt->ylow = i;
|
||||
pEnt->offsy += 0x0080;
|
||||
if (pEnt->offsy > 0x0800)
|
||||
pEnt->offsy = 0x0800;
|
||||
return;
|
||||
}
|
||||
if (((ent_ents[e].x & 0x07) == 0x04) && (y < E_RICK_ENT.y)) {
|
||||
if (((pEnt->x & 0x07) == 0x04) && (y < E_RICK_ENT.y)) {
|
||||
/*sys_printf("e_them_t2 climbing00\n");*/
|
||||
ent_ents[e].flgclmb = TRUE; /* climbing */
|
||||
pEnt->flgclmb = TRUE; /* climbing */
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*sys_printf("e_them_t2 ymove nok or ...\n");*/
|
||||
/* can't go there, or ... */
|
||||
ent_ents[e].y = (ent_ents[e].y & 0xf8) | 0x03; /* align to ground */
|
||||
ent_ents[e].offsy = 0x0100;
|
||||
if (ent_ents[e].latency != 00)
|
||||
pEnt->y = (pEnt->y & 0xf8) | 0x03; /* align to ground */
|
||||
pEnt->offsy = 0x0100;
|
||||
if (pEnt->latency != 00)
|
||||
return;
|
||||
|
||||
if ((env1 & MAP_EFLG_CLIMB) &&
|
||||
((ent_ents[e].x & 0x0e) == 0x04) &&
|
||||
(ent_ents[e].y > E_RICK_ENT.y)) {
|
||||
((pEnt->x & 0x0e) == 0x04) &&
|
||||
(pEnt->y > E_RICK_ENT.y)) {
|
||||
/*sys_printf("e_them_t2 climbing01\n");*/
|
||||
ent_ents[e].flgclmb = TRUE; /* climbing */
|
||||
pEnt->flgclmb = TRUE; /* climbing */
|
||||
return;
|
||||
}
|
||||
|
||||
/* calc new sprite */
|
||||
ent_ents[e].sprite = ent_ents[e].sprbase +
|
||||
ent_sprseq[(ent_ents[e].offsx < 0 ? 4 : 0) +
|
||||
((ent_ents[e].x & 0x0e) >> 3)];
|
||||
/*sys_printf("e_them_t2 sprite %02x\n", ent_ents[e].sprite);*/
|
||||
pEnt->sprite = pEnt->sprbase +
|
||||
ent_sprseq[(pEnt->offsx < 0 ? 4 : 0) +
|
||||
((pEnt->x & 0x0e) >> 3)];
|
||||
/*sys_printf("e_them_t2 sprite %02x\n", pEnt->sprite);*/
|
||||
|
||||
|
||||
/* */
|
||||
if (ent_ents[e].offsx == 0)
|
||||
ent_ents[e].offsx = 2;
|
||||
x = ent_ents[e].x + ent_ents[e].offsx;
|
||||
if (pEnt->offsx == 0)
|
||||
pEnt->offsx = 2;
|
||||
x = pEnt->x + pEnt->offsx;
|
||||
/*sys_printf("e_them_t2 xmove x=%02x\n", x);*/
|
||||
if (x < 0xe8) {
|
||||
u_envtest(x, ent_ents[e].y, FALSE, &env0, &env1);
|
||||
u_envtest(x, pEnt->y, FALSE, &env0, &env1);
|
||||
if (!(env1 & (MAP_EFLG_VERT|MAP_EFLG_SOLID|MAP_EFLG_SPAD|MAP_EFLG_WAYUP))) {
|
||||
ent_ents[e].x = x;
|
||||
pEnt->x = x;
|
||||
if ((x & 0x1e) != 0x08)
|
||||
return;
|
||||
|
||||
|
@ -492,7 +492,7 @@ e_them_t2_action2(U8 e)
|
|||
*bl ^= *bh;
|
||||
e_them_rndnbr = bx;
|
||||
|
||||
ent_ents[e].offsx = (*bl & 0x01) ? -0x02 : 0x02;
|
||||
pEnt->offsx = (*bl & 0x01) ? -0x02 : 0x02;
|
||||
|
||||
/* back to normal */
|
||||
|
||||
|
@ -503,10 +503,10 @@ e_them_t2_action2(U8 e)
|
|||
|
||||
/* U-turn */
|
||||
/*sys_printf("e_them_t2 u-turn\n");*/
|
||||
if (ent_ents[e].offsx == 0)
|
||||
ent_ents[e].offsx = 2;
|
||||
if (pEnt->offsx == 0)
|
||||
pEnt->offsx = 2;
|
||||
else
|
||||
ent_ents[e].offsx = -ent_ents[e].offsx;
|
||||
pEnt->offsx = -pEnt->offsx;
|
||||
#undef offsx
|
||||
}
|
||||
|
||||
|
@ -516,39 +516,39 @@ e_them_t2_action2(U8 e)
|
|||
* ASM 2718
|
||||
*/
|
||||
void
|
||||
e_them_t2_action(U8 e)
|
||||
e_them_t2_action(ent_t* pEnt)
|
||||
{
|
||||
e_them_t2_action2(e);
|
||||
e_them_t2_action2(pEnt);
|
||||
|
||||
/* they kill rick */
|
||||
if (e_rick_boxtest(e))
|
||||
if (e_rick_boxtest(pEnt))
|
||||
e_rick_gozombie();
|
||||
|
||||
/* lethal entities kill them */
|
||||
if (u_themtest(e)) {
|
||||
e_them_gozombie(e);
|
||||
if (u_themtest(pEnt)) {
|
||||
e_them_gozombie(pEnt);
|
||||
return;
|
||||
}
|
||||
|
||||
/* bullet kills them */
|
||||
if (E_BULLET_ENT.n &&
|
||||
u_fboxtest(e, E_BULLET_ENT.x + (e_bullet_offsx < 0 ? 00 : 0x18),
|
||||
u_fboxtest(pEnt, E_BULLET_ENT.x + (e_bullet_offsx < 0 ? 00 : 0x18),
|
||||
E_BULLET_ENT.y)) {
|
||||
E_BULLET_ENT.n = 0;
|
||||
e_them_gozombie(e);
|
||||
e_them_gozombie(pEnt);
|
||||
return;
|
||||
}
|
||||
|
||||
/* bomb kills them */
|
||||
if (e_bomb_lethal && e_bomb_hit(e)) {
|
||||
e_them_gozombie(e);
|
||||
if (e_bomb_lethal && e_bomb_hit(pEnt)) {
|
||||
e_them_gozombie(pEnt);
|
||||
return;
|
||||
}
|
||||
|
||||
/* rick stops them */
|
||||
if (E_RICK_STTST(E_RICK_STSTOP) &&
|
||||
u_fboxtest(e, e_rick_stop_x, e_rick_stop_y))
|
||||
ent_ents[e].latency = 0x14;
|
||||
u_fboxtest(pEnt, e_rick_stop_x, e_rick_stop_y))
|
||||
pEnt->latency = 0x14;
|
||||
}
|
||||
|
||||
|
||||
|
@ -566,7 +566,7 @@ e_them_t2_action(U8 e)
|
|||
* ASM: 255A
|
||||
*/
|
||||
void
|
||||
e_them_t3_action2(U8 e)
|
||||
e_them_t3_action2(ent_t* pEnt)
|
||||
{
|
||||
#define sproffs c1
|
||||
#define step_count c2
|
||||
|
@ -576,41 +576,41 @@ e_them_t3_action2(U8 e)
|
|||
while (1) {
|
||||
|
||||
/* calc new sprite */
|
||||
i = ent_sprseq[ent_ents[e].sprbase + ent_ents[e].sproffs];
|
||||
i = ent_sprseq[pEnt->sprbase + pEnt->sproffs];
|
||||
if (i == 0xff)
|
||||
i = ent_sprseq[ent_ents[e].sprbase];
|
||||
ent_ents[e].sprite = i;
|
||||
i = ent_sprseq[pEnt->sprbase];
|
||||
pEnt->sprite = i;
|
||||
|
||||
if (ent_ents[e].sproffs != 0) { /* awake */
|
||||
if (pEnt->sproffs != 0) { /* awake */
|
||||
|
||||
/* rotate sprseq */
|
||||
if (ent_sprseq[ent_ents[e].sprbase + ent_ents[e].sproffs] != 0xff)
|
||||
ent_ents[e].sproffs++;
|
||||
if (ent_sprseq[ent_ents[e].sprbase + ent_ents[e].sproffs] == 0xff)
|
||||
ent_ents[e].sproffs = 1;
|
||||
if (ent_sprseq[pEnt->sprbase + pEnt->sproffs] != 0xff)
|
||||
pEnt->sproffs++;
|
||||
if (ent_sprseq[pEnt->sprbase + pEnt->sproffs] == 0xff)
|
||||
pEnt->sproffs = 1;
|
||||
|
||||
if (ent_ents[e].step_count < ent_mvstep[ent_ents[e].step_no].count) {
|
||||
if (pEnt->step_count < ent_mvstep[pEnt->step_no].count) {
|
||||
/*
|
||||
* still running this step: try to increment x and y while
|
||||
* checking that they remain within boudaries. if so, return.
|
||||
* else switch to next step.
|
||||
*/
|
||||
ent_ents[e].step_count++;
|
||||
x = ent_ents[e].x + ((S16)(ent_mvstep[ent_ents[e].step_no].dx));
|
||||
pEnt->step_count++;
|
||||
x = pEnt->x + ((S16)(ent_mvstep[pEnt->step_no].dx));
|
||||
|
||||
/* check'n save */
|
||||
if (x > 0 && x < 0xe8) {
|
||||
ent_ents[e].x = x;
|
||||
pEnt->x = x;
|
||||
/*FIXME*/
|
||||
/*
|
||||
y = ent_mvstep[ent_ents[e].step_no].dy;
|
||||
y = ent_mvstep[pEnt->step_no].dy;
|
||||
if (y < 0)
|
||||
y += 0xff00;
|
||||
y += ent_ents[e].y;
|
||||
y += pEnt->y;
|
||||
*/
|
||||
y = ent_ents[e].y + ((S16)(ent_mvstep[ent_ents[e].step_no].dy));
|
||||
y = pEnt->y + ((S16)(ent_mvstep[pEnt->step_no].dy));
|
||||
if (y > 0 && y < 0x0140) {
|
||||
ent_ents[e].y = y;
|
||||
pEnt->y = y;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -620,62 +620,62 @@ e_them_t3_action2(U8 e)
|
|||
* step is done, or x or y is outside boundaries. try to
|
||||
* switch to next step
|
||||
*/
|
||||
ent_ents[e].step_no++;
|
||||
if (ent_mvstep[ent_ents[e].step_no].count != 0xff) {
|
||||
pEnt->step_no++;
|
||||
if (ent_mvstep[pEnt->step_no].count != 0xff) {
|
||||
/* there is a next step: init and loop */
|
||||
ent_ents[e].step_count = 0;
|
||||
pEnt->step_count = 0;
|
||||
}
|
||||
else {
|
||||
/* there is no next step: restart or deactivate */
|
||||
if (!E_RICK_STTST(E_RICK_STZOMBIE) &&
|
||||
!(ent_ents[e].flags & ENT_FLG_ONCE)) {
|
||||
!(pEnt->flags & ENT_FLG_ONCE)) {
|
||||
/* loop this entity */
|
||||
ent_ents[e].sproffs = 0;
|
||||
ent_ents[e].n &= ~ENT_LETHAL;
|
||||
if (ent_ents[e].flags & ENT_FLG_LETHALR)
|
||||
ent_ents[e].n |= ENT_LETHAL;
|
||||
ent_ents[e].x = ent_ents[e].xsave;
|
||||
ent_ents[e].y = ent_ents[e].ysave;
|
||||
if (ent_ents[e].y < 0 || ent_ents[e].y > 0x140) {
|
||||
ent_ents[e].n = 0;
|
||||
pEnt->sproffs = 0;
|
||||
pEnt->n &= ~ENT_LETHAL;
|
||||
if (pEnt->flags & ENT_FLG_LETHALR)
|
||||
pEnt->n |= ENT_LETHAL;
|
||||
pEnt->x = pEnt->xsave;
|
||||
pEnt->y = pEnt->ysave;
|
||||
if (pEnt->y < 0 || pEnt->y > 0x140) {
|
||||
pEnt->n = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* deactivate this entity */
|
||||
ent_ents[e].n = 0;
|
||||
pEnt->n = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else { /* ent_ents[e].sprseq1 == 0 -- waiting */
|
||||
else { /* pEnt->sprseq1 == 0 -- waiting */
|
||||
|
||||
/* ugly GOTOs */
|
||||
|
||||
if (ent_ents[e].flags & ENT_FLG_TRIGRICK) { /* reacts to rick */
|
||||
if (pEnt->flags & ENT_FLG_TRIGRICK) { /* reacts to rick */
|
||||
/* wake up if triggered by rick */
|
||||
if (u_trigbox(e, E_RICK_ENT.x + 0x0C, E_RICK_ENT.y + 0x0A))
|
||||
if (u_trigbox(pEnt, E_RICK_ENT.x + 0x0C, E_RICK_ENT.y + 0x0A))
|
||||
goto wakeup;
|
||||
}
|
||||
|
||||
if (ent_ents[e].flags & ENT_FLG_TRIGSTOP) { /* reacts to rick "stop" */
|
||||
if (pEnt->flags & ENT_FLG_TRIGSTOP) { /* reacts to rick "stop" */
|
||||
/* wake up if triggered by rick "stop" */
|
||||
if (E_RICK_STTST(E_RICK_STSTOP) &&
|
||||
u_trigbox(e, e_rick_stop_x, e_rick_stop_y))
|
||||
u_trigbox(pEnt, e_rick_stop_x, e_rick_stop_y))
|
||||
goto wakeup;
|
||||
}
|
||||
|
||||
if (ent_ents[e].flags & ENT_FLG_TRIGBULLET) { /* reacts to bullets */
|
||||
if (pEnt->flags & ENT_FLG_TRIGBULLET) { /* reacts to bullets */
|
||||
/* wake up if triggered by bullet */
|
||||
if (E_BULLET_ENT.n && u_trigbox(e, e_bullet_xc, e_bullet_yc)) {
|
||||
if (E_BULLET_ENT.n && u_trigbox(pEnt, e_bullet_xc, e_bullet_yc)) {
|
||||
E_BULLET_ENT.n = 0;
|
||||
goto wakeup;
|
||||
}
|
||||
}
|
||||
|
||||
if (ent_ents[e].flags & ENT_FLG_TRIGBOMB) { /* reacts to bombs */
|
||||
if (pEnt->flags & ENT_FLG_TRIGBOMB) { /* reacts to bombs */
|
||||
/* wake up if triggered by bomb */
|
||||
if (e_bomb_lethal && u_trigbox(e, e_bomb_xc, e_bomb_yc))
|
||||
if (e_bomb_lethal && u_trigbox(pEnt, e_bomb_xc, e_bomb_yc))
|
||||
goto wakeup;
|
||||
}
|
||||
|
||||
|
@ -694,15 +694,15 @@ e_them_t3_action2(U8 e)
|
|||
* FIXME is it 8 of them, not 10?
|
||||
* FIXME testing below...
|
||||
*/
|
||||
syssnd_play(WAV_ENTITY[(ent_ents[e].trigsnd & 0x1F) - 0x14], 1);
|
||||
syssnd_play(WAV_ENTITY[(pEnt->trigsnd & 0x1F) - 0x14], 1);
|
||||
/*syssnd_play(WAV_ENTITY[0], 1);*/
|
||||
#endif
|
||||
ent_ents[e].n &= ~ENT_LETHAL;
|
||||
if (ent_ents[e].flags & ENT_FLG_LETHALI)
|
||||
ent_ents[e].n |= ENT_LETHAL;
|
||||
ent_ents[e].sproffs = 1;
|
||||
ent_ents[e].step_count = 0;
|
||||
ent_ents[e].step_no = ent_ents[e].step_no_i;
|
||||
pEnt->n &= ~ENT_LETHAL;
|
||||
if (pEnt->flags & ENT_FLG_LETHALI)
|
||||
pEnt->n |= ENT_LETHAL;
|
||||
pEnt->sproffs = 1;
|
||||
pEnt->step_count = 0;
|
||||
pEnt->step_no = pEnt->step_no_i;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -716,13 +716,13 @@ e_them_t3_action2(U8 e)
|
|||
* ASM 2546
|
||||
*/
|
||||
void
|
||||
e_them_t3_action(U8 e)
|
||||
e_them_t3_action(ent_t* pEnt)
|
||||
{
|
||||
e_them_t3_action2(e);
|
||||
e_them_t3_action2(pEnt);
|
||||
|
||||
/* if lethal, can kill rick */
|
||||
if ((ent_ents[e].n & ENT_LETHAL) &&
|
||||
!E_RICK_STTST(E_RICK_STZOMBIE) && e_rick_boxtest(e)) { /* CALL 1130 */
|
||||
if ((pEnt->n & ENT_LETHAL) &&
|
||||
!E_RICK_STTST(E_RICK_STZOMBIE) && e_rick_boxtest(pEnt)) { /* CALL 1130 */
|
||||
e_rick_gozombie();
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -293,7 +293,7 @@ frame(void)
|
|||
while (1) {
|
||||
|
||||
{
|
||||
printf("%ld game_state = %s\n", *tick, game_state_strings[game_state]);
|
||||
// printf("%ld game_state = %s\n", *tick, game_state_strings[game_state]);
|
||||
}
|
||||
|
||||
|
||||
|
@ -610,8 +610,6 @@ init(void)
|
|||
{
|
||||
U8 i;
|
||||
|
||||
printf("game.c: init(void);\n");
|
||||
|
||||
E_RICK_STRST(0xff);
|
||||
|
||||
game_lives = 6;
|
||||
|
|
38
src/util.c
38
src/util.c
|
@ -36,12 +36,12 @@
|
|||
* ret: TRUE/(x,y) is within e's space, FALSE/not.
|
||||
*/
|
||||
U8
|
||||
u_fboxtest(U8 e, S16 x, S16 y)
|
||||
u_fboxtest(ent_t* pEnt, S16 x, S16 y)
|
||||
{
|
||||
if (ent_ents[e].x >= x ||
|
||||
ent_ents[e].x + ent_ents[e].w < x ||
|
||||
ent_ents[e].y >= y ||
|
||||
ent_ents[e].y + ent_ents[e].h < y)
|
||||
if (pEnt->x >= x ||
|
||||
pEnt->x + pEnt->w < x ||
|
||||
pEnt->y >= y ||
|
||||
pEnt->y + pEnt->h < y)
|
||||
return FALSE;
|
||||
else
|
||||
return TRUE;
|
||||
|
@ -60,20 +60,20 @@ u_fboxtest(U8 e, S16 x, S16 y)
|
|||
* ret: TRUE/intersect, FALSE/not.
|
||||
*/
|
||||
U8
|
||||
u_boxtest(U8 e1, U8 e2)
|
||||
u_boxtest(ent_t* pEnt1, ent_t* pEnt2)
|
||||
{
|
||||
/* rick is special (may be crawling) */
|
||||
if (e1 == E_RICK_NO)
|
||||
return e_rick_boxtest(e2);
|
||||
if (pEnt1 == &ent_ents[E_RICK_NO])
|
||||
return e_rick_boxtest(pEnt2);
|
||||
|
||||
/*
|
||||
* entity 1: x+0x05 to x+0x011, y to y+0x14
|
||||
* entity 2: x to x+ .w, y to y+ .h
|
||||
*/
|
||||
if (ent_ents[e1].x + 0x11 < ent_ents[e2].x ||
|
||||
ent_ents[e1].x + 0x05 > ent_ents[e2].x + ent_ents[e2].w ||
|
||||
ent_ents[e1].y + 0x14 < ent_ents[e2].y ||
|
||||
ent_ents[e1].y > ent_ents[e2].y + ent_ents[e2].h - 1)
|
||||
if (pEnt1->x + 0x11 < pEnt2->x ||
|
||||
pEnt1->x + 0x05 > pEnt2->x + pEnt2->w ||
|
||||
pEnt1->y + 0x14 < pEnt2->y ||
|
||||
pEnt1->y > pEnt2->y + pEnt2->h - 1)
|
||||
return FALSE;
|
||||
else
|
||||
return TRUE;
|
||||
|
@ -175,7 +175,7 @@ u_envtest(S16 x, S16 y, U8 crawl, U8 *rc0, U8 *rc1)
|
|||
*/
|
||||
if (!(*rc1 & MAP_EFLG_LETHAL)
|
||||
&& ent_ents[0].n
|
||||
&& u_boxtest(ENT_ENTSNUM, 0)) {
|
||||
&& u_boxtest(&ent_ents[ENT_ENTSNUM], &ent_ents[0])) {
|
||||
*rc1 |= MAP_EFLG_SOLID;
|
||||
}
|
||||
|
||||
|
@ -193,17 +193,19 @@ u_envtest(S16 x, S16 y, U8 crawl, U8 *rc0, U8 *rc1)
|
|||
* return: FALSE if not in box, TRUE if in box.
|
||||
*/
|
||||
U8
|
||||
u_trigbox(U8 e, S16 x, S16 y)
|
||||
u_trigbox(ent_t* pEnt, S16 x, S16 y)
|
||||
{
|
||||
U16 xmax, ymax;
|
||||
|
||||
xmax = ent_ents[e].trig_x + (ent_entdata[ent_ents[e].n & 0x7F].trig_w << 3);
|
||||
ymax = ent_ents[e].trig_y + (ent_entdata[ent_ents[e].n & 0x7F].trig_h << 3);
|
||||
//printf("u_trigbox e=%d x=%d y=%d ", e, x, y);
|
||||
|
||||
xmax = pEnt->trig_x + (ent_entdata[pEnt->n & 0x7F].trig_w << 3);
|
||||
ymax = pEnt->trig_y + (ent_entdata[pEnt->n & 0x7F].trig_h << 3);
|
||||
|
||||
if (xmax > 0xFF) xmax = 0xFF;
|
||||
|
||||
if (x <= ent_ents[e].trig_x || x > xmax ||
|
||||
y <= ent_ents[e].trig_y || y > ymax)
|
||||
if (x <= pEnt->trig_x || x > xmax ||
|
||||
y <= pEnt->trig_y || y > ymax)
|
||||
return FALSE;
|
||||
else
|
||||
return TRUE;
|
||||
|
|
Loading…
Reference in New Issue