From 7b383ec1df539d45ccac8d6e192acafc721876fe Mon Sep 17 00:00:00 2001 From: stpohle Date: Mon, 4 Oct 2004 21:36:46 +0000 Subject: [PATCH] Teammenus again changed, now all players will be in team 1. this will be changed again. So the new player will join the weakest team or the team with the less people --- TechDoc.txt | 154 ---------------------- include/player.h | 8 +- include/single.h | 3 +- src/netmenu.c | 1 + src/packets.c | 2 + src/player.c | 20 ++- src/playermenu.c | 332 ++++++++--------------------------------------- src/single.c | 51 +++++++- 8 files changed, 129 insertions(+), 442 deletions(-) delete mode 100644 TechDoc.txt diff --git a/TechDoc.txt b/TechDoc.txt deleted file mode 100644 index d548a48..0000000 --- a/TechDoc.txt +++ /dev/null @@ -1,154 +0,0 @@ - -This file will hold some Details about the Game. -A list of files and what every file is used for: - -field.c: - loading maps - generating maps - drawing the field - -bomb.c: - drawing bombs - drawing explosions - calculating and checking the explosions - -player.c: - drawing the player - moving the player - *calculating the new position of the players - checking for powerups - -chat.c: - drawing chatbox - -game.c: - the whole gameloop (multi and singleplayer) - -single.c: - creating a single game - *generating ai players - *moving the ai players - -font.c: - drawing text on the screen - -network.c: - network loop - - keeping ther network alife, like sending ping, checking for - timeouts. - - doing the dynamic change of the send_pkg option - - this function will take care about all incomming network packets. - network init - network shutdown - update the clients for a new game - send to all players - - playerdata - - playermoves - - bombdata - - fielddata - - playerlist - - chat messages - - playerillness - - specials - delete a network player from a game - fills in the sockaddr from all the players - clean everything for a new network game - -netmenu.c: - network menu - join a game - host a game - network options - -packets.c: - everything what have to do with the network packet, - all send_* and all do_* function are defined in here. - send_packetname, do_packetname. - forwarding packets between the players who are behind - a firewall. - - do_pkg - ------ - will check the packet for wrong data network type - illegal packets, will delete the packet if we have got it already - do automatic pingreply or send the pkgack packet back. - - send_pkg - -------- - if the PKGF_ACKREQ flag is set it will cache the packet and check it if - it's reched the other side and if we have got the ACKPKG back. - - holds an incoming index table of the last 256 (PKG_IN_INDEX_NUM) packets - so if one reches double in a certain time it will be ignored. - -pkgcache.c: - gives a pointer to a outgoing packet - add a outgoing packet - - function is only called from send_pkg - - only packet with PKGF_ackreq flag will cached - deletes a packet - len of an outgoing packet - resend cache loop - - function only called from network_loop - will resend after a timeout time a packet. - to make sure the packet got reched on the other side. - -configuration.c: - configuratio/option menu - read config - write config - change resolution menu - read program arguments - game startup init - - only called from the main function to set some variables at - programstart - -gfx.c: - draw shadowed boxes - shading parts on the screen - draw background logo - draw shaded background logos - updates a list of parts from the screen - - gfx_UpdateRects (updates all rects) - - gfx_AddUpdateRects(add a rect of the screen) - gets the color of an pixel on a surface - scaling of images - load/free playergraphics - load/free game data (fonts and background) - load/free tilesets - init/shutdown game graphics - - this function will calculate the best scaling size on the screen - -gamesrv.c: - communiaction with the game master server - adds a game to the master server - deletes a game from the masterserver - sends chat information to the master server - server selection menu - -udp.c: - send messages - get messages - dns names - start/stop udp server - -mapmenu.c: - map option menu - map initializing - - selects random maps - - loads random tilesets - -keypinput.c: - loop for keyboard text fields - -sysfunc.c: - s_delay - - waiting for some milliseconds - s_random - - returns a random number - s_gethomedir - - returns the name of the homedir used for the config file - s_getdir - - list of files and directorys - s_filterdir - - filters the list diff --git a/include/player.h b/include/player.h index 02538bc..53a0fc6 100644 --- a/include/player.h +++ b/include/player.h @@ -1,4 +1,4 @@ -/* $Id: player.h,v 1.7 2004/10/03 20:22:45 stpohle Exp $ +/* $Id: player.h,v 1.8 2004/10/04 21:36:47 stpohle Exp $ * playerinclude file */ @@ -114,6 +114,7 @@ struct { struct __team { _player *players[MAX_PLAYERS]; char name[LEN_PLAYERNAME]; + int col; // color of the Teamname int wins; int points; } typedef _team; @@ -151,7 +152,7 @@ extern void player2_join (); extern void player2_add (int pl_nr); extern void team_update (); - +extern void team_choose (_player *pl); // for the playerinput handling extern void playerinput_loop (int pl_nr); @@ -164,6 +165,7 @@ extern void playermenu (); extern int playermenu_selgfx (int pl_nr); extern void playermenu_getflags (char *text, _player *player); +extern int teammenu_select (_player *pl); extern void teammenu (); - + #endif diff --git a/include/single.h b/include/single.h index 3de01fd..e865777 100644 --- a/include/single.h +++ b/include/single.h @@ -1,4 +1,4 @@ -/* $Id: single.h,v 1.4 2004/09/23 13:21:44 stpohle Exp $ +/* $Id: single.h,v 1.5 2004/10/04 21:36:47 stpohle Exp $ * single player */ // single.c @@ -17,3 +17,4 @@ extern int ai_bombpoints (_point pos, int range); extern _airunaway ai_runawayfrom (_point p, int nearbomb, int range, signed char norecursive); extern int ai_checkfield (int x, int y); extern int ai_easyrunaway (_point p, int range); +extern void ai_team_choosegfx (); diff --git a/src/netmenu.c b/src/netmenu.c index 05435ab..2a2489f 100644 --- a/src/netmenu.c +++ b/src/netmenu.c @@ -157,6 +157,7 @@ void host_multiplayer_game () { /* prepare the server */ strncpy (players[0].name, bman.playername, LEN_PLAYERNAME); bman.p_nr = bman.p_servnr = 0; + team_choose (&players[0]); players[0].state = PSF_used; if (bman.notifygamemaster) send_ogc_update (); /* send the information that we started an server */ diff --git a/src/packets.c b/src/packets.c index be1e6fb..f92757e 100644 --- a/src/packets.c +++ b/src/packets.c @@ -146,6 +146,8 @@ do_joingame (struct pkg_joingame *p_jg, _net_addr * addr) pl->points = 0; pl->wins = 0; pl->team_nr = -1; + + team_choose (pl); } strncpy (pl->name, p_jg->name, LEN_PLAYERNAME); player_set_gfx (pl, -1); diff --git a/src/player.c b/src/player.c index b6943ed..f27e084 100644 --- a/src/player.c +++ b/src/player.c @@ -1,4 +1,4 @@ -/* $Id: player.c,v 1.88 2004/09/26 22:06:58 stpohle Exp $ +/* $Id: player.c,v 1.89 2004/10/04 21:36:47 stpohle Exp $ * player.c - everything what have to do with the player */ #include @@ -1071,13 +1071,16 @@ void player2_add (int pl_nr) { /* - * set the teams[] witht he current player data + * set the teams[] with the current player data */ void team_update () { int cnt[MAX_TEAMS] = { 0,0,0,0 }; int pl; for (pl = 0; pl < MAX_PLAYERS; pl++) { + if (PS_IS_used (players[pl].state) && players[pl].team_nr < 0 && players[pl].team_nr >= MAX_TEAMS) + players[pl].team_nr = 0; + if (PS_IS_used (players[pl].state) && players[pl].team_nr >= 0) { teams[players[pl].team_nr].players[cnt[players[pl].team_nr]] = &players[pl]; cnt[players[pl].team_nr]++; @@ -1088,3 +1091,16 @@ void team_update () { // d_teamdetail ("Teaminformation"); } + + +/* + * if the team number is -1 then join this player into the losing team + */ +void team_choose (_player *pl) { + + if (pl->team_nr >= 0 && pl->team_nr < MAX_TEAMS) + return; + + printf ("team_choose need to fix\n"); + pl->team_nr = 1; +}; diff --git a/src/playermenu.c b/src/playermenu.c index e17f520..50b0ced 100644 --- a/src/playermenu.c +++ b/src/playermenu.c @@ -1,5 +1,4 @@ -/* $Id: playermenu.c,v 1.9 2004/10/03 20:22:46 stpohle Exp $ - * +/* $Id: playermenu.c,v 1.10 2004/10/04 21:36:47 stpohle Exp $ */ #include "bomberclone.h" @@ -17,28 +16,10 @@ */ // static int playermenu_gfxaviable (int gfx); static void playermenu_selgfx_drawplayer (int selgfx, _menu *menu); -static void teammenu_ai_choosegfx (); #define PLAYERMENU_GFXSEL_Y 130 -/* - * check if the gfx is still aviable - * -static int playermenu_gfxaviable (int gfx) { - int i; - - for (i = 0; i < MAX_PLAYERS && gfx != players[i].gfx_nr; i++); - if (i == MAX_PLAYERS) - return 1; - - return 0; -}; - * - * **** DO WE NEED THIS? - */ - - /* * show the basis menu */ @@ -337,6 +318,13 @@ void playermenu () { teammenu (); done = 0; } + + if (done == 1 && menu->focus->id == list_PlayerList->id) { /* team selection */ + done = 0; + players[sel_pl_nr].team_nr = teammenu_select (&players[sel_pl_nr]); + bman.updatestatusbar = 1; + team_update (); + } if (done == 1 && menu->focus->id == 4) { /* kick player */ if (sel_pl_nr >= 0 && sel_pl_nr < MAX_PLAYERS && sel_pl_nr != bman.p_servnr) @@ -371,293 +359,77 @@ void playermenu_getflags (char *text, _player *player) { /* - * teammenu: Teamplay menuselection - * Show and edit all teams and the players. + * teammenu: Returns a Teamnumber for this player. */ -struct __teammenu { - struct { - _charlist names[MAX_PLAYERS]; - _charlist *select; - _menuitem *item; - _menuitem *label; - } teamp, freep; - - _menuitem *teamlist; - _charlist teamnames[MAX_TEAMS]; - _charlist *teamsel; -}; - -static void teammenu_update (_menu *menu, struct __teammenu *tm); -static int inline teammenu_get_selteam (_menu *menu, struct __teammenu *tm); -static void teammenu_set_selteam (_menu *menu, struct __teammenu *tm, int teamnr); -static void teammenu_player2team (_menu *menu, struct __teammenu *tm); -static void teammenu_team2player (_menu *menu, struct __teammenu *tm); - - -void teammenu () { +int teammenu_select (_player *pl) { _menu *menu; - struct __teammenu tm; - - int done, eventstate, menu_id = 0, last_id = 0, last_selteam = -1; - SDL_Event event; - - menu = menu_new ("Team Details", 400, 350); + int i; + _charlist teamlist[MAX_TEAMS]; + _charlist *teamlistsel=NULL; - menu_create_text (menu, "help1", 10, 70, (250/font[0].size.x), 5, COLOR_gray, "Move the players from one team into the other by selecting them with ENTER."); - menu_create_button (menu, "Close", -1, 325, 150, 0); + if (pl == NULL) return -1; - /* reset all teamlist data and create element */ - tm.teamsel = NULL; - tm.teamnames[0].text[0] = 0; - tm.teamnames[0].next = NULL; + /* create the list of teams */ + for (i = 0; i < MAX_TEAMS; i++) + strncpy (teamlist[i].text, teams[i].name, LEN_PLAYERNAME); + charlist_fillarraypointer (teamlist, MAX_TEAMS); - tm.teamlist = menu_create_list (menu, "Teamlist", 250, 70, 150, 80, tm.teamnames, &tm.teamsel, ++menu_id); + teamlistsel = &teamlist[pl->team_nr]; - /* reset all player data and create element*/ - tm.teamp.names[0].text[0] = 0; - tm.teamp.names[0].next = NULL; - tm.teamp.select = &tm.teamp.names[0];; - tm.freep.names[0].text[0] = 0; - tm.freep.names[0].next = NULL; - tm.freep.select = &tm.freep.names[0];; - - tm.freep.label = menu_create_label (menu, "Free Players", 40, 160, 0, COLOR_yellow); - tm.freep.item = menu_create_list (menu, "freeplayer", 30, 180, 150, 120, tm.freep.names, &tm.freep.select, ++menu_id); - tm.teamp.label = menu_create_label (menu, teams[0].name, 250, 160, 0, COLOR_yellow); - tm.teamp.item = menu_create_list (menu, "teamplayer", 240, 180, 150, 120, tm.teamp.names, &tm.teamp.select, ++menu_id); - - - /* prepare everything for the menu_loop */ + menu = menu_new ("Teamselection", 250, 250); + menu_create_text (menu, "text", -1, 50, 200/font[0].size.x, 5, COLOR_yellow, + "Please select the team where you want to put in Player '%s'.", pl->name); + menu_create_list (menu, "teams", -1, 120, 200, 100, teamlist, &teamlistsel, 1); menu_focus_id (menu, 1); - menu->looprunning = 1; - menu_draw (menu); - - teammenu_set_selteam (menu, &tm, 0); - teammenu_update (menu, &tm); + menu_loop (menu); - /* the menu loop */ - do { - gfx_blitdraw (); - eventstate = SDL_PollEvent (&event); - if (bman.sock != -1) - network_loop (); - - menu_draw (menu); - done = menu_event_loop (menu, &event, eventstate); - /* - * check if one of the buttons was pressed - */ - if (last_id != menu->focus->id || last_selteam != teammenu_get_selteam(menu, &tm)) { - teammenu_update (menu, &tm); - } - - if (done == 1 && menu->focus->id == tm.freep.item->id) { // freeplayer selected - teammenu_player2team (menu, &tm); - teammenu_update (menu, &tm); - done = 0; - } - - if (done == 1 && menu->focus->id == tm.teamp.item->id) { // teamplayer selected - teammenu_team2player (menu, &tm); - teammenu_update (menu, &tm); - done = 0; - } - - if (done == 1 && menu->focus->id == tm.teamlist->id) { - menu_focus_id (menu, tm.freep.item->id); - teammenu_update (menu, &tm); - done = 0; - } - - s_calctimesync (); - last_id = menu->focus->id; - } while ((done == 0 || menu->focus->id != 0) && done != -1); menu_delete (menu); - teammenu_ai_choosegfx (); -} - + i = (teamlistsel - teamlist); -/* - * add the current selected playxer to the free players - */ -static void teammenu_team2player (_menu *menu, struct __teammenu *tm) { - int sel_team = teammenu_get_selteam (menu,tm); - int sel_teampl = tm->teamp.select - tm->teamp.names; - - if (sel_team < 0 || sel_team >= MAX_TEAMS || sel_teampl < 0 || sel_teampl >= MAX_PLAYERS) - return; - if (teams[sel_team].players[sel_teampl] == NULL) - return; + d_printf ("teammenu_select: Player %s is in Team %s (%d)\n", pl->name, teams[i].name); - teams[sel_team].players[sel_teampl]->team_nr = -1; - team_update (); + return i; }; /* - * add the current selected player to the current team + * with the team menu you can select your own teamnames */ -static void teammenu_player2team (_menu *menu, struct __teammenu *tm) { - int sel_player = tm->freep.select - tm->freep.names; - int sel_team = teammenu_get_selteam (menu,tm); - int pl; - - // d_printf ("teammenu_player2team: sel_player=%d, sel_team=%d\n", sel_player, sel_team); - - if (sel_team < 0 || sel_team >= MAX_TEAMS || sel_player < 0 || sel_player >= MAX_PLAYERS) - return; - - /* get the player */ - pl = 0; - while (pl < MAX_PLAYERS && (sel_player > 0 || players[pl].team_nr != -1)) { - if (players[pl].team_nr == -1) sel_player--; - pl++; - } - // d_printf ("teammenu_player2team: sel_player=%d, sel_team=%d, pl=\n", sel_player, sel_team, pl); - - if (pl < MAX_PLAYERS && sel_player == 0 && players[pl].team_nr == -1) - players[pl].team_nr = sel_team; +void teammenu () { + _menu *menu; - team_update (); -} - -/* - * update all elements on the screen - * clean the player lists for the team and free players - */ -static void teammenu_update (_menu *menu, struct __teammenu *tm) { - int pl, cnt_team, cnt_free; + int i, col, y; + struct _s_team { + _charlist collist[COLOR_max]; + _charlist *collistsel; + } tdata[MAX_TEAMS]; - // d_printf ("teammenu_update\n"); + menu = menu_new ("Teamsettings", 360, 100 + (MAX_TEAMS * 30)); - /* - * teamnames - */ - tm->teamnames[0].text[0] = 0; - tm->teamnames[0].next = NULL; - for (pl = 0; pl < MAX_TEAMS; pl++) { - if (pl > 0) - tm->teamnames[pl-1].next = &tm->teamnames[pl]; - tm->teamnames[pl].next = NULL; - strncpy (tm->teamnames[pl].text, teams[pl].name, LEN_CHARENTRY); + y = 60; + + for (i = 0; i < MAX_TEAMS; i++) { + for (col = 0; col < COLOR_max; col++) + sprintf (tdata[i].collist[col].text, "%d", col); + charlist_fillarraypointer (tdata[i].collist, COLOR_max); + tdata[i].collistsel = tdata[i].collist + i; + menu_create_entry (menu, "Name :", 25, y, 200, teams[i].name, LEN_PLAYERNAME, MENU_entrytext, 2*i + 1); + menu_create_label (menu, "Color:", 250, y, 0, COLOR_yellow); + menu_create_list (menu, "Liste", 320, y, 30, 20, tdata[i].collist, &tdata[i].collistsel, 2*i + 2); + + y += 30; } - strncpy (tm->teamp.label->label, tm->teamsel->text, MENU_TITLELEN); + menu_create_button (menu, "Close", -1, y + 10, 150, 2*i+1); - /* - * playernames - */ - tm->freep.names[0].next = NULL; - tm->freep.names[0].text[0] = 0; - tm->teamp.names[0].next = NULL; - tm->teamp.names[0].text[0] = 0; - for (pl = 0, cnt_team = 0, cnt_free = 0; pl < MAX_PLAYERS; pl++) { - if (PS_IS_used (players[pl].state) && (players[pl].team_nr == -1 || players[pl].team_nr == teammenu_get_selteam (menu, tm))) { - _charlist *cl; - int *cnt; - - /* select the right list with the right counter */ - if (players[pl].team_nr == -1) { - cl = tm->freep.names; - cnt = &cnt_free; - } - else { - cl = tm->teamp.names; - cnt = &cnt_team; - } - - /* set the data */ - if (*cnt > 0) - cl[(*cnt)-1].next = &cl[*cnt]; - strncpy (cl[*cnt].text, players[pl].name, LEN_CHARENTRY); - cl[*cnt].next = NULL; - (*cnt)++; - } - } + menu_loop (menu); + menu_delete (menu); - /* send update */ - tm->freep.item->changed = 1; - tm->freep.label->changed = 1; - menu_draw_menuitem (tm->freep.item); - menu_draw_menuitem (tm->freep.label); - tm->teamp.item->changed = 1; - tm->teamp.label->changed = 1; - menu_draw_menuitem (tm->teamp.item); - menu_draw_menuitem (tm->teamp.label); - tm->teamlist->changed = 1; - menu_draw_menuitem (tm->teamlist); + return; } -/* - * get the current teamnumber - */ -static inline int teammenu_get_selteam (_menu *menu, struct __teammenu *tm) { - return (tm->teamsel - tm->teamnames); -}; - - -/* - * set the current teamnumber - */ -static void teammenu_set_selteam (_menu *menu, struct __teammenu *tm, int teamnr) { - if (teamnr < 0 ) teamnr = 0; - else if (teamnr >= MAX_TEAMS) teamnr = MAX_TEAMS-1; - - tm->teamsel = &tm->teamnames[teamnr]; - tm->teamlist->changed = 1; - menu_draw_menuitem (tm->teamlist); -}; - - - -/* - * the ai player will choose diffrent gfx for every - * team another gfx, but not one which is selected by - * human player. - */ -static void teammenu_ai_choosegfx () { - struct _team_tmpdata_ { -// int ai_player; -// int hu_player; - int ai_gfx; - } teamdat[MAX_TEAMS]; - - int tm_nr; - int pl_nr; - int i, used; - _player *pl; - - /* find a ai player gfx for every team */ - for (i = 0, tm_nr = 0; (i < gfx.player_gfx_count && tm_nr < MAX_TEAMS); i++) { - used = 0; - for (pl_nr = 0; pl_nr < MAX_PLAYERS; pl_nr++) { - if ((!PS_IS_aiplayer(players[pl_nr].state)) - && (PS_IS_used (players[pl_nr].state)) - && i == players[pl_nr].gfx_nr) - used = 1; - } - if (!used && tm_nr < MAX_TEAMS) { - teamdat[tm_nr].ai_gfx = i; - tm_nr++; - } - } - - /* - * give all ai players in the teams the right gfx - */ - for (tm_nr = 0; tm_nr < MAX_TEAMS; tm_nr++) for (pl_nr = 0; pl_nr < MAX_PLAYERS; pl_nr++) { - pl = teams[tm_nr].players[pl_nr]; - if (pl) { - if (PS_IS_used(pl->state) && PS_IS_aiplayer(pl->state)) - player_set_gfx (pl, teamdat[tm_nr].ai_gfx); - } - } -}; - - - /* * create a menu where we can change the playernames */ diff --git a/src/single.c b/src/single.c index d35843f..3add2ce 100644 --- a/src/single.c +++ b/src/single.c @@ -1,4 +1,4 @@ -/* $Id: single.c,v 1.75 2004/10/03 20:22:46 stpohle Exp $ */ +/* $Id: single.c,v 1.76 2004/10/04 21:36:47 stpohle Exp $ */ /* single player */ #include "basic.h" @@ -37,6 +37,51 @@ single_game_new () }; + +/* + * the ai player will choose diffrent gfx for every + * team another gfx, but not one which is selected by + * human player. + */ +void ai_team_choosegfx () { + struct _team_tmpdata_ { + int ai_gfx; + } teamdat[MAX_TEAMS]; + + int tm_nr; + int pl_nr; + int i, used; + _player *pl; + + /* find a ai player gfx for every team */ + for (i = 0, tm_nr = 0; (i < gfx.player_gfx_count && tm_nr < MAX_TEAMS); i++) { + used = 0; + for (pl_nr = 0; pl_nr < MAX_PLAYERS; pl_nr++) { + if ((!PS_IS_aiplayer(players[pl_nr].state)) + && (PS_IS_used (players[pl_nr].state)) + && i == players[pl_nr].gfx_nr) + used = 1; + } + if (!used && tm_nr < MAX_TEAMS) { + teamdat[tm_nr].ai_gfx = i; + tm_nr++; + } + } + + /* + * give all ai players in the teams the right gfx + */ + for (tm_nr = 0; tm_nr < MAX_TEAMS; tm_nr++) for (pl_nr = 0; pl_nr < MAX_PLAYERS; pl_nr++) { + pl = teams[tm_nr].players[pl_nr]; + if (pl) { + if (PS_IS_used(pl->state) && PS_IS_aiplayer(pl->state)) + player_set_gfx (pl, teamdat[tm_nr].ai_gfx); + } + } +}; + + + inline int ai_checkfield (int x, int y) { @@ -584,6 +629,8 @@ single_create_ai (int num_players) pl->wins = 0; pl->points = 0; pl->team_nr = -1; + + team_choose (pl); } if (pl == NULL) @@ -656,7 +703,7 @@ single_playergame (int second_player, int ai_players) single_create_ai (ai_players); if (bman.gametype == GT_team) - teammenu (); + playermenu (); bman.state = GS_ready;