Example #1
0
/* the loop itself */
void wait_for_players ()
{
    SDL_Event event;

    mw_init ();

    do {
        if (s_fetchevent (&event) != 0)
            switch (event.type) {
            case (SDL_QUIT):
                bman.state = GS_quit;
                break;
            }

        /*
         * check some little things and do the network stuff
         */
        network_loop ();

        /*
         * the drawing stuff
         */
        if (mw_check_screenredraw()) {
            d_printf ("Draw Status\n");
            gfx_blitdraw ();
            draw_logo ();
            if (bman.gametype==GT_team) mw_draw_all_teams();
            else mw_draw_all_player ();
        }
        gfx_blitdraw ();

        /*
         *	input handling
         */
        keyb_loop (&event);
        mw_keys_loop ();

        chat_loop (&event);
        chat.active = 1;

        s_calctimesync ();
    } while (bman.state == GS_wait && bman.sock != -1);

    mw_shutdown ();
};
Example #2
0
void
game_showresult ()
{
    char text[255];
    SDL_Event event;
    Uint8 *keys;
    int done = 0,
        keypressed = 0,
        x,
        y;

    gfx_blitdraw ();

    draw_logo ();

    strcpy (text, "Game Result");
    x = (gfx.res.x - (font[2].size.x * strlen (text)) - 64) / 2;
    y = 0;
    font_drawbold (x, y, text, 2, 6, 2);
    font_draw (x, y, text, 2, 5);
    y += font[2].size.x;

    strcpy (text, "[CTRL],[RETURN] or [STRG] for another game");
    x = (gfx.res.x - (font[1].size.x * strlen (text)) - 64) / 2;
    font_drawbold (x, gfx.res.y - (2 * font[0].size.y) - 2, text, 0, COLOR_brown, 1);
    font_draw (x, gfx.res.y - (2 * font[0].size.y) - 2, text, 0, COLOR_yellow);

    strcpy (text, "or [ESC] to leave the game.");
    x = (gfx.res.x - (font[1].size.x * strlen (text)) - 64) / 2;
    font_drawbold (x, gfx.res.y - font[0].size.y - 2, text, 0, COLOR_brown, 1);
    font_draw (x, gfx.res.y - font[0].size.y - 2, text, 0, COLOR_yellow);

    if (bman.gametype == GT_team)
        game_showresultteam (10, 50, gfx.res.x - 20, gfx.res.y - 100);
    else
        game_showresultnormal (10, 50, gfx.res.x - 20, gfx.res.y - 100);

    gfx_blitdraw ();
    SDL_Flip (gfx.screen);

    while (!done && bman.state != GS_quit) {
        /* do the keyboard handling */
        if (s_fetchevent (&event) != 0)
            switch (event.type) {
            case (SDL_QUIT):
                bman.state = GS_quit;
                bman.p_nr = -1;
                done = 1;
            }

        keys = SDL_GetKeyState (NULL);

        if (keys[SDLK_ESCAPE] && event.type == SDL_KEYDOWN) {
            /* we want to quit */
            done = 1;
            bman.p_nr = -1;
            keypressed = 1;
            bman.state = GS_startup;
        }

        if ((keys[SDLK_RETURN] || keys[SDLK_LCTRL] || keys[SDLK_RCTRL]) && (!keypressed)
                && (event.type = SDL_KEYDOWN)) {
            done = 1;
            keypressed = 1;
        }

        if (keys[SDLK_F8] && event.type == SDL_KEYDOWN) {
            /* Switch Fullscreen */
            SDL_WM_ToggleFullScreen (gfx.screen);
            gfx.fullscreen = !gfx.fullscreen;
            bman.updatestatusbar = 1; // force an update
        }

        if (event.type == SDL_KEYUP)
            keypressed = 0;
        else if (event.type == SDL_KEYDOWN)
            keypressed = 1;

        s_delay (25);
    }

    if (bman.state != GS_quit && bman.state != GS_startup)
        bman.state = GS_running;
};
Example #3
0
/*
    sets up everything for the network game..
	on servers the game field will be created and the clients will wait for the game data
	within the network loop
*/
void
net_transmit_gamedata ()
{
    int done = 0,
        keypressed = 0,
        x,
        y,                      // network upload status for one step
        p,
        i,
        net_istep;              // network init step
    SDL_Event event;
    Uint8 *keys;
    Uint32 downtimestamp = 0;

    draw_logo ();

    if (GT_MP_PTPM)
        font_draw (100, 0, "Waiting for the Clients", 1, 0);
    else
        font_draw (100, 0, "Downloading Data", 1, 0);

    /* 
       prepare everything for the loop 
     */
    for (x = 0; x < MAX_PLAYERS; x++) {
        players[x].net.timestamp = 0;
        players[x].net.net_status = -1;
        if ((PS_IS_aiplayer (players[x].state)) || (x == bman.p_servnr) || (x == bman.p2_nr)
            || (players[x].net.flags & NETF_local2) == NETF_local2)
            players[x].net.net_istep = 0;
        else
            players[x].net.net_istep = 3;
    }

    y = -1;
    if (GT_MP_PTPM)
        net_istep = 0;
    else
        net_istep = 3;

    draw_netupdatestate (1);
    SDL_Flip (gfx.screen);

    downtimestamp = timestamp;
    while (!done && (bman.state == GS_update || (GT_MP_PTPS && net_istep != 0))) {
        /* the network thing */

        network_loop ();

        /* if PTPM check if all players are ready */
        if (GT_MP_PTPM) {
            if (timestamp - downtimestamp > TIME_UPDATEINFO) {
                downtimestamp = timestamp;
                net_send_updateinfo ();
            }
            for (p = 0, i = 1; p < MAX_PLAYERS; p++)
                if (PS_IS_playing (players[p].state)
                    && players[p].net.net_istep != 0)
                    i = 0;
            if (i == 1) {       /* all players are ready */
                done = 1;
                bman.state = GS_ready;
            }
        }

        /* if PTPS get all data */
        if (GT_MP_PTPS) {
            if (net_istep == 3) {
                /* 
                   get tunneldata 
                 */
                if ((y < GAME_MAX_TUNNELS - 1 && y == players[bman.p_nr].net.net_status)
                    || y == -1) {
                    y++;
                    downtimestamp = timestamp;
                    send_tunneldata (&players[bman.p_servnr].net.addr, y, -1, -1);
                }
                else if (y < GAME_MAX_TUNNELS
                         && y != players[bman.p_nr].net.net_status && y >= 0
                         && timestamp - downtimestamp > DOWNLOAD_TIMEOUT) {
                    /* we have got no tunnel data */
                    y--;
                }
                else if (y == GAME_MAX_TUNNELS - 1 && players[bman.p_nr].net.net_status == y) {
                    /* we have got all tunnel data */
                    y = -1;
                    players[bman.p_nr].net.net_istep = --net_istep;
                    players[bman.p_nr].net.net_status = -1;
                }
            }

            if (net_istep == 2) {
                /* 
                   get field data
                 */
                if ((y < map.size.y - 1 && y == players[bman.p_nr].net.net_status)
                    || y == -1) {
                    /* send field data req */
                    y++;
                    downtimestamp = timestamp;
                    send_getfield (&players[bman.p_servnr].net.addr, y);
                }
                else if (y < map.size.y && y != players[bman.p_nr].net.net_status
                         && y >= 0 && timestamp - downtimestamp > DOWNLOAD_TIMEOUT) {
                    /* getdata timed out - we have got no field data */
                    y--;
                }
                else if (y == map.size.y - 1 && players[bman.p_nr].net.net_status == y) {
                    /* we have got all field data */
                    y = -1;
                    players[bman.p_nr].net.net_istep = --net_istep;
                    players[bman.p_nr].net.net_status = -1;
                }
            }

            if (net_istep == 1) {
                /*
                   get player data
                 */
                if ((y < MAX_PLAYERS - 1 && y == players[bman.p_nr].net.net_status)
                    || y == -1) {
                    /* send player date req */
                    y++;
                    downtimestamp = timestamp;
                    send_getplayerdata (&players[bman.p_servnr].net.addr, y);
                }
                if (y < MAX_PLAYERS && y != players[bman.p_nr].net.net_status
                    && y >= 0 && timestamp - downtimestamp > DOWNLOAD_TIMEOUT) {
                    /* we have got no player data */
                    y--;
                }
                if (y == MAX_PLAYERS - 1 && players[bman.p_nr].net.net_status == y) {
                    /* we have got all playerdata */
                    y = -1;
                    players[bman.p_nr].net.net_istep = --net_istep;
                    players[bman.p_nr].net.net_status = -1;
                    downtimestamp = timestamp;
                    send_playerstatus (&players[bman.p_servnr].net.addr, bman.p_nr, 0, 0);
                }
            }

            if (net_istep == 0 && players[bman.p_nr].net.net_status == -1
                && timestamp - downtimestamp > DOWNLOAD_TIMEOUT) {
                /* server did not send informations back */
                downtimestamp = timestamp;
                send_playerstatus (&players[bman.p_servnr].net.addr, bman.p_nr, 0, 0);
            }
        }

        /* do the grafik work */
        draw_netupdatestate (0);

        if (s_fetchevent (&event) != 0)
            switch (event.type) {
            case (SDL_QUIT):
                bman.state = GS_quit;
                bman.p_nr = -1;
                done = 1;
            }

        keys = SDL_GetKeyState (NULL);

        if (keys[SDLK_ESCAPE] && event.type == SDL_KEYDOWN) {
            done = 1;
            bman.p_nr = -1;
            keypressed = 1;
            bman.state = GS_startup;
        }

        if (event.type == SDL_KEYUP)
            keypressed = 0;
    }

    timestamp = SDL_GetTicks (); // needed for time sync.
    SDL_Delay (1);              // we don't need here anything better

    /* player is only watching so just go after we have got everything
       go to show the field */
    if (GT_MP_PTPS && bman.state == GS_update && net_istep == 0 && players[bman.p_nr].gfx_nr == -1) {
        done = 1;
        bman.state = GS_running;
    }
};
Example #4
0
/* singleplayer menĂ¼ with some options you can make */
void
single_menu ()
{
    int i,
		p,
		eventstate = 0,
        done = 0,
		second_player = 0;
    _charlist nrplayerlist[MAX_PLAYERS + 1];
    _charlist *selnrplayer = &nrplayerlist[bman.ai_players];
	_menu *menu;
	_menuitem *aiplayer = NULL;
	SDL_Event event;

    /* fill in the nrplayerlist */
    for (p = 0, 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++;
    }
	
	game_resetdata ();
	
	menu = menu_new ("Single Game", 380,240);
	
	menu_create_text (menu, "numpl", 20, 50, 12, 2, COLOR_yellow, "Number of\nAI Players");
	aiplayer = menu_create_list (menu, "AI Players", 40, 90, 50, 100, nrplayerlist, &selnrplayer, 3);
	
	menu_create_button (menu,"Change Playernames" ,160, 50, 210, 4);

	menu_create_bool (menu, "Use Second Player", 160, 90, 210, &second_player, 5);

	menu_create_button (menu, "Game Options", 180, 130, 150, 6);
	menu_create_button (menu, "Map Options", 180, 170, 150, 7);
	menu_create_button (menu, "Main Menu", 30, 220, 150, 1);
	menu_create_button (menu, "Start", 220, 220, 150, 2);
	
	menu_focus_id (menu, 2);
	menu->looprunning = 1;
	menu_draw (menu);
	
	do {
		gfx_blitdraw ();
		eventstate = s_fetchevent (&event);

		done = menu_event_loop (menu, &event, eventstate);

		if (done > 0 && menu->focus->id == 6) {
			done = 0;
			mapgamesetting ();
		}
		
		if (done > 0 && menu->focus->id == 7) {
			done = 0;
			mapmenu ();
		}
		
		if (done > 0 && menu->focus->id == 4) {
			done = 0;
			playernamemenu ();
		}
		
		if (done > 0 && menu->focus->id == 3)
			done = 0;
		
		s_calctimesync ();
	} while (!done); 
	
	bman.ai_players = selnrplayer - &nrplayerlist[0];
	
	if (menu->focus->id == 2)
		single_playergame (second_player, bman.ai_players);

	menu_delete (menu);
};