respawn finally working weell

origin
stpohle 22 years ago
parent 5842d80f24
commit 4c84a21b23

@ -1,4 +1,4 @@
/* $Id: single.c,v 1.55 2004/01/27 21:13:45 stpohle Exp $ */ /* $Id: single.c,v 1.56 2004/01/28 18:19:12 stpohle Exp $ */
/* single player */ /* single player */
#include "basic.h" #include "basic.h"
@ -19,7 +19,7 @@ single_game_new ()
bman.players_nr_s++; bman.players_nr_s++;
bman.players_nr++; bman.players_nr++;
players[p].state |= PSF_used + PSF_alife + PSF_playing; players[p].state |= PSF_used + PSF_alife + PSF_playing;
} }
else else
players[p].state = 0; players[p].state = 0;
} }
@ -38,7 +38,7 @@ ai_checkfield (int x, int y)
{ {
return ((map.field[x][y].type == FT_nothing || map.field[x][y].type == FT_fire return ((map.field[x][y].type == FT_nothing || map.field[x][y].type == FT_fire
|| map.field[x][y].type == FT_shoe || map.field[x][y].type == FT_bomb || map.field[x][y].type == FT_shoe || map.field[x][y].type == FT_bomb
|| map.field[x][y].type == FT_mixed || map.field[x][y].type == FT_tunnel) || map.field[x][y].type == FT_mixed || map.field[x][y].type == FT_tunnel)
&& map.bfield[x][y] == 0); && map.bfield[x][y] == 0);
} }
@ -51,7 +51,7 @@ ai_easyrunaway (_point p)
{ {
int i, int i,
done = 0, done = 0,
dir = 0; dir = 0;
_point pos[4], _point pos[4],
m[4]; m[4];
@ -124,12 +124,12 @@ ai_runawayfrom (_point p, int nearbomb, signed char norecursive)
{ {
int i, int i,
done = 0, done = 0,
nbomb, nbomb,
tdir, tdir,
_i, _i,
bdirpoints = 10, bdirpoints = 10,
j, j,
c; c;
_airunaway res; _airunaway res;
_point pos[4], _point pos[4],
m[4], m[4],
@ -236,8 +236,8 @@ int
ai_bombpoints (_point pos, int range) ai_bombpoints (_point pos, int range)
{ {
int points = 0, int points = 0,
d, d,
r; r;
_point p, _point p,
m; m;
@ -265,7 +265,10 @@ ai_bombpoints (_point pos, int range)
p = pos; p = pos;
for (r = 0; (r < range && (map.field[p.x][p.y].type == FT_nothing || map.field[p.x][p.y].type == FT_tunnel)); r++) { for (r = 0;
(r < range
&& (map.field[p.x][p.y].type == FT_nothing
|| map.field[p.x][p.y].type == FT_tunnel)); r++) {
p.x += m.x; p.x += m.x;
p.y += m.y; p.y += m.y;
} }
@ -294,9 +297,9 @@ ai_findbestbombdir (_point pos, int dir, int range)
int points[5] = { 0, 0, 0, 0, 0 }; int points[5] = { 0, 0, 0, 0, 0 };
int d, int d,
done = 0, done = 0,
j, j,
maxpoints = 0, maxpoints = 0,
bestd; bestd;
_point m[4], _point m[4],
p[4]; p[4];
@ -375,8 +378,7 @@ ai_findnearbombs (_point pos)
{ {
int d, int d,
res = 0, // result if there is a bomb res = 0, // result if there is a bomb
done = 0;
done = 0;
_point m[4]; // direction addition _point m[4]; // direction addition
_point dist[4]; // to check every direction (on three ways) _point dist[4]; // to check every direction (on three ways)
@ -541,19 +543,22 @@ ai_checknewpos (_point pos, int d)
/* delete single players from the game */ /* delete single players from the game */
void single_delete_ai (int num_players) { void
int p, count; single_delete_ai (int num_players)
{
for (p = 0, count = 0; p < MAX_PLAYERS && count < num_players; p++) { int p,
if (PS_IS_aiplayer (players[p].state)) { count;
/* ai player found... delete */
player_set_gfx (&players[p], -1); for (p = 0, count = 0; p < MAX_PLAYERS && count < num_players; p++) {
players[p].state = 0; if (PS_IS_aiplayer (players[p].state)) {
players[p].net.addr.host[0] = 0; /* ai player found... delete */
players[p].net.addr.port[0] = 0; player_set_gfx (&players[p], -1);
count++; players[p].state = 0;
} players[p].net.addr.host[0] = 0;
} players[p].net.addr.port[0] = 0;
count++;
}
}
}; };
@ -572,11 +577,11 @@ single_create_ai (int num_players)
for (pl = NULL, p = 0; (pl == NULL && p < MAX_PLAYERS); p++) for (pl = NULL, p = 0; (pl == NULL && p < MAX_PLAYERS); p++)
if (!(PS_IS_used (players[p].state))) { if (!(PS_IS_used (players[p].state))) {
pl = &players[p]; pl = &players[p];
sprintf (pl->name, "AIPlayer %d", p+1); sprintf (pl->name, "AIPlayer %d", p + 1);
pl->state |= PSF_used + PSF_alife + PSF_playing + PSF_ai; pl->state |= PSF_used + PSF_alife + PSF_playing + PSF_ai;
pl->net.flags = NETF_firewall; pl->net.flags = NETF_firewall;
sprintf (pl->net.addr.host, "localhost"); sprintf (pl->net.addr.host, "localhost");
sprintf (pl->net.addr.port, "11000"); sprintf (pl->net.addr.port, "11000");
do { do {
gfx_sel = s_random (MAX_PLAYERS); gfx_sel = s_random (MAX_PLAYERS);
MW_IS_GFX_SELECT (gfx_sel, i); MW_IS_GFX_SELECT (gfx_sel, i);
@ -602,8 +607,8 @@ single_playergame ()
players[p].points = 0; players[p].points = 0;
players[p].wins = 0; players[p].wins = 0;
players[p].state = 0; players[p].state = 0;
players[p].gfx_nr = -1; players[p].gfx_nr = -1;
players[p].gfx = NULL; players[p].gfx = NULL;
} }
for (bman.p_nr = -1, p = 0; (bman.p_nr == -1 && p < MAX_PLAYERS); p++) for (bman.p_nr = -1, p = 0; (bman.p_nr == -1 && p < MAX_PLAYERS); p++)
@ -640,100 +645,110 @@ single_loop ()
_player *pl; _player *pl;
_point plpos; _point plpos;
int nearbomb = 0, int nearbomb = 0,
bestbdir, bestbdir,
i; i;
_airunaway rawdir; _airunaway rawdir;
if (GT_MP_PTPS) // we are not the master so no need for this. if (GT_MP_PTPS) // we are not the master so no need for this.
return; return;
for (p = 0; p < MAX_PLAYERS; p++) for (p = 0; p < MAX_PLAYERS; p++)
if (p != bman.p_nr && PS_IS_alife (players[p].state) && PS_IS_aiplayer(players[p].state)) { if (p != bman.p_nr && PS_IS_aiplayer (players[p].state)) {
pl = &players[p]; if (PS_IS_alife (players[p].state)) {
pl = &players[p];
i = ai_checkpos (pl, &plpos); i = ai_checkpos (pl, &plpos);
if (!i) if (!i)
/* we're still moving */ /* we're still moving */
pl->m = 1; pl->m = 1;
else { else {
nearbomb = ai_findnearbombs (plpos); nearbomb = ai_findnearbombs (plpos);
if (nearbomb == 0) { // no bombs found if (nearbomb == 0) { // no bombs found
bestbdir = ai_findbestbombdir (plpos, pl->d, pl->range); bestbdir = ai_findbestbombdir (plpos, pl->d, pl->range);
if (bestbdir & DIRM_under) { if (bestbdir & DIRM_under) {
if (ai_easyrunaway (plpos) != 0) if (ai_easyrunaway (plpos) != 0)
player_drop_bomb (p); player_drop_bomb (p);
} }
else if (bestbdir == 0) { else if (bestbdir == 0) {
pl->d = s_random (4); pl->d = s_random (4);
pl->m = 1; pl->m = 1;
}
else {
pl->d = ai_choosedir (bestbdir, 0, pl->d);
pl->m = 1;
}
if (!ai_checknewpos (plpos, pl->d))
pl->m = 0;
} }
else { else {
pl->d = ai_choosedir (bestbdir, 0, pl->d); // bombs in the near found
pl->m = 1; rawdir = ai_runawayfrom (plpos, nearbomb, 0);
} if (rawdir.dir != 0 && rawdir.bestdir == -1) {
if (!ai_checknewpos (plpos, pl->d)) pl->d = ai_choosedir (rawdir.dir, nearbomb, pl->d); // we have to make a choice.. do it
pl->m = 0; pl->m = 1;
} }
else { else if (rawdir.bestdir != -1) {
// bombs in the near found pl->d = rawdir.bestdir;
rawdir = ai_runawayfrom (plpos, nearbomb, 0); pl->m = 1;
if (rawdir.dir != 0 && rawdir.bestdir == -1) { }
pl->d = ai_choosedir (rawdir.dir, nearbomb, pl->d); // we have to make a choice.. do it
pl->m = 1;
} }
else if (rawdir.bestdir != -1) {
pl->d = rawdir.bestdir; if (pl->m == 0 && map.field[(int) pl->pos.x][(int) pl->pos.y].type == FT_tunnel)
pl->m = 1; pl->m = 1;
}
} }
player_ilness_loop (p);
if (pl->m == 0 && map.field[(int)pl->pos.x][(int)pl->pos.y].type == FT_tunnel) move_player (p);
pl->m = 1;
} }
player_ilness_loop (p); else
player_checkdeath (p); player_checkdeath (p);
move_player (p);
} }
}; };
/* singleplayer menü with some options you can make */ /* singleplayer menü with some options you can make */
void void
single_menu () single_menu ()
{ {
int menuselect = 0, i, p, done = 0; int menuselect = 0,
_charlist nrplayerlist[MAX_PLAYERS+1]; i,
_charlist *selnrplayer = &nrplayerlist[bman.ai_players]; p,
done = 0;
/* fill in the nrplayerlist */ _charlist nrplayerlist[MAX_PLAYERS + 1];
if (debug) p = 0; else p = 1; _charlist *selnrplayer = &nrplayerlist[bman.ai_players];
for (i = 0; p < MAX_PLAYERS+1; i++) {
sprintf (nrplayerlist[i].text, "%d", p); /* fill in the nrplayerlist */
if (p < MAX_PLAYERS-1) if (debug)
nrplayerlist[i].next = &nrplayerlist[i+1]; p = 0;
else else
nrplayerlist[i].next = NULL; p = 1;
p++; for (i = 0; p < MAX_PLAYERS + 1; i++) {
} sprintf (nrplayerlist[i].text, "%d", p);
if (p < MAX_PLAYERS - 1)
nrplayerlist[i].next = &nrplayerlist[i + 1];
else
nrplayerlist[i].next = NULL;
p++;
}
while (!done && bman.state != GS_quit) { while (!done && bman.state != GS_quit) {
menu_new ("Single Player", 300, 250); menu_new ("Single Player", 300, 250);
menu_create_label ("Number Of AI Players", -1, 55, 0); menu_create_label ("Number Of AI Players", -1, 55, 0);
menu_create_list ("Players", -1, 80, 70, 70, nrplayerlist, &selnrplayer, 1); menu_create_list ("Players", -1, 80, 70, 70, nrplayerlist, &selnrplayer, 1);
menu_create_button ("Map Setting", -1, 180, 150, 2); menu_create_button ("Map Setting", -1, 180, 150, 2);
menu_create_button ("OK", -1, 220, 150, 0); menu_create_button ("OK", -1, 220, 150, 0);
menuselect = menu_loop (); menuselect = menu_loop ();
menu_delete (); menu_delete ();
/* read the current number of AI Players */ /* read the current number of AI Players */
bman.ai_players = (selnrplayer - &nrplayerlist[0]); bman.ai_players = (selnrplayer - &nrplayerlist[0]);
if (!debug) if (!debug)
bman.ai_players++; bman.ai_players++;
if (bman.ai_players > MAX_PLAYERS) { if (bman.ai_players > MAX_PLAYERS) {
d_fatal ("single_menu: bman.ai_players selection out of range (%d)\n", bman.ai_players); d_fatal ("single_menu: bman.ai_players selection out of range (%d)\n", bman.ai_players);
bman.ai_players = 5; bman.ai_players = 5;
} }
switch (menuselect) { switch (menuselect) {
case (0): // Start Game case (0): // Start Game
@ -746,8 +761,8 @@ single_menu ()
done = 1; done = 1;
break; break;
} }
draw_logo (); draw_logo ();
SDL_Flip (gfx.screen); SDL_Flip (gfx.screen);
} }
}; };
@ -758,22 +773,22 @@ int
single_select_player () single_select_player ()
{ {
int selgfx = 0, int selgfx = 0,
done = 0, done = 0,
x, x,
y, y,
keypressed = 0, keypressed = 0,
frame = 0, frame = 0,
d = 0, d = 0,
dto = 2, dto = 2,
newplayer = -1, newplayer = -1,
pos = 0, pos = 0,
i; i;
SDL_Rect dest, SDL_Rect dest,
src; src;
char text[255]; char text[255];
SDL_Event event; SDL_Event event;
Uint8 *keys; Uint8 *keys;
Uint32 timeloop1; Uint32 timeloop1;
// menu_displaytext ("Loading..", "Please Wait", 32, 128, 32); // menu_displaytext ("Loading..", "Please Wait", 32, 128, 32);
@ -816,7 +831,7 @@ single_select_player ()
SDL_Rect dest1, SDL_Rect dest1,
src1; src1;
pos += 8; pos += 8;
if (d == left) { if (d == left) {
/* image 1 */ /* image 1 */
@ -832,7 +847,9 @@ single_select_player ()
src1.w = dest1.w = gfx.players[newplayer].ani.w; src1.w = dest1.w = gfx.players[newplayer].ani.w;
src1.x = gfx.players[newplayer].ani.w * d; src1.x = gfx.players[newplayer].ani.w * d;
src1.y = gfx.players[newplayer].ani.h * frame; src1.y = gfx.players[newplayer].ani.h * frame;
dest1.x = ((gfx.res.x - gfx.players[newplayer].ani.w) / 2) + ((gfx.res.x / 2)+ 128) - pos; dest1.x =
((gfx.res.x - gfx.players[newplayer].ani.w) / 2) + ((gfx.res.x / 2) + 128) -
pos;
dest1.y = y + font[0].size.y + 64; dest1.y = y + font[0].size.y + 64;
} }
else { else {
@ -849,26 +866,28 @@ single_select_player ()
src1.w = dest1.w = gfx.players[newplayer].ani.w; src1.w = dest1.w = gfx.players[newplayer].ani.w;
src1.x = gfx.players[newplayer].ani.w * d; src1.x = gfx.players[newplayer].ani.w * d;
src1.y = gfx.players[newplayer].ani.h * frame; src1.y = gfx.players[newplayer].ani.h * frame;
dest1.x = ((gfx.res.x - gfx.players[newplayer].ani.w) / 2) - ((gfx.res.x / 2)+ 128) + pos; dest1.x =
((gfx.res.x - gfx.players[newplayer].ani.w) / 2) - ((gfx.res.x / 2) + 128) +
pos;
dest1.y = y + font[0].size.y + 64; dest1.y = y + font[0].size.y + 64;
} }
redraw_logo (0, y + font[0].size.y + 64, gfx.res.x, 128); redraw_logo (0, y + font[0].size.y + 64, gfx.res.x, 128);
if (dest.x + dest.w > 0) if (dest.x + dest.w > 0)
gfx_blit (gfx.players[selgfx].ani.image, &src, gfx.screen, &dest, 0); gfx_blit (gfx.players[selgfx].ani.image, &src, gfx.screen, &dest, 0);
if (dest1.x + dest1.w > 0) if (dest1.x + dest1.w > 0)
gfx_blit (gfx.players[newplayer].ani.image, &src1, gfx.screen, &dest1, 0); gfx_blit (gfx.players[newplayer].ani.image, &src1, gfx.screen, &dest1, 0);
if (pos > (gfx.res.x / 2)+ 128) { if (pos > (gfx.res.x / 2) + 128) {
selgfx = newplayer; selgfx = newplayer;
newplayer = -1; newplayer = -1;
pos = 0; pos = 0;
frame = 0; frame = 0;
d = down; d = down;
dto = 5; dto = 5;
} }
frame++; frame++;
} }
else { else {
src.h = dest.h = gfx.players[selgfx].ani.h; src.h = dest.h = gfx.players[selgfx].ani.h;
@ -918,7 +937,8 @@ single_select_player ()
d = right; d = right;
} }
if ((keys[SDLK_RETURN] ||keys[SDLK_RCTRL] || keys[SDLK_LCTRL]) && (!keypressed) && (event.type = SDL_KEYDOWN) && newplayer == -1) { if ((keys[SDLK_RETURN] || keys[SDLK_RCTRL] || keys[SDLK_LCTRL]) && (!keypressed)
&& (event.type = SDL_KEYDOWN) && newplayer == -1) {
done = 1; done = 1;
keypressed = 1; keypressed = 1;
// d_printf("return pressed - done=1\n"); // d_printf("return pressed - done=1\n");
@ -931,10 +951,10 @@ single_select_player ()
// calculate time sync. // calculate time sync.
timeloop1 = SDL_GetTicks (); timeloop1 = SDL_GetTicks ();
if (newplayer != -1) if (newplayer != -1)
i = 17; i = 17;
else else
i = 25; i = 25;
while (timeloop1 - timestamp >= 0 && timeloop1 - timestamp < i) { while (timeloop1 - timestamp >= 0 && timeloop1 - timestamp < i) {
s_delay (i - (timeloop1 - timestamp) - 1); s_delay (i - (timeloop1 - timestamp) - 1);

Loading…
Cancel
Save