From dbbd1a7a2920953a8c296f9418e936566248dd33 Mon Sep 17 00:00:00 2001 From: stpohle Date: Sun, 8 Feb 2004 00:40:20 +0000 Subject: [PATCH] new player position placement coded by dcdillon --- ChangeLog | 7 +- TODO | 7 +- src/game.c | 11 ++- src/map.c | 273 +-------------------------------------------------- src/player.c | 17 ++-- 5 files changed, 26 insertions(+), 289 deletions(-) diff --git a/ChangeLog b/ChangeLog index e23d118..8669044 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,4 @@ -$Id: ChangeLog,v 1.70 2004/02/05 22:58:57 stpohle Exp $ +$Id: ChangeLog,v 1.71 2004/02/08 00:43:30 stpohle Exp $ - Fixed: forgot to put the Message F4 to start the game into the playerselection screen. I put this only into the @@ -36,6 +36,11 @@ $Id: ChangeLog,v 1.70 2004/02/05 22:58:57 stpohle Exp $ - Fixed/Added: display messages enabled again (after disabling for changing the menu style with version 0.11.0) +- Changed: new player position placement, that works much + better as the old version (coded by dcdillon) + +- Changed: if no human players are left the game will end + Version 0.11.1 ============== diff --git a/TODO b/TODO index 080c2cb..b8789e8 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -$Id: TODO,v 1.39 2004/02/05 21:32:11 stpohle Exp $ +$Id: TODO,v 1.40 2004/02/08 00:43:30 stpohle Exp $ - support for more player on one keyboard @@ -8,13 +8,10 @@ $Id: TODO,v 1.39 2004/02/05 21:32:11 stpohle Exp $ a new one you will lose the old one and someone else can catch this one. -- player will lose all his power if he die and other people - can collect his powerups. - - multiplayer broadcast in the local network ip: 10.*.*.* and 192.168.*.* -- more specials (Kicking Bomb) +- more specials - network joining menu Add: information about the playernames and the point list. diff --git a/src/game.c b/src/game.c index 9cf9491..e0dc3a3 100644 --- a/src/game.c +++ b/src/game.c @@ -1,4 +1,4 @@ -/* $Id: game.c,v 1.79 2004/02/07 13:35:28 stpohle Exp $ +/* $Id: game.c,v 1.80 2004/02/08 00:40:20 stpohle Exp $ game.c - procedures for the game. */ #include @@ -139,7 +139,7 @@ game_loop () { SDL_Event event; Uint8 *keys; - int done = 0; + int done = 0, i; unsigned char key_bomb = 0; // last state of the bomb key gfx_blitupdaterectclear (); @@ -211,7 +211,7 @@ game_loop () } if (keys[SDLK_F9] && event.type == SDL_KEYDOWN) { - /* Switch Fullscreen */ + /* Switch Debugmode */ debug = !debug; bman.updatestatusbar = 1; // force an update } @@ -249,6 +249,11 @@ game_loop () /* check if there is only one player left and the game is in multiplayer mode and if there the last dieing animation is done */ + for (i = 0; (i < MAX_PLAYERS && (!PS_IS_used (players[i].state) + || PS_IS_aiplayer (players[i].state) + || (PS_IS_used (players[i].state) && !PS_IS_alife (players[i].state)))); i++); + if (i == MAX_PLAYERS) /* only AI Players alife, make sure the game is going to an end */ + bman.players_nr = 1; if (((bman.players_nr < 2 && (GT_MP || (GT_SP && bman.ai_players > 0))) || (GT_SP && bman.ai_players == 0 && bman.players_nr < 1)) diff --git a/src/map.c b/src/map.c index 266f8cb..e21ca79 100644 --- a/src/map.c +++ b/src/map.c @@ -1,4 +1,4 @@ -/* $Id: map.c,v 1.21 2004/02/07 23:51:17 stpohle Exp $ */ +/* $Id: map.c,v 1.22 2004/02/08 00:40:20 stpohle Exp $ */ /* map handling, like generate and load maps. */ #include "bomberclone.h" @@ -128,9 +128,6 @@ map_new (char *filename) map_find_and_add_start_points(pl_cnt - map_num_defined_start_points(), MAP_POSITION_TOLERENCE); - /* Set the Playerinformation */ - map_set_playerposition (fmap != NULL); - /* put the fire powerups in the field */ map_fillitems (FT_fire, map.fire); /* put the bomb powerups in the field */ @@ -197,274 +194,6 @@ map_genrandom () } -/* will set the playerposition but in a way that we won't start on a block */ -/* i am just too lazy to write this all again and again */ -#define PLX(__i) players[__i].pos.x -#define PLY(__i) players[__i].pos.y - -/* check if there is another player in the near if so delete player pos for another try */ -void map_playerpos_check (int pl) { - int i, d = MAX_FIELDSIZE_X, dx, dy; - for (i = 0; (i < MAX_PLAYERS && d > 1); i++) - if (i != pl) { - dx = PLX(i) - PLX(pl); - if (dx < 0) - dx = -dx; - dy = PLY(i) - PLY(pl); - if (dy < 0) - dy = -dy; - if (dx < dy) // save the biggest distance in there - dx = dy; - if (dx < d) - d = dx; - - } - - if (d < 2) { - PLX(pl) = -1; - PLY(pl) = -1; - } -} - -void -map_set_player_way1 (int pl) -{ - _point p, t[4]; - int i, j, ok = 0; - - p.x = s_random (map.size.x - 2) + 1; - p.y = s_random (map.size.y - 2) + 1; - - /* check if there is no block */ - if (map.field[p.x][p.y].type != FT_nothing) - return; - - /* check if we can run away somewhere */ - for (j = 0; j < 4; j++) { - t[j].x = p.x; - t[j].y = p.y; - } - - for (i = 0; (i < 10 && ok == 0); i++) { - t[left].x -= 1; - t[right].x += 1; - t[up].y = -1; - t[down].y += 1; - for (j = 0; j < 4; j++) - if (t[j].x > 0 && t[j].x < map.size.x - && t[j].y > 0 && t[j].y < map.size.y) { - if (map.field[t[j].x][t[j].y].type == FT_nothing) { - if ((j == left || j == right) - && map.field[t[j].x][t[j].y - 1].type == FT_nothing - && map.field[t[j].x][t[j].y + 1].type == FT_nothing) - ok = 1; - if ((j == up || j == down) - && map.field[t[j].x - 1][t[j].y].type == FT_nothing - && map.field[t[j].x + 1][t[j].y].type == FT_nothing) - ok = 1; - } - else { /* this field is not free anymore */ - t[j].x = -1; - t[j].y = -1; - } - } else { - t[j].x = -1; - t[j].y = -1; - } - } - if (ok) { - PLX(pl) = p.x; - PLY(pl) = p.y; - } -} - - -void -map_set_player_way2 (int pl, int hardway) -{ - _point p, t[4]; - int i, j, ok = 0; - - p.x = s_random (map.size.x - 2) + 1; - p.y = s_random (map.size.y - 2) + 1; - - /* check if there is no block */ - if ((map.field[p.x][p.y].type != FT_nothing && (!hardway || map.field[p.x][p.y].type != FT_stone)) - || map.field[p.x][p.y].special == FT_tunnel) - return; - - /* delete the stone under the player, only in hardway mode */ - if (map.field[p.x][p.y].type != FT_stone && hardway) { - map.field[p.x][p.y].type = FT_nothing; - map.field[p.x][p.y].special = FT_nothing; - } - - - /* check if we can run away somewhere */ - for (j = 0; j < 4; j++) { - t[j].x = p.x; - t[j].y = p.y; - } - - if (hardway) // if we using the hard way for playerposition - hardway = s_random (4)+1; // then select a side which we use - - for (i = 0; (i < 10 && ok == 0); i++) { - t[left].x -= 1; - t[right].x += 1; - t[up].y = -1; - t[down].y += 1; - for (j = 0; j < 4; j++) - if (t[j].x > 0 && t[j].x < map.size.x - && t[j].y > 0 && t[j].y < map.size.y) { - - if (hardway && (hardway - 1) == j && map.field[t[j].x][t[j].y].type == FT_stone) { - map.field[t[j].x][t[j].y].type = FT_nothing; - map.field[t[j].x][t[j].y].special = FT_nothing; - } - - if (map.field[t[j].x][t[j].y].type == FT_nothing) { - if (ok == 0 && (j == left || j == right) - && (map.field[t[j].x][t[j].y - 1].type == FT_stone || map.field[t[j].x][t[j].y - 1].type == FT_nothing)) { - map.field[t[j].x][t[j].y - 1].type = FT_nothing; - map.field[t[j].x][t[j].y - 1].special = FT_nothing; - ok = 1; - } - if (ok == 0 && (j == left || j == right) - && (map.field[t[j].x][t[j].y + 1].type == FT_stone || map.field[t[j].x][t[j].y + 1].type == FT_nothing)) { - map.field[t[j].x][t[j].y + 1].type = FT_nothing; - map.field[t[j].x][t[j].y + 1].special = FT_nothing; - ok = 1; - } - if (ok == 0 && (j == up || j == down) - && (map.field[t[j].x + 1][t[j].y].type == FT_stone || map.field[t[j].x + 1][t[j].y].type == FT_nothing)) { - map.field[t[j].x + 1][t[j].y].type = FT_nothing; - map.field[t[j].x + 1][t[j].y].special = FT_nothing; - ok = 1; - } - if (ok == 0 && (j == up || j == down) - && (map.field[t[j].x - 1][t[j].y].type == FT_stone || map.field[t[j].x - 1][t[j].y].type == FT_nothing)) { - map.field[t[j].x - 1][t[j].y].type = FT_nothing; - map.field[t[j].x - 1][t[j].y].special = FT_nothing; - ok = 1; - } - } - else { /* this field is not free anymore */ - t[j].x = -1; - t[j].y = -1; - } - } else { - t[j].x = -1; - t[j].y = -1; - } - } - if (ok) { - PLX(pl) = p.x; - PLY(pl) = p.y; - } -} - - -void -map_set_playerposition (int usermap) -{ - int pl, - ready, - maxtry; - int all_players_set = 1; - - d_printf ("map_set_playerposition\n"); - - /* This is the new code that will set every player in a starting point - * It should never fail, but if it does, it will fall through to the old method - */ - - for (pl = 0; pl < MAX_PLAYERS; pl++) { - if (PS_IS_used(players[pl].state)) { - map_place_player(pl); - } - } - - /* test to see if all players are placed */ - - for (pl = 0; pl < MAX_PLAYERS; pl++) { - - if ((PS_IS_used(players[pl].state)) - && ((players[pl].pos.x < 0) || (players[pl].pos.y < 0))) { - - all_players_set = 0; - break; - } - } - - /* if a used player is not set at a valid start point, fall into the old mode */ - - if (!all_players_set) { - - d_fatal("Using old player set method. This should not happen.\n"); - - /* try to set every player on a good place */ - maxtry = 300; - ready = 0; - while (!ready && maxtry-- > 0) { - ready = 1; - for (pl = 0; pl < MAX_PLAYERS; pl++) - if (PS_IS_used (players[pl].state) && (PLX (pl) < 0 || PLY (pl) < 0)) { - /* set player */ - ready = 0; - map_set_player_way1 (pl); - map_playerpos_check (pl); - } - } - - /* every player which is still not set .. set now and delete some normal stones */ - maxtry = 200; - ready = 0; - while (!ready && maxtry-- > 0) { - ready = 1; - for (pl = 0; pl < MAX_PLAYERS; pl++) - if (PS_IS_used (players[pl].state) && (PLX (pl) < 0 || PLY (pl) < 0)) { - /* set player */ - ready = 0; - map_set_player_way2 (pl, 0); - if (maxtry > 50) - map_playerpos_check (pl); - } - } - /* try another way for setting the players */ - maxtry = 200; - ready = 0; - while (!ready && maxtry-- > 0) { - ready = 1; - for (pl = 0; pl < MAX_PLAYERS; pl++) - if (PS_IS_used (players[pl].state) && (PLX (pl) < 0 || PLY (pl) < 0)) { - /* set player */ - ready = 0; - map_set_player_way2 (pl, 1); - if (maxtry > 50) - map_playerpos_check (pl); - } - } - - - - /* every player who is still not set ... let them die before they - * can play put a warning on the screen */ - maxtry = 0; // mark our warning - for (pl = 0; pl < MAX_PLAYERS; pl++) - if (PS_IS_used (players[pl].state) && (PLX (pl) < 0 || PLY (pl) < 0)) { - PLX (pl) = 0.0; - PLY (pl) = 0.0; - maxtry = 1; - } - if (maxtry) - d_fatal ("Not All Player could been set\n"); - } -}; - -#undef PLX -#undef PLY - /* load a random map */ void map_random () diff --git a/src/player.c b/src/player.c index a722c2d..3df2531 100644 --- a/src/player.c +++ b/src/player.c @@ -1,4 +1,4 @@ -/* $Id: player.c,v 1.77 2004/02/01 23:51:11 stpohle Exp $ +/* $Id: player.c,v 1.78 2004/02/08 00:40:20 stpohle Exp $ * player.c - everything what have to do with the player */ #include @@ -873,13 +873,14 @@ void player_checkdeath (int pnr) { && PS_IS_dead (player->state) && player->frame >= gfx.dead.frames) { /* check new position */ d_printf ("Respawn for player %s\n", player->name); - trypos = 0; - do { - player->pos.x = -1.0f; - player->pos.y = -1.0f; - map_set_player_way1 (pnr); - trypos++; - } while (trypos < 100 && (player->pos.x == -1 || player->pos.y == -1)); + + player->pos.x = -1; + player->pos.y = -1; + + while (player->pos.x == -1 && player->pos.y == -1) { + + map_respawn_player(pnr); + } if (player->pos.x != -1 && player->pos.y != -1) { player->frame = 0;