kicked bomb is not anymore jumping in time

origin
stpohle 19 years ago
parent 751164628d
commit 111e53867b

@ -1,11 +1,16 @@
$Id: ChangeLog,v 1.116 2006/12/15 18:41:45 stpohle Exp $
$Id: ChangeLog,v 1.117 2007/01/12 11:15:42 stpohle Exp $
Version 0.11.7.1 (still in progress)
================
- Fixed: kicked bombs can travel in time. (map.bfield was set too early)
rewrote full bomb kicked system.
- Fixed: compile warning: packets.c(635): error #592: variable "s_mod" is
used before its value is set (reported by: David Binderman)
- Fixed: Special settings will be saved into the config file.
- Changed: all data will have thier own Makefile. So "make install" and
"make dist" won't copy the CVS dirs.

@ -1,4 +1,4 @@
/* $Id: bomb.h,v 1.6 2006/02/06 21:18:01 stpohle Exp $
/* $Id: bomb.h,v 1.7 2007/01/12 11:15:44 stpohle Exp $
* bomb include file
*/
@ -24,7 +24,8 @@ enum _bombmode {
struct {
_pointf pos; // lower byte = _X Higher Byte = FX
_pointf pos; // position of the bomb.
_pointf oldpos; // old position of the bomb.
struct __bomb_id { // save the bomb id
signed char p; // playernumber of this bomb
signed char b; // bombnumber of this bomb
@ -37,9 +38,9 @@ struct {
unsigned char state; // state of the bomb BS_*
unsigned char mode; // mode of the bomb BM_*
int ex_nr; // explosion number
_point source; // start of a kicked bomb
_point dest; // destination to move the bomb to
float speed; // bomb moving speed or kicked bomb 0.0=start 1.0=end
_pointf source; // start of a kicked bomb
_pointf dest; // destination to move the bomb to
float fdata; // float data: speed (moving bombs), pos (kicked bombs)
} typedef _bomb;
@ -49,6 +50,7 @@ extern void bomb_loop ();
extern void bomb_explode (_bomb * bomb, int net);
extern inline void bomb_action (_bomb * bomb);
extern void bomb_move (_bomb * bomb);
extern void bomb_kicked (_bomb * bomb);
extern void get_bomb_on (float x, float y, _point bombs[]);
extern void explosion_do (_bomb * bomb);
extern void explosion_restore (_bomb * bomb);

@ -1,4 +1,4 @@
/* $Id: packets.h,v 1.34 2006/08/15 15:00:31 stpohle Exp $
/* $Id: packets.h,v 1.35 2007/01/12 11:15:44 stpohle Exp $
* network packets.. */
#ifndef _PACKETS_H_
@ -220,7 +220,7 @@ struct pkg_bombdata {
Sint32 to;
Uint16 destx;
Uint16 desty;
Sint16 speed;
Sint16 fdata;
} __attribute__((packed));
struct pkg_quit {

@ -1,4 +1,4 @@
/* $Id: bomb.c,v 1.65 2006/12/15 18:51:01 stpohle Exp $ */
/* $Id: bomb.c,v 1.66 2007/01/12 11:15:44 stpohle Exp $ */
/* everything what have to do with the bombs */
#include "bomberclone.h"
@ -9,19 +9,11 @@
void
draw_bomb (_bomb * bomb)
{
SDL_Rect src,
dest;
int x = floorf (bomb->pos.x),
y = floorf (bomb->pos.y);
float w,
x1,
x2,
y1,
y2;
if (x < 0 || y < 0 || x >= map.size.x || y >= map.size.y) {
d_printf ("FATAL: Draw Bomb out of range [%f,%f]\n", x, y);
SDL_Rect src, dest;
int x = floorf (bomb->oldpos.x), y = floorf (bomb->oldpos.y);
if (bomb->pos.x < 0 || bomb->pos.y < 0 || bomb->pos.x >= map.size.x || bomb->pos.y >= map.size.y) {
d_printf ("FATAL: Draw Bomb out of range [%f,%f]\n", bomb->pos.x, bomb->pos.y);
return;
}
@ -36,59 +28,27 @@ draw_bomb (_bomb * bomb)
dest.w = src.w = gfx.bomb.image->w;
dest.h = src.h = gfx.block.y;
if (bomb->mode == BM_kicked) {
/*
* draw the kicked bomb
*/
w = sqrt (bomb->speed);
w *= absol (sin (w));
x1 = bomb->dest.x - bomb->pos.x;
y1 = bomb->dest.y - bomb->pos.y;
if (x1 > 0) {
x2 = bomb->pos.x + x1 * bomb->speed / 88 + y1 * w / 20;
y2 = bomb->pos.y + y1 * bomb->speed / 88 - x1 * w / 20;
}
else {
x2 = bomb->pos.x + x1 * bomb->speed / 88 - y1 * w / 20;
y2 = bomb->pos.y + y1 * bomb->speed / 88 + x1 * w / 20;
}
x = floorf (x2);
y = floorf (y2);
bomb->speed -= timediff * 100;
if (bomb->speed < 0) {
dest.x = gfx.offset.x + bomb->pos.x * gfx.block.x;
dest.y = gfx.offset.y + bomb->pos.y * gfx.block.y;
bomb->mode = BM_normal;
}
else {
w = sqrt (bomb->speed);
w *= absol (sin (w));
if (x1 > 0) {
x2 = bomb->pos.x + x1 * bomb->speed / 88 + y1 * w / 20;
y2 = bomb->pos.y + y1 * bomb->speed / 88 - x1 * w / 20;
}
else {
x2 = bomb->pos.x + x1 * bomb->speed / 88 - y1 * w / 20;
y2 = bomb->pos.y + y1 * bomb->speed / 88 + x1 * w / 20;
}
dest.x = gfx.offset.x + x2 * gfx.block.x;
dest.y = gfx.offset.y + y2 * gfx.block.y;
}
}
else {
dest.x = gfx.offset.x + bomb->pos.x * gfx.block.x;
dest.y = gfx.offset.y + bomb->pos.y * gfx.block.y;
}
dest.x = gfx.offset.x + bomb->pos.x * gfx.block.x;
dest.y = gfx.offset.y + bomb->pos.y * gfx.block.y;
src.x = 0;
src.y = src.h * (int) bomb->frame;
stonelist_add (x, y);
if (bomb->mode != BM_normal) {
stonelist_add (x + 1, y);
stonelist_add (x, y + 1);
stonelist_add (x + 1, y + 1);
}
/* delete the old position of the bomb */
if (bomb->oldpos.x >= 0.0f && bomb->oldpos.y >= 0.0f) {
stonelist_add (x, y);
if (bomb->mode != BM_normal) {
stonelist_add (x + 1, y);
stonelist_add (x, y + 1);
stonelist_add (x + 1, y + 1);
}
}
else
stonelist_add (bomb->pos.x, bomb->pos.y);
/* save the current position */
bomb->oldpos = bomb->pos;
gfx_blit (gfx.bomb.image, &src, gfx.screen, &dest, (y * 256) + 2);
};
@ -172,8 +132,8 @@ bomb_move (_bomb * bomb)
fpos.y += 1.0f;
}
if (step > (timefactor * bomb->speed) || step == 0.0f)
step = (timefactor * bomb->speed);
if (step > (timefactor * bomb->fdata) || step == 0.0f)
step = (timefactor * bomb->fdata);
/* move the bomb to the new position */
if (bomb->dest.x < 0)
@ -235,7 +195,7 @@ bomb_move (_bomb * bomb)
}
}
dist += step;
} while (dist < (timefactor * bomb->speed)
} while (dist < (timefactor * bomb->fdata)
&& (bomb->mode == BM_liquid || bomb->mode == BM_moving) && keepdir);
map.bfield[(int) bomb->pos.x][(int) bomb->pos.y] = 1; /* set new bfield */
@ -278,10 +238,11 @@ bomb_loop ()
}
draw_bomb (bomb);
}
/*
* if the bomb is moving or something...
*/
if (bomb->mode != BM_normal)
bomb_action (bomb);
break;
case BS_exploding:
@ -292,22 +253,21 @@ bomb_loop ()
explosion_restore (bomb);
bomb->to = 0.0f;
bomb->state = BS_off;
bomb->oldpos.x = bomb->oldpos.y = -1.0f;
}
bomb->to -= timediff;
break;
}
}
}
}
}
}
return;
};
/* check if on the givin place is a bomb
bombs[].x = player, bombs[].y = bombnumber */
void
get_bomb_on (float x, float y, _point bombs[])
{
void get_bomb_on (float x, float y, _point bombs[]) {
int p,
b,
i;
@ -350,6 +310,7 @@ void explosion_restore (_bomb *bomb) {
if (map.field[_x][_y].ex[d].count > 0)
map.field[_x][_y].ex[d].count--;
map.field[_x][_y].ex[d].frame = 0.0f; // reset the framenumber
/* refresh the screen here.. */
if (d==3)
stonelist_add (_x, _y);
@ -391,7 +352,7 @@ void explosion_restore (_bomb *bomb) {
/* delete field from the bfield map */
if (bomb->mode == BM_moving || bomb->mode == BM_pushed || bomb->mode == BM_liquid)
map.bfield[(int) bomb->pos.x + bomb->dest.x][(int) bomb->pos.y + bomb->dest.y] = 0;
map.bfield[(int) bomb->pos.x + (int)bomb->dest.x][(int) bomb->pos.y + (int)bomb->dest.y] = 0;
map.bfield[(int) bomb->pos.x][(int) bomb->pos.y] = 0;
};
@ -426,7 +387,6 @@ explosion_draw (_bomb * bomb)
}
/*
* calculate the explosion itself,
* check the direction of the explosion and and and
@ -457,7 +417,6 @@ void explosion_do (_bomb *bomb) {
step = 1.0f;
}
bomb->firer[d] += step;
// printf ("d:%d, Cur_Range:%f New_Range:%f\n", d, bomb->firer[d], new_range);
dx = rintf(bomb->pos.x + dir_change[d].x * bomb->firer[d]);
dy = rintf(bomb->pos.y + dir_change[d].y * bomb->firer[d]);
@ -507,9 +466,10 @@ int explosion_check_field (int x, int y, _bomb *bomb)
/* check if any bomb have to explode.. */
for (i = 0; bo[i].x != -1; i++) {
tmpbomb = &players[bo[i].x].bombs[bo[i].y];
if (tmpbomb != bomb && tmpbomb->state != BS_exploding) {
tmpbomb->ex_nr = bomb->ex_nr; // set the ex_nr to identify explosions
bomb_explode (tmpbomb, 1);
if (tmpbomb != bomb && tmpbomb->state != BS_exploding
&& tmpbomb->mode != BM_kicked) {
tmpbomb->ex_nr = bomb->ex_nr; // set the ex_nr to identify explosions
bomb_explode (tmpbomb, 1);
}
}
@ -536,10 +496,38 @@ int explosion_check_field (int x, int y, _bomb *bomb)
};
/*
* the bomb was kicked.. so move the bomb in the right way..
*/
void bomb_kicked (_bomb * bomb) {
float dist, dX, dY, pX, pY;
pX = dX = bomb->dest.x - bomb->source.x;
pY = dY = bomb->dest.y - bomb->source.y;
if (pX < 0.0f) pX = -dX;
if (pY < 0.0f) pY = -dY;
if (pX == 0.0f) dist = pY;
else if (pY == 0.0f) dist = pX;
else {
dist = sqrtf (powf (pX,2) + powf (pY,2));
}
bomb->fdata += timediff; // * (SPECIAL_KICK_MAXDIST / dist);
if (bomb->fdata >= 1.0f) {
bomb->pos.x = bomb->dest.x;
bomb->pos.y = bomb->dest.y;
bomb->mode = BM_normal;
bomb->fdata = 0.0f;
map.bfield[(int)bomb->dest.x][(int)bomb->dest.y] = 1;
}
else {
bomb->pos.x = bomb->source.x + dX * bomb->fdata;
bomb->pos.y = (bomb->source.y + dY * bomb->fdata) - (4.0-(4.0 * powf ((-0.5+bomb->fdata)*2.0f, 2.0f)));
}
};
inline void
bomb_action (_bomb * bomb)
inline void bomb_action (_bomb * bomb)
{
switch (bomb->mode) {
case (BM_moving):
@ -548,6 +536,7 @@ bomb_action (_bomb * bomb)
bomb_move (bomb);
break;
case (BM_kicked):
bomb_kicked (bomb);
break;
default:
bomb->mode = BM_normal;

@ -1,4 +1,4 @@
/* $Id: configuration.c,v 1.80 2006/08/15 00:57:46 stpohle Exp $
/* $Id: configuration.c,v 1.81 2007/01/12 11:15:44 stpohle Exp $
* configuration */
#include <SDL.h>
@ -368,6 +368,18 @@ config_read ()
if (!strcmp (keyword, "start_speed")) {
sscanf (value, "%f", &bman.start_speed);
}
if (!strcmp (keyword, "special_trigger")) {
sscanf (value, "%d", &map.sp_trigger);
}
if (!strcmp (keyword, "special_row")) {
sscanf (value, "%d", &map.sp_row);
}
if (!strcmp (keyword, "special_push")) {
sscanf (value, "%d", &map.sp_push);
}
if (!strcmp (keyword, "special_kick")) {
sscanf (value, "%d", &map.sp_kick);
}
if (!strcmp (keyword, "bomb_ticking")) {
sscanf (value, "%f", &bman.bomb_tickingtime);
}
@ -484,6 +496,11 @@ config_write ()
fprintf (config, "start_bombs=%d\n", bman.start_bombs);
fprintf (config, "start_range=%d\n", bman.start_range);
fprintf (config, "start_speed=%f\n", bman.start_speed);
fprintf (config, "special_trigger=%d\n", map.sp_trigger);
fprintf (config, "special_row=%d\n", map.sp_row);
fprintf (config, "special_push=%d\n", map.sp_push);
fprintf (config, "special_kick=%d\n", map.sp_kick);
fprintf (config, "bomb_ticking=%f\n", bman.bomb_tickingtime);
fprintf (config, "dropitemsondeath=%d\n",bman.dropitemsondeath);

@ -1,4 +1,4 @@
/* $Id: game.c,v 1.116 2006/08/19 23:41:47 stpohle Exp $
/* $Id: game.c,v 1.117 2007/01/12 11:15:44 stpohle Exp $
game.c - procedures for the game. */
#include <string.h>
@ -539,7 +539,7 @@ game_start ()
for (i = 0; i < MAX_BOMBS; i++) {
players[p].bombs[i].state = BS_off;
players[p].bombs[i].ex_nr = -1;
players[p].bombs[i].speed = 0;
players[p].bombs[i].fdata = 0;
players[p].bombs[i].dest.x = 0;
players[p].bombs[i].dest.y = 0;
players[p].bombs[i].mode = BM_normal;

@ -1,4 +1,4 @@
/* $Id: main.c,v 1.34 2006/08/12 12:44:06 stpohle Exp $ */
/* $Id: main.c,v 1.35 2007/01/12 11:15:44 stpohle Exp $ */
#include "basic.h"
#include "bomberclone.h"
@ -21,7 +21,7 @@ Uint32 timestamp; // timestamp
float timefactor = 0.0f; /* factor for the time time of the last loop
1.0f would be 20ms */
float timediff = 0.0f; /* last loop timedifference in seconds */
int firstrun = 1; // flag for the first menuloop
int firstrun = 1; // flag for the first menuloop
int
main (int argc, char **argv)

@ -1058,7 +1058,7 @@ do_bombdata (struct pkg_bombdata *b_dat, _net_addr * addr)
bomb->ex_nr = NTOH32 (b_dat->ex_nr);
bomb->state = b_dat->state & 0x0F;
bomb->mode = b_dat->state >> 4;
bomb->speed = I16TOF (NTOH16 (b_dat->speed));
bomb->fdata = I16TOF (NTOH16 (b_dat->fdata));
bomb->dest.x = NTOH16 (b_dat->destx);
bomb->dest.y = NTOH16 (b_dat->desty);
@ -1085,7 +1085,7 @@ send_bombdata (_net_addr * addr, int p, int b, _bomb * bomb)
b_dat.b_nr = b;
b_dat.p_nr = p;
b_dat.h.flags = PKGF_ackreq;
b_dat.speed = HTON16 (FTOI16 (bomb->speed));
b_dat.fdata = HTON16 (FTOI16 (bomb->fdata));
b_dat.destx = HTON16 (bomb->dest.x);
b_dat.desty = HTON16 (bomb->dest.y);

@ -1,4 +1,4 @@
/* $Id: special.c,v 1.37 2004/12/26 23:18:40 stpohle Exp $ */
/* $Id: special.c,v 1.38 2007/01/12 11:15:44 stpohle Exp $ */
/* special.c - procedues to control the specials */
#include "bomberclone.h"
@ -122,7 +122,7 @@ special_liquidmoved (int p_nr)
if (b->state != BS_exploding) {
b->dest.x = dx;
b->dest.y = dy;
b->speed = p->speed;
b->fdata = p->speed;
if (p->special.type == SP_liquid)
b->mode = BM_liquid;
else
@ -181,7 +181,7 @@ special_push (int p_nr)
if (b->state != BS_exploding) {
b->dest.x = dx;
b->dest.y = dy;
b->speed = p->speed;
b->fdata = p->speed;
b->mode = BM_pushed;
map.bfield[x][y] = 0;
map.bfield[x1][y1] = 1;
@ -193,10 +193,11 @@ special_push (int p_nr)
}
}
void
special_kick (int p_nr)
{
/*
* kick the bomb over the field
*/
#define KICK_MAXTRY 20
void special_kick (int p_nr) {
_bomb *b = NULL;
_player *p = &players[p_nr];
_point bombs[MAX_PLAYERS * MAX_BOMBS];
@ -205,9 +206,9 @@ special_kick (int p_nr)
y = (int) p->pos.y,
dx = 0,
dy = 0,
x1,
y1,
i = 20,
x1,y1, // new position
i,
trycnt = KICK_MAXTRY, // maximum number of trys to kick the bomb.
r;
if ((CUTINT (p->pos.x) != 0.0f) || (CUTINT (p->pos.y) != 0.0f))
@ -228,7 +229,7 @@ special_kick (int p_nr)
if the bomb kickt to the border of maze, nothing happens.)
*/
do {
i--;
trycnt--;
r = s_random (SPECIAL_KICK_MAXDIST) + 1;
if (dx != 0) {
x1 = x + dx * r;
@ -240,33 +241,32 @@ special_kick (int p_nr)
}
// check if within maze
if ((x1 >= 0) && (x1 < map.size.x) && (y1 >= 0) && (y1 < map.size.y)) {
// check that field is emty
// check if that field is emty
if (!map.bfield[x1][y1]
&& (map.field[x1][y1].type == FT_nothing || map.field[x1][y1].type == FT_tunnel)) {
// move bomb to new destination
get_bomb_on (x, y, bombs);
for (i = 0; bombs[i].x != -1; i++) {
for (i = 0; bombs[i].x != -1; i++) {
b = &players[bombs[i].x].bombs[bombs[i].y];
if (b->state != BS_exploding) {
b->dest.x = x;
b->dest.y = y;
b->speed = 88; //ca (3*pi)*(3*pi)
b->mode = BM_kicked;
b->pos.x = x1;
b->pos.y = y1;
b->dest.x = x1;
b->dest.y = y1;
b->fdata = 0.0f;
b->mode = BM_kicked;
b->source.x = x;
b->source.y = y;
map.bfield[x][y] = 0;
map.bfield[x1][y1] = 1;
stonelist_add (x, y);
if (GT_MP) {
net_game_send_bomb (bombs[i].x, bombs[i].y);
}
}
if (GT_MP) net_game_send_bomb (bombs[i].x, bombs[i].y);
}
}
i = 0;
trycnt = 0;
}
}
} while (i > 0);
} while (trycnt > 0);
}
#undef KICK_MAXTRY
void

Loading…
Cancel
Save