Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show Newsroom and VS in DEMO mode and Score fixes #761

Merged
merged 7 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/console/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions src/controller/ai_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions src/game/common_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 39 additions & 3 deletions src/game/game_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,20 @@ 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) {
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;
}
Expand Down Expand Up @@ -882,11 +896,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
Expand Down Expand Up @@ -1022,3 +1036,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);
}
6 changes: 6 additions & 0 deletions src/game/game_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/game/gui/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,15 @@ 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));
menu_transparent_bg_create(m->help_bg1, m->help_w + 16, m->help_w / 8);
}
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);
Expand Down
52 changes: 27 additions & 25 deletions src/game/gui/menu_background.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 11 additions & 2 deletions src/game/gui/menu_background.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
88 changes: 21 additions & 67 deletions src/game/scenes/arena.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -248,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(sc)) {
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)) {
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)));
Expand Down Expand Up @@ -312,7 +269,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);
Expand Down Expand Up @@ -396,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));
}

Expand Down Expand Up @@ -563,7 +521,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(scene)) {
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 {
Expand Down Expand Up @@ -593,12 +554,14 @@ 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(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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1085,10 +1048,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) && e->key.keysym.sym == SDLK_ESCAPE) {
game_state_set_next(scene->gs, SCENE_MENU);
}
return 0;
}

Expand Down Expand Up @@ -1160,13 +1119,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) {
Expand Down Expand Up @@ -1232,11 +1191,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:
Expand Down Expand Up @@ -1429,7 +1383,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);
Expand Down Expand Up @@ -1464,11 +1418,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]));
}
Expand Down
2 changes: 1 addition & 1 deletion src/game/scenes/mainmenu/menu_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading
Loading