/* free all graphics */ static void mw_shutdown () { chat_show (-1, -1, -1, -1); gfx_blitdraw (); draw_logo (); SDL_Flip (gfx.screen); };
/* this will load some graphics and so other stuff */ static void mw_init () { team_update (); gfx_blitdraw (); draw_logo (); gfx_blitdraw (); bman.updatestatusbar = 1; d_playerdetail ("mw_init:\n"); SDL_Flip (gfx.screen); chat_show (10, gfx.res.y / 2, gfx.res.x - 20, gfx.res.y / 2 - 10); chat_setactive (1, 1); };
static void tgp_msg_display (struct tgl_state *TLS, struct tgp_msg_loading *C) { connection_data *conn = TLS->ev_base; struct tgl_message *M = C->msg; char *text = NULL; int flags = 0; // only display new messages, ignore updates or deletions if ((M->flags & (TGLMF_EMPTY | TGLMF_DELETED)) || !(M->flags & TGLMF_CREATED) || !M->message || tgp_outgoing_msg (TLS, M) || !tgl_get_peer_type (M->to_id)) { return; } if (M->flags & TGLMF_SERVICE) { text = format_service_msg (TLS, M); flags |= PURPLE_MESSAGE_SYSTEM; } else if (M->media.type == tgl_message_media_document && M->media.document->flags & TGLDF_STICKER) { #ifdef HAVE_LIBWEBP char *filename = C->data; int img = p2tgl_imgstore_add_with_id_webp (filename); if (img <= 0) { failure ("Cannot display sticker, adding to imgstore failed"); return; } used_images_add (conn, img); text = format_img_full (img); flags |= PURPLE_MESSAGE_IMAGES; g_free (filename); #else char *txt_user = p2tgl_strdup_alias (tgl_peer_get (TLS, M->from_id)); text = g_strdup_printf ("%s sent a sticker", txt_user); flags |= PURPLE_MESSAGE_SYSTEM; g_free (txt_user); #endif } else if (M->media.type == tgl_message_media_photo || (M->media.type == tgl_message_media_document_encr && M->media.encr_document->flags & TGLDF_IMAGE)) { char *filename = C->data; int img = p2tgl_imgstore_add_with_id (filename); if (img <= 0) { failure ("Cannot display picture message, adding to imgstore failed."); return; } used_images_add (conn, img); text = format_img_full (img); flags |= PURPLE_MESSAGE_IMAGES; g_free (filename); } else if (M->media.type == tgl_message_media_document) { char *who = p2tgl_strdup_id (M->from_id); if (! tgp_our_msg(TLS, M)) { tgprpl_recv_file (conn->gc, who, M->media.document); } g_free (who); return; } else if (M->media.type == tgl_message_media_document_encr) { char *who = p2tgl_strdup_id (M->to_id); if (! tgp_our_msg(TLS, M)) { tgprpl_recv_encr_file (conn->gc, who, M->media.encr_document); } g_free (who); return; } else { text = format_message (M); flags |= PURPLE_MESSAGE_RECV; } if (! text || ! *text) { warning ("No text to display"); return; } switch (tgl_get_peer_type (M->to_id)) { case TGL_PEER_CHAT: { if (chat_show (conn->gc, tgl_get_peer_id (M->to_id))) { p2tgl_got_chat_in (TLS, M->to_id, M->from_id, text, flags, M->date); } pending_reads_add (conn->pending_reads, M->to_id); break; } case TGL_PEER_ENCR_CHAT: { p2tgl_got_im (TLS, M->to_id, text, flags, M->date); pending_reads_add (conn->pending_reads, M->to_id); break; } case TGL_PEER_USER: { if (tgp_our_msg (TLS, M)) { flags |= PURPLE_MESSAGE_SEND; flags &= ~PURPLE_MESSAGE_RECV; p2tgl_got_im_combo (TLS, M->to_id, text, flags, M->date); } else { p2tgl_got_im (TLS, M->from_id, text, flags, M->date); pending_reads_add (conn->pending_reads, M->from_id); } break; } } if (p2tgl_status_is_present (purple_account_get_active_status (conn->pa)) && p2tgl_send_notifications(conn->pa)) { pending_reads_send_all (conn->pending_reads, conn->TLS); } g_free (text); }
static void tgp_msg_display (struct tgl_state *TLS, struct tgp_msg_loading *C) { connection_data *conn = TLS->ev_base; struct tgl_message *M = C->msg; char *text = NULL; int flags = 0; // Filter message updates and deletes, are not created and // all messages in general that were already displayed, or shouldn't be displayed if ((M->flags & (FLAG_MESSAGE_EMPTY | FLAG_DELETED)) || !(M->flags & FLAG_CREATED) || !M->message || our_msg (TLS, M) || !tgl_get_peer_type (M->to_id)) { return; } if (M->service) { text = format_service_msg (TLS, M); flags |= PURPLE_MESSAGE_SYSTEM; } else if (M->media.type == tgl_message_media_document) { char *who = p2tgl_strdup_id (M->from_id); if (! out_msg(TLS, M)) { tgprpl_recv_file (conn->gc, who, &M->media.document); } g_free (who); return; } else if (M->media.type == tgl_message_media_document_encr) { char *who = p2tgl_strdup_id (M->from_id); if (! out_msg(TLS, M)) { tgprpl_recv_encr_file (conn->gc, who, &M->media.encr_document); } g_free (who); } else if (M->media.type == tgl_message_media_photo) { char *filename = C->data; int imgStoreId = p2tgl_imgstore_add_with_id (filename); if (imgStoreId <= 0) { failure ("Cannot display picture message, adding to imgstore failed."); return; } used_images_add (conn, imgStoreId); text = format_img_full (imgStoreId); flags |= PURPLE_MESSAGE_IMAGES; } else { text = format_message (M); flags |= PURPLE_MESSAGE_RECV; } if (! text || ! *text) { warning ("No text to display"); return; } switch (tgl_get_peer_type (M->to_id)) { case TGL_PEER_CHAT: { if (chat_show (conn->gc, tgl_get_peer_id (M->to_id))) { p2tgl_got_chat_in (TLS, M->to_id, M->from_id, text, flags, M->date); } pending_reads_add (conn->pending_reads, M->to_id); break; } case TGL_PEER_ENCR_CHAT: { p2tgl_got_im (TLS, M->to_id, text, flags, M->date); pending_reads_add (conn->pending_reads, M->to_id); break; } case TGL_PEER_USER: { if (out_msg (TLS, M)) { flags |= PURPLE_MESSAGE_SEND; flags &= ~PURPLE_MESSAGE_RECV; p2tgl_got_im_combo (TLS, M->to_id, text, flags, M->date); } else { p2tgl_got_im (TLS, M->from_id, text, flags, M->date); pending_reads_add (conn->pending_reads, M->from_id); } break; } } if (p2tgl_status_is_present (purple_account_get_active_status (conn->pa))) { pending_reads_send_all (conn->pending_reads, conn->TLS); } g_free (text); }
void game_draw_info () { int i, x, j, col; char text[255]; char scrtext[255]; SDL_Rect src, dest; if (GT_MP && (chat.oldscreen == NULL || chat.window.x != 4 || chat.window.y != 4.5 * 16)) { chat_show (4, 4.5 * 16, gfx.res.x - 8, gfx.offset.y - 4.5 * 16); chat_setactive (0, 0); } if (bman.updatestatusbar) { redraw_logo (0, 0, gfx.res.x, (4.5 * 16)); dest.x = dest.y = 0; dest.h = 4.5 * 16; dest.w = gfx.res.x; gfx_blitupdaterectadd (&dest); /* In Multiplayer mode draw Player names and count the players who are still alife. */ for (x = 0, j = 0, i = 0; i < MAX_PLAYERS; i++) if ((players[i].state & PSFM_used) != 0) { if (players[i].gfx_nr != -1 && PS_IS_used (players[i].state)) { src.x = 0; src.y = 0; src.w = dest.w = players[i].gfx->small_image->w; src.h = dest.h = players[i].gfx->small_image->h; dest.x = x; dest.y = j - 4; SDL_BlitSurface (players[i].gfx->small_image, &src, gfx.screen, &dest); } sprintf (scrtext, "%10s:%d %1d %1d", players[i].name, players[i].wins, players[i].points, players[i].nbrKilled); if (!PS_IS_alife (players[i].state)) { // Player is dead if ((players[i].state & PSF_used) != PSF_used) col = 4; else col = 3; } else { // player is alife if (bman.gametype == GT_team) col = teams[players[i].team_nr].col; else col = 0; } font_draw (x, j, scrtext, 0, col); x = x + 180; if (x >= gfx.res.x - (120 + 170)) { x = 0; j = j + 1.5 * font[0].size.x; } } x = gfx.res.x - 120; sprintf (text, "Bombs: %2d", players[bman.p_nr].bombs_n); font_draw (x, 0, text, 0, 0); sprintf (text, "Range: %2d", players[bman.p_nr].range); font_draw (x, 16, text, 0, 0); sprintf (text, "Speed: %1.1f", players[bman.p_nr].speed * 10); font_draw (x, 32, text, 0, 0); if (players[bman.p_nr].special.type != 0) { col = players[bman.p_nr].special.type + FT_sp_trigger - 1; dest.x = x - 32; dest.y = 16; dest.w = gfx.menu_field[col]->w; dest.h = gfx.menu_field[col]->h; SDL_BlitSurface (gfx.menu_field[col], NULL, gfx.screen, &dest); } if (bman.state == GS_ready && GT_MP_PTPM) font_gfxdraw (100, 32, "Press F4 to start the game", 0, COLOR_yellow, 0xFFFF); else if (bman.state == GS_ready) font_gfxdraw (100, 32, "Waiting for the Server to Start", 0, COLOR_yellow, 0xFFFF); } /* draw the warning part */ if (map.state != MS_normal) { hurrywarn_to -= timediff; if (bman.updatestatusbar || hurrywarn_to <= 0.0 || hurrywarn_to > HURRYWARN_TO_BLINKING) { hurrywarn_to = HURRYWARN_TO_BLINKING; hurrywarn_state = !hurrywarn_state; if (hurrywarn_state) { font_drawbold ((gfx.res.x - strlen ("HURRY HURRY") * font[1].size.x) / 2, 40, "HURRY HURRY", 1, 0, 2); font_draw ((gfx.res.x - strlen ("HURRY HURRY") * font[1].size.x) / 2, 40, "HURRY HURRY", 1, 1); } else { font_drawbold ((gfx.res.x - strlen ("HURRY HURRY") * font[1].size.x) / 2, 40, "HURRY HURRY", 1, 1, 2); font_draw ((gfx.res.x - strlen ("HURRY HURRY") * font[1].size.x) / 2, 40, "HURRY HURRY", 1, 0); } dest.x = dest.y = 0; dest.h = 4.5 * 16; dest.w = gfx.res.x; gfx_blitupdaterectadd (&dest); } } if (debug) debug_ingameinfo (); bman.updatestatusbar = 0; };
void game_loop () { SDL_Event event; int done = 0, eventstate; if (GT_MP) net_game_fillsockaddr (); if ( SDL_InitSubSystem ( SDL_INIT_JOYSTICK ) < 0 ) { fprintf ( stderr, "Unable to initialize Joystick: %s\n", SDL_GetError() ); } printf ( "%i joysticks found\n", SDL_NumJoysticks () ); menu = NULL; bman.updatestatusbar = 1; // force an update timestamp = SDL_GetTicks (); // needed for time sync. d_gamedetail ("GAME START"); gfx_blitupdaterectclear (); draw_logo (); draw_field (); SDL_Flip (gfx.screen); draw_players (); if (bman.p_nr >= 0 && bman.p_nr < MAX_PLAYERS) { players[bman.p_nr].ready = 1; if (GT_MP_PTPS) send_playerdata (&players[bman.p_servnr].net.addr, bman.p_nr, &players[bman.p_nr]); } if (bman.p2_nr >= 0 && bman.p2_nr < MAX_PLAYERS) { players[bman.p2_nr].ready = 1; if (GT_MP_PTPS) send_playerdata (&players[bman.p_servnr].net.addr, bman.p2_nr, &players[bman.p2_nr]); } fire_init(); while (!done && (bman.state == GS_running || bman.state == GS_ready)) { SDL_JoystickUpdate (); if ((eventstate = SDL_PollEvent (&event)) != 0) switch (event.type) { case (SDL_QUIT): done = 1; bman.state = GS_quit; } /* * input handling */ keyb_loop (&event); game_keys_loop (); if (GT_MP) chat_loop (&event); if ((!IS_LPLAYER2) && (!chat.active)) chat_setactive (1, 1); restore_players_screen (); player_check (bman.p_nr); if (IS_LPLAYER2) player_check (bman.p2_nr); dead_playerani (); special_loop (); player_move (bman.p_nr); if (IS_LPLAYER2) player_move (bman.p2_nr); if (GT_MP) { player_calcpos (); network_loop (); } if (bman.state == GS_running) single_loop (); bomb_loop (); /* wind_loop (); SOON */ fire_loop (); field_loop (); flitems_loop (); draw_players (); game_draw_info (); // will set the var bman.player_nr /* check if there is only one player left and the game is in multiplayer mode and if there the last dieing animation is done */ if (game_check_endgame () && bman.timeout >= 0.0f) bman.timeout = 0.0f; if ((GT_SP || GT_MP_PTPM) && bman.timeout < -GAME_OVERTIMEOUT) { d_printf ("GAME: Game Over\n"); done = 1; } stonelist_draw (); /* if there is any menu displayed do so */ if (menu != NULL) game_menu_loop (&event, eventstate); gfx_blitdraw (); s_calctimesync (); bman.timeout -= timediff; } if (menu != NULL) { menu_delete (menu); menu = NULL; } gfx_blitdraw (); chat_show (-1, -1, -1, -1); draw_logo (); gfx_blitupdaterectclear (); SDL_Flip (gfx.screen); d_gamedetail ("GAME END"); d_printf ("done = %d\n", done); };