From fded0fbfeb4a7ac00bd5c3b65604d5dc1631ffac Mon Sep 17 00:00:00 2001 From: Magnus Larsen Date: Tue, 5 Nov 2024 16:08:31 -0800 Subject: [PATCH 1/7] Move is_twoplayer and friends to game_state --- src/game/game_state.c | 22 ++++++++++++++++ src/game/game_state.h | 6 +++++ src/game/scenes/arena.c | 57 ++++++++--------------------------------- 3 files changed, 38 insertions(+), 47 deletions(-) diff --git a/src/game/game_state.c b/src/game/game_state.c index cdba70360..8a671cf09 100644 --- a/src/game/game_state.c +++ b/src/game/game_state.c @@ -1022,3 +1022,25 @@ int game_state_clone(game_state *src, game_state *dst) { return 0; } + +bool is_netplay(game_state *gs) { + return game_state_get_player(gs, 0)->ctrl->type == CTRL_TYPE_NETWORK || + game_state_get_player(gs, 1)->ctrl->type == CTRL_TYPE_NETWORK; +} + +bool is_singleplayer(game_state *gs) { + return game_state_get_player(gs, 1)->ctrl->type == CTRL_TYPE_AI; +} + +bool is_tournament(game_state *gs) { + return game_state_get_player(gs, 0)->chr; +} + +bool is_demoplay(game_state *gs) { + return game_state_get_player(gs, 0)->ctrl->type == CTRL_TYPE_AI && + game_state_get_player(gs, 1)->ctrl->type == CTRL_TYPE_AI; +} + +bool is_twoplayer(game_state *gs) { + return !is_demoplay(gs) && !is_netplay(gs) && !is_singleplayer(gs); +} diff --git a/src/game/game_state.h b/src/game/game_state.h index c19abcde4..8c4552a6b 100644 --- a/src/game/game_state.h +++ b/src/game/game_state.h @@ -57,4 +57,10 @@ void game_state_del_animation(game_state *gs, int anim_id); void game_state_get_projectiles(game_state *gs, vector *obj_proj); void game_state_clear_hazards_projectiles(game_state *gs); +bool is_netplay(game_state *gs); +bool is_singleplayer(game_state *gs); +bool is_tournament(game_state *gs); +bool is_demoplay(game_state *gs); +bool is_twoplayer(game_state *gs); + #endif // GAME_STATE_H diff --git a/src/game/scenes/arena.c b/src/game/scenes/arena.c index e842b11fd..57fcb0474 100644 --- a/src/game/scenes/arena.c +++ b/src/game/scenes/arena.c @@ -193,43 +193,6 @@ void arena_repeat_controller(void *userdata) { controller_set_repeat(game_player_get_ctrl(player1), 1); } -int is_netplay(scene *scene) { - if(game_state_get_player(scene->gs, 0)->ctrl->type == CTRL_TYPE_NETWORK || - game_state_get_player(scene->gs, 1)->ctrl->type == CTRL_TYPE_NETWORK) { - return 1; - } - return 0; -} - -int is_singleplayer(scene *scene) { - if(game_state_get_player(scene->gs, 1)->ctrl->type == CTRL_TYPE_AI) { - return 1; - } - return 0; -} - -int is_tournament(scene *scene) { - if(game_state_get_player(scene->gs, 0)->chr) { - return 1; - } - return 0; -} - -int is_demoplay(scene *scene) { - if(game_state_get_player(scene->gs, 0)->ctrl->type == CTRL_TYPE_AI && - game_state_get_player(scene->gs, 1)->ctrl->type == CTRL_TYPE_AI) { - return 1; - } - return 0; -} - -int is_twoplayer(scene *scene) { - if(!is_demoplay(scene) && !is_netplay(scene) && !is_singleplayer(scene)) { - return 1; - } - return 0; -} - void arena_screengrab_winner(scene *sc) { game_state *gs = sc->gs; @@ -251,12 +214,12 @@ void arena_end(scene *sc) { int next_id; // Switch scene - if(is_demoplay(sc)) { + if(is_demoplay(gs)) { do { next_id = rand_arena(); } while(next_id == sc->id); game_state_set_next(gs, next_id); - } else if(is_singleplayer(sc) || is_tournament(sc)) { + } else if(is_singleplayer(gs) || is_tournament(gs)) { game_player *p1 = game_state_get_player(gs, 0); game_player *p2 = game_state_get_player(gs, 1); har *p1_har = object_get_userdata(game_state_find_object(gs, game_player_get_har_obj_id(p1))); @@ -312,7 +275,7 @@ void arena_end(scene *sc) { PERROR("Failed to save pilot %s", p1->chr->pilot.name); } game_state_set_next(gs, SCENE_NEWSROOM); - } else if(is_twoplayer(sc)) { + } else if(is_twoplayer(gs)) { game_state_set_next(gs, SCENE_MELEE); } else if(gs->net_mode == NET_MODE_LOBBY) { game_state_set_next(gs, SCENE_LOBBY); @@ -563,7 +526,7 @@ void arena_har_defeat_hook(int player_id, scene *scene) { } else if(player_winner->ctrl->type == CTRL_TYPE_NETWORK && player_loser->ctrl->type != CTRL_TYPE_NETWORK) { scene_youlose_anim_start(scene->gs); } else { - if(!is_singleplayer(scene)) { + if(!is_singleplayer(gs)) { // XXX in two player mode, "you win" should always be displayed scene_youwin_anim_start(scene->gs); } else { @@ -598,7 +561,7 @@ void arena_har_defeat_hook(int player_id, scene *scene) { chr_score_victory(score, har_health_percent(winner_har)); winner_har->state = STATE_VICTORY; local->over = 1; - if(is_singleplayer(scene)) { + if(is_singleplayer(gs)) { player_winner->sp_wins |= 2 << player_loser->pilot->pilot_id; if(player_loser->pilot->pilot_id == PILOT_KREISSACK) { // can't scrap/destruct kreissack @@ -890,7 +853,7 @@ int arena_handle_events(scene *scene, game_player *player, ctrl_event *i) { } else if(i->type == EVENT_TYPE_ACTION && local->menu_visible && (player->ctrl->type == CTRL_TYPE_KEYBOARD || player->ctrl->type == CTRL_TYPE_GAMEPAD) && i->event_data.action != ACT_ESC && /* take AST_ESC only from player 1 */ - !is_demoplay(scene)) { + !is_demoplay(scene->gs)) { DEBUG("menu event %d", i->event_data.action); // menu events guiframe_action(local->game_menu, i->event_data.action); @@ -1086,7 +1049,7 @@ void arena_input_tick(scene *scene) { int arena_event(scene *scene, SDL_Event *e) { // ESC during demo mode jumps you back to the main menu - if(e->type == SDL_KEYDOWN && is_demoplay(scene) && e->key.keysym.sym == SDLK_ESCAPE) { + if(e->type == SDL_KEYDOWN && is_demoplay(scene->gs) && e->key.keysym.sym == SDLK_ESCAPE) { game_state_set_next(scene->gs, SCENE_MENU); } return 0; @@ -1429,7 +1392,7 @@ int arena_create(scene *scene) { component *speed_slider = textslider_create_bind( &tconf, "SPEED", "Change the speed of the game when in the arena. Press left or right to change", 10, 0, arena_speed_slide, scene, &setting->gameplay.speed); - if(is_netplay(scene)) { + if(is_netplay(scene->gs)) { component_disable(speed_slider, 1); } menu_attach(menu, speed_slider); @@ -1464,11 +1427,11 @@ int arena_create(scene *scene) { OBJECT_FACE_LEFT); // TODO: Set better coordinates for this // Reset the score - chr_score_reset(game_player_get_score(_player[0]), !is_singleplayer(scene)); + chr_score_reset(game_player_get_score(_player[0]), !is_singleplayer(scene->gs)); chr_score_reset(game_player_get_score(_player[1]), 1); // Reset the win counter in single player mode - if(is_singleplayer(scene)) { + if(is_singleplayer(scene->gs)) { chr_score_reset_wins(game_player_get_score(_player[0])); chr_score_reset_wins(game_player_get_score(_player[1])); } From f079b4d0339d78f303dfbd9138383bb76f20471e Mon Sep 17 00:00:00 2001 From: Magnus Larsen Date: Tue, 5 Nov 2024 15:58:42 -0800 Subject: [PATCH 2/7] DEMO the VS and Newsroom scenes, too The original game also goes through MELEE, but I think that's less important. --- src/controller/ai_controller.c | 6 ++++++ src/game/common_defines.h | 2 ++ src/game/game_state.c | 11 ++++++++--- src/game/scenes/arena.c | 17 +---------------- src/game/scenes/mainmenu/menu_main.c | 2 +- src/game/scenes/newsroom.c | 5 +++++ src/game/scenes/vs.c | 5 +++++ 7 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/controller/ai_controller.c b/src/controller/ai_controller.c index 82a575ea1..daa1f1eed 100644 --- a/src/controller/ai_controller.c +++ b/src/controller/ai_controller.c @@ -2578,6 +2578,12 @@ bool handle_queued_tactic(controller *ctrl, ctrl_event **ev) { int ai_controller_poll(controller *ctrl, ctrl_event **ev) { ai *a = ctrl->data; object *o = game_state_find_object(ctrl->gs, ctrl->har_obj_id); + scene *scene = game_state_get_scene(ctrl->gs); + if(scene->id == SCENE_VS || scene->id == SCENE_NEWSROOM) { + if(ctrl->gs->warp_speed || (scene->static_ticks_since_start + 1) % 256 == 0) { + controller_cmd(ctrl, ACT_PUNCH, ev); + } + } if(!o) { return 1; } diff --git a/src/game/common_defines.h b/src/game/common_defines.h index 382293dcd..21e559517 100644 --- a/src/game/common_defines.h +++ b/src/game/common_defines.h @@ -91,6 +91,8 @@ enum PILOT_RAVEN, PILOT_KREISSACK, NUMBER_OF_PILOT_TYPES, + // Major Kreissack is not a playable character + NUMBER_OF_PLAYABLE_PILOT_TYPES = NUMBER_OF_PILOT_TYPES - 1, }; enum diff --git a/src/game/game_state.c b/src/game/game_state.c index 8a671cf09..b3e3a8285 100644 --- a/src/game/game_state.c +++ b/src/game/game_state.c @@ -320,6 +320,11 @@ void game_state_set_paused(game_state *gs, unsigned int paused) { // Return 0 if event was handled here int game_state_handle_event(game_state *gs, SDL_Event *event) { + // ESC during demo mode jumps you back to the main menu + if(event->type == SDL_KEYDOWN && is_demoplay(gs) && event->key.keysym.sym == SDLK_ESCAPE) { + game_state_set_next(gs, SCENE_MENU); + return 0; + } if(scene_event(gs->sc, event) == 0) { return 0; } @@ -882,11 +887,11 @@ void game_state_init_demo(game_state *gs) { sd_pilot *pl = game_player_get_pilot(player); ai_controller_create(ctrl, 4, pl, player->pilot->pilot_id); game_player_set_ctrl(player, ctrl); - game_player_set_selectable(player, 1); + game_player_set_selectable(player, 0); // select random pilot and har - player->pilot->pilot_id = rand_int(10); - player->pilot->har_id = rand_int(11); + player->pilot->pilot_id = rand_int(NUMBER_OF_PLAYABLE_PILOT_TYPES); + player->pilot->har_id = rand_int(NUMBER_OF_HAR_TYPES); chr_score_reset(&player->score, 1); // set proper color diff --git a/src/game/scenes/arena.c b/src/game/scenes/arena.c index 57fcb0474..a87a23572 100644 --- a/src/game/scenes/arena.c +++ b/src/game/scenes/arena.c @@ -211,15 +211,9 @@ void arena_end(scene *sc) { game_state *gs = sc->gs; const scene *scene = game_state_get_scene(gs); fight_stats *fight_stats = &gs->fight_stats; - int next_id; // Switch scene - if(is_demoplay(gs)) { - do { - next_id = rand_arena(); - } while(next_id == sc->id); - game_state_set_next(gs, next_id); - } else if(is_singleplayer(gs) || is_tournament(gs)) { + if(is_singleplayer(gs) || is_tournament(gs) || is_demoplay(gs)) { game_player *p1 = game_state_get_player(gs, 0); game_player *p2 = game_state_get_player(gs, 1); har *p1_har = object_get_userdata(game_state_find_object(gs, game_player_get_har_obj_id(p1))); @@ -1048,10 +1042,6 @@ void arena_input_tick(scene *scene) { } int arena_event(scene *scene, SDL_Event *e) { - // ESC during demo mode jumps you back to the main menu - if(e->type == SDL_KEYDOWN && is_demoplay(scene->gs) && e->key.keysym.sym == SDLK_ESCAPE) { - game_state_set_next(scene->gs, SCENE_MENU); - } return 0; } @@ -1195,11 +1185,6 @@ int arena_create(scene *scene) { fight_stats *fight_stats = &scene->gs->fight_stats; memset(fight_stats, 0, sizeof(*fight_stats)); - // Initialize Demo - if(is_demoplay(scene)) { - game_state_init_demo(scene->gs); - } - // Handle music playback switch(scene->bk_data->file_id) { case 8: diff --git a/src/game/scenes/mainmenu/menu_main.c b/src/game/scenes/mainmenu/menu_main.c index 7f056f095..559495e3c 100644 --- a/src/game/scenes/mainmenu/menu_main.c +++ b/src/game/scenes/mainmenu/menu_main.c @@ -62,7 +62,7 @@ void mainmenu_demo(component *c, void *userdata) { // Set up controllers game_state_init_demo(s->gs); - game_state_set_next(s->gs, rand_arena()); + game_state_set_next(s->gs, SCENE_VS); } void mainmenu_soreboard(component *c, void *userdata) { diff --git a/src/game/scenes/newsroom.c b/src/game/scenes/newsroom.c index f7928afdc..c265c92de 100644 --- a/src/game/scenes/newsroom.c +++ b/src/game/scenes/newsroom.c @@ -232,6 +232,11 @@ void newsroom_input_tick(scene *scene) { local->screen++; newsroom_fixup_str(local); + if(is_demoplay(scene->gs) && local->screen >= 2) { + game_state_set_next(scene->gs, SCENE_VS); + continue; + } + if((local->screen >= 2 && !local->champion) || local->screen >= 3) { if(local->won || player1->chr) { // pick a new player diff --git a/src/game/scenes/vs.c b/src/game/scenes/vs.c index 4c1f9e30e..04aa0cab6 100644 --- a/src/game/scenes/vs.c +++ b/src/game/scenes/vs.c @@ -409,6 +409,11 @@ void vs_too_pathetic_dialog_clicked(dialog *dlg, dialog_result result) { } int vs_create(scene *scene) { + // Initialize Demo + if(is_demoplay(scene->gs)) { + game_state_init_demo(scene->gs); + } + // Init local data vs_local *local = omf_calloc(1, sizeof(vs_local)); scene_set_userdata(scene, local); From 7680d1ab207a1410169034cc4a24de92402c27a1 Mon Sep 17 00:00:00 2001 From: Magnus Larsen Date: Tue, 5 Nov 2024 16:55:22 -0800 Subject: [PATCH 3/7] Remove lines from newsroom menu_background --- src/console/console.c | 2 +- src/game/gui/menu.c | 4 +-- src/game/gui/menu_background.c | 52 ++++++++++++++++++---------------- src/game/gui/menu_background.h | 13 +++++++-- src/game/scenes/melee.c | 4 +-- src/game/scenes/newsroom.c | 2 +- src/game/scenes/vs.c | 2 +- 7 files changed, 45 insertions(+), 34 deletions(-) diff --git a/src/console/console.c b/src/console/console.c index 77848502d..164a97727 100644 --- a/src/console/console.c +++ b/src/console/console.c @@ -232,7 +232,7 @@ bool console_init(void) { list_create(&con->history); hashmap_create(&con->cmds); menu_transparent_bg_create(&con->background1, 322, 101); - menu_background_create(&con->background2, 322, 101); + menu_background_create(&con->background2, 322, 101, MenuBackground); // Read from stdin needs to be nonblocking #if !defined(WIN32) && !defined(_WIN32) diff --git a/src/game/gui/menu.c b/src/game/gui/menu.c index 5a01ecbe3..2b6ae0cce 100644 --- a/src/game/gui/menu.c +++ b/src/game/gui/menu.c @@ -304,7 +304,7 @@ static void menu_layout(component *c, int x, int y, int w, int h) { } if(m->bg2 == NULL && m->background) { m->bg2 = omf_malloc(sizeof(surface)); - menu_background_create(m->bg2, w, height + m->margin_top * 2); + menu_background_create(m->bg2, w, height + m->margin_top * 2, MenuBackground); } if(m->help_bg1 == NULL && m->background) { m->help_bg1 = omf_calloc(1, sizeof(surface)); @@ -312,7 +312,7 @@ static void menu_layout(component *c, int x, int y, int w, int h) { } if(m->help_bg2 == NULL && m->background) { m->help_bg2 = omf_calloc(1, sizeof(surface)); - menu_background_create(m->help_bg2, m->help_w + 16, m->help_w / 8); + menu_background_create(m->help_bg2, m->help_w + 16, m->help_w / 8, MenuBackground); } component_set_size_hints(c, w, height); diff --git a/src/game/gui/menu_background.c b/src/game/gui/menu_background.c index a2f9dbb1c..a266460cb 100644 --- a/src/game/gui/menu_background.c +++ b/src/game/gui/menu_background.c @@ -13,35 +13,37 @@ void menu_transparent_bg_create(surface *s, int w, int h) { surface_set_transparency(s, -1); } -void menu_background_create(surface *s, int w, int h) { +void menu_background_create(surface *s, int w, int h, menu_background_style style) { image img; image_create(&img, w, h); image_clear(&img, COLOR_MENU_BG); - for(int x = 5; x < w; x += 8) { - image_line(&img, x, 0, x, h - 1, COLOR_MENU_LINE); + switch(style) { + case MenuBackground: { + for(int x = 5; x < w; x += 8) { + image_line(&img, x, 0, x, h - 1, COLOR_MENU_LINE); + } + for(int y = 5; y < h; y += 8) { + image_line(&img, 0, y, w - 1, y, COLOR_MENU_LINE); + } + image_rect(&img, 0, 0, w - 1, h - 1, COLOR_MENU_BORDER); + break; + } + case MenuBackgroundMeleeVs: { + for(int x = 5; x < w; x += 5) { + image_line(&img, x, 0, x, h - 1, COLOR_MENU_LINE2); + } + for(int y = 4; y < h; y += 5) { + image_line(&img, 0, y, w - 1, y, COLOR_MENU_LINE2); + } + image_rect(&img, 1, 1, w - 2, h - 2, COLOR_MENU_BORDER2); + image_rect(&img, 0, 0, w - 2, h - 2, COLOR_MENU_BORDER1); + break; + } + case MenuBackgroundNewsroom: { + image_rect(&img, 0, 0, w - 1, h - 1, COLOR_MENU_BORDER); + break; + } } - for(int y = 5; y < h; y += 8) { - image_line(&img, 0, y, w - 1, y, COLOR_MENU_LINE); - } - image_rect(&img, 0, 0, w - 1, h - 1, COLOR_MENU_BORDER); - surface_create_from_image(s, &img); - surface_set_transparency(s, COLOR_MENU_BG); - image_free(&img); -} - -// the *other* style menu background, used on VS and MELEE -void menu_background2_create(surface *s, int w, int h) { - image img; - image_create(&img, w, h); - image_clear(&img, COLOR_MENU_BG); - for(int x = 5; x < w; x += 5) { - image_line(&img, x, 0, x, h - 1, COLOR_MENU_LINE2); - } - for(int y = 4; y < h; y += 5) { - image_line(&img, 0, y, w - 1, y, COLOR_MENU_LINE2); - } - image_rect(&img, 1, 1, w - 2, h - 2, COLOR_MENU_BORDER2); - image_rect(&img, 0, 0, w - 2, h - 2, COLOR_MENU_BORDER1); surface_create_from_image(s, &img); surface_set_transparency(s, COLOR_MENU_BG); image_free(&img); diff --git a/src/game/gui/menu_background.h b/src/game/gui/menu_background.h index db084e85e..7bb893fb9 100644 --- a/src/game/gui/menu_background.h +++ b/src/game/gui/menu_background.h @@ -3,9 +3,18 @@ #include "video/surface.h" +typedef enum menu_background_style_t +{ + // blue borders, coarse grid + MenuBackground, + // green borders, finer grid + MenuBackgroundMeleeVs, + // blue borders, no grid + MenuBackgroundNewsroom, +} menu_background_style; + void menu_transparent_bg_create(surface *s, int w, int h); -void menu_background_create(surface *sur, int w, int h); -void menu_background2_create(surface *sur, int w, int h); +void menu_background_create(surface *sur, int w, int h, menu_background_style); void menu_background_border_create(surface *sur, int w, int h); #endif // MENU_BACKGROUND_H diff --git a/src/game/scenes/melee.c b/src/game/scenes/melee.c index c6660128f..fab6b7941 100644 --- a/src/game/scenes/melee.c +++ b/src/game/scenes/melee.c @@ -731,8 +731,8 @@ int melee_create(scene *scene) { palette_set_player_color(0, 8, 1); palette_set_player_color(0, 8, 2); - menu_background2_create(&local->bg_player_stats, 90, 61); - menu_background2_create(&local->bg_player_bio, 160, 43); + menu_background_create(&local->bg_player_stats, 90, 61, MenuBackgroundMeleeVs); + menu_background_create(&local->bg_player_bio, 160, 43, MenuBackgroundMeleeVs); // Create a black surface for the highlight box. We modify the palette in renderer. unsigned char *black = omf_calloc(1, 51 * 36); diff --git a/src/game/scenes/newsroom.c b/src/game/scenes/newsroom.c index c265c92de..7a63fecdc 100644 --- a/src/game/scenes/newsroom.c +++ b/src/game/scenes/newsroom.c @@ -329,7 +329,7 @@ int newsroom_create(scene *scene) { local->screen = 0; local->champion = false; menu_transparent_bg_create(&local->news_bg1, 280, 55); - menu_background_create(&local->news_bg2, 280, 55); + menu_background_create(&local->news_bg2, 280, 55, MenuBackgroundNewsroom); game_player *p1 = game_state_get_player(scene->gs, 0); game_player *p2 = game_state_get_player(scene->gs, 1); diff --git a/src/game/scenes/vs.c b/src/game/scenes/vs.c index 04aa0cab6..b593b98ae 100644 --- a/src/game/scenes/vs.c +++ b/src/game/scenes/vs.c @@ -640,7 +640,7 @@ int vs_create(scene *scene) { } // Background tex - menu_background2_create(&local->arena_select_bg, 211, 50); + menu_background_create(&local->arena_select_bg, 211, 50, MenuBackgroundMeleeVs); // Quit Dialog dialog_create(&local->quit_dialog, DIALOG_STYLE_YES_NO, "Are you sure you want to quit this game?", 72, 60); From cc7d72430fc98677e123299410edf34118fcd652 Mon Sep 17 00:00:00 2001 From: Magnus Larsen Date: Tue, 5 Nov 2024 17:17:14 -0800 Subject: [PATCH 4/7] Support pressing ENTER during DEMO to skip menus --- src/game/game_state.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/game/game_state.c b/src/game/game_state.c index b3e3a8285..bf1e6d3d9 100644 --- a/src/game/game_state.c +++ b/src/game/game_state.c @@ -320,10 +320,19 @@ void game_state_set_paused(game_state *gs, unsigned int paused) { // Return 0 if event was handled here int game_state_handle_event(game_state *gs, SDL_Event *event) { - // ESC during demo mode jumps you back to the main menu if(event->type == SDL_KEYDOWN && is_demoplay(gs) && event->key.keysym.sym == SDLK_ESCAPE) { + // ESC during demo mode jumps you back to the main menu game_state_set_next(gs, SCENE_MENU); return 0; + } else if(event->type == SDL_KEYDOWN && is_demoplay(gs) && event->key.keysym.sym == SDLK_RETURN) { + // ENTER during demo mode skips menus + if(gs->sc->id < SCENE_ARENA0 || gs->sc->id > SCENE_ARENA4) { + if(gs->sc->id != SCENE_VS) { + game_state_init_demo(gs); + } + game_state_set_next(gs, rand_arena()); + return 0; + } } if(scene_event(gs->sc, event) == 0) { return 0; From c2fec6b8341cf6006a3fd427d75a36c488b65470 Mon Sep 17 00:00:00 2001 From: Magnus Larsen Date: Mon, 25 Nov 2024 20:55:42 -0800 Subject: [PATCH 5/7] Always play "you lose" in demo mode --- src/game/scenes/arena.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/game/scenes/arena.c b/src/game/scenes/arena.c index a87a23572..00d1b0463 100644 --- a/src/game/scenes/arena.c +++ b/src/game/scenes/arena.c @@ -520,7 +520,10 @@ void arena_har_defeat_hook(int player_id, scene *scene) { } else if(player_winner->ctrl->type == CTRL_TYPE_NETWORK && player_loser->ctrl->type != CTRL_TYPE_NETWORK) { scene_youlose_anim_start(scene->gs); } else { - if(!is_singleplayer(gs)) { + if(is_demoplay(gs)) { + // in demo mode, "you lose" should always be displayed + scene_youlose_anim_start(scene->gs); + } else if(!is_singleplayer(gs)) { // XXX in two player mode, "you win" should always be displayed scene_youwin_anim_start(scene->gs); } else { From 083bab22875673158b9d703eb35f6ea5d823eb1a Mon Sep 17 00:00:00 2001 From: Magnus Larsen Date: Mon, 25 Nov 2024 21:36:46 -0800 Subject: [PATCH 6/7] Don't display score's points for AIs Score's toasts, such as "3 HIT COMBO" will still be displayed. --- src/game/scenes/arena.c | 13 +++++++------ src/game/utils/score.c | 35 +++++++++++++++++++++-------------- src/game/utils/score.h | 3 ++- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/game/scenes/arena.c b/src/game/scenes/arena.c index 00d1b0463..991b0faee 100644 --- a/src/game/scenes/arena.c +++ b/src/game/scenes/arena.c @@ -353,7 +353,8 @@ void arena_har_take_hit_hook(int hittee, af_move *move, scene *scene) { if(h->state == STATE_RECOIL) { DEBUG("COMBO!"); } - chr_score_hit(score, move->points); + bool no_points = is_demoplay(scene->gs) || !game_state_get_player(scene->gs, hitter)->selectable; + chr_score_hit(score, no_points ? 0 : move->points); chr_score_interrupt(otherscore, object_get_pos(hit_har)); } @@ -1116,13 +1117,13 @@ void arena_render_overlay(scene *scene) { lang_get((player[1]->pilot->har_id) + 31)); } + // dont render total score in demo play + bool render_totalscore = !is_demoplay(scene->gs); // Render score stuff - chr_score_render(game_player_get_score(player[0])); + chr_score_render(game_player_get_score(player[0]), render_totalscore); - // Do not render player 2 score in 1 player mode - if(game_player_get_selectable(player[1])) { - chr_score_render(game_player_get_score(player[1])); - } + // Do not render player 2 total score in 1 player mode + chr_score_render(game_player_get_score(player[1]), render_totalscore && game_player_get_selectable(player[1])); // render ping, if player is networked if(player[0]->ctrl->type == CTRL_TYPE_NETWORK) { diff --git a/src/game/utils/score.c b/src/game/utils/score.c index 2595dfcfb..ea5c696cf 100644 --- a/src/game/utils/score.c +++ b/src/game/utils/score.c @@ -126,25 +126,26 @@ void chr_score_tick(chr_score *score) { } } -void chr_score_render(chr_score *score) { - // Render all texts in list to right spot - char tmp[50]; - score_format(score->score, tmp, 50); - +void chr_score_render(chr_score *score, bool render_total_points) { text_settings tconf_score; text_defaults(&tconf_score); tconf_score.font = FONT_SMALL; tconf_score.cforeground = TEXT_COLOR; tconf_score.shadow = TEXT_SHADOW_RIGHT | TEXT_SHADOW_BOTTOM; - if(score->direction == OBJECT_FACE_RIGHT) { - text_render(&tconf_score, TEXT_DEFAULT, score->x, score->y, 200, 6, tmp); + if(render_total_points) { + char tmp[50]; + score_format(score->score, tmp, 50); - } else { - int s2len = strlen(tmp) * font_small.w; - text_render(&tconf_score, TEXT_DEFAULT, score->x - s2len, score->y, 200, 6, tmp); + if(score->direction == OBJECT_FACE_RIGHT) { + text_render(&tconf_score, TEXT_DEFAULT, score->x, score->y, 200, 6, tmp); + } else { + int s2len = strlen(tmp) * font_small.w; + text_render(&tconf_score, TEXT_DEFAULT, score->x - s2len, score->y, 200, 6, tmp); + } } + // Render all texts in list to right spot iterator it; score_text *t; int lastage = -1; @@ -252,8 +253,11 @@ int chr_score_interrupt(chr_score *score, vec2i pos) { if(score->consecutive_hits > 3) { char *text = omf_calloc(64, 1); ret = 1; - int len = snprintf(text, 64, "%d consecutive hits ", score->consecutive_hits); - score_format(score->consecutive_hit_score, text + len, 64 - len); + int len = snprintf(text, 64, "%d consecutive hits", score->consecutive_hits); + if(score->consecutive_hit_score > 0) { + text[len++] = ' '; + score_format(score->consecutive_hit_score, text + len, 64 - len); + } // XXX hardcode the y coordinate for now chr_score_add(score, text, score->consecutive_hit_score, vec2i_create(pos.x, 130), 1.0f); } @@ -268,8 +272,11 @@ int chr_score_end_combo(chr_score *score, vec2i pos) { if(score->combo_hits > 1) { char *text = omf_calloc(64, 1); ret = 1; - int len = snprintf(text, 64, "%d hit combo ", score->combo_hits); - score_format(score->combo_hit_score * 4, text + len, 64 - len); + int len = snprintf(text, 64, "%d hit combo", score->combo_hits); + if(score->combo_hit_score > 0) { + text[len++] = ' '; + score_format(score->combo_hit_score * 4, text + len, 64 - len); + } // XXX hardcode the y coordinate for now chr_score_add(score, text, score->combo_hit_score * 4, vec2i_create(pos.x, 130), 1.0f); } diff --git a/src/game/utils/score.h b/src/game/utils/score.h index ae0f9b9ea..8e21ce15e 100644 --- a/src/game/utils/score.h +++ b/src/game/utils/score.h @@ -5,6 +5,7 @@ #include "game/protos/object.h" #include "utils/list.h" #include "video/surface.h" +#include #include #include @@ -43,7 +44,7 @@ void chr_score_set_pos(chr_score *score, int x, int y, int direction); unsigned int chr_score_get_num_texts(chr_score *score); void chr_score_free(chr_score *score); void chr_score_tick(chr_score *score); -void chr_score_render(chr_score *score); +void chr_score_render(chr_score *score, bool render_total_points); int chr_score_onscreen(chr_score *score); void chr_score_hit(chr_score *score, int points); From 2f50f915c955a06b65e3ca45c1dc8eba28d16566 Mon Sep 17 00:00:00 2001 From: Magnus Larsen Date: Tue, 5 Nov 2024 15:33:46 -0800 Subject: [PATCH 7/7] Award VITALITY points every round a human player defeats an AI --- src/game/scenes/arena.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/game/scenes/arena.c b/src/game/scenes/arena.c index 991b0faee..09d2370e6 100644 --- a/src/game/scenes/arena.c +++ b/src/game/scenes/arena.c @@ -554,9 +554,11 @@ void arena_har_defeat_hook(int player_id, scene *scene) { object_set_sprite_override(round_token, 1); } score->rounds++; + if(player_winner->ctrl->type != CTRL_TYPE_AI && player_loser->ctrl->type == CTRL_TYPE_AI) { + chr_score_victory(score, har_health_percent(winner_har)); + } if(score->rounds >= ceilf(local->rounds / 2.0f)) { har_set_ani(winner, ANIM_VICTORY, 0); - chr_score_victory(score, har_health_percent(winner_har)); winner_har->state = STATE_VICTORY; local->over = 1; if(is_singleplayer(gs)) {