Fix emulator compilation and crash, and implement Monopoly payment modal

This commit is contained in:
Adolfo Reyna
2026-02-06 23:13:32 -05:00
parent 75e17fb26b
commit 64f61759d7
10 changed files with 309 additions and 66 deletions

View File

@@ -23,6 +23,7 @@ extern "C" {
#include "ChanceModalGame.h"
#include "CommunityChestModalGame.h"
#include "TurnModalGame.h"
#include "PaymentModalGame.h"
#include "ModalButtonHelper.h"
#include "sprites.h"
#include "MonopolyBoardRenderer.h"
@@ -55,6 +56,7 @@ void MonopolyGame::init() {
srand(time(NULL));
shuffle_chance_deck();
shuffle_community_deck();
//renderer->set_font(&font_tama_mini02_obj);
if (active_modal) { delete active_modal; active_modal = nullptr; }
active_modal = new TurnModalGame(width, height, renderer, gui, input_manager, &players[current_player_idx]);
// TODO: Reset all board state, property ownership, etc.
@@ -113,6 +115,16 @@ bool MonopolyGame::update(const InputEvent& event) {
ChanceModalGame* chance_modal = (active_modal->get_type() == Game::Type::MONOPOLY_CHANCE) ? static_cast<ChanceModalGame*>(active_modal) : nullptr;
CommunityChestModalGame* community_modal = (active_modal->get_type() == Game::Type::MONOPOLY_COMMUNITY_CHEST) ? static_cast<CommunityChestModalGame*>(active_modal) : nullptr;
TurnModalGame* turn_modal = (active_modal->get_type() == Game::Type::MONOPOLY_TURN) ? static_cast<TurnModalGame*>(active_modal) : nullptr;
PaymentModalGame* pay_modal = (active_modal->get_type() == Game::Type::MONOPOLY_PAYMENT) ? static_cast<PaymentModalGame*>(active_modal) : nullptr;
if (pay_modal && pay_modal->is_dismissed()) {
delete active_modal;
active_modal = nullptr;
selected_action = -1;
needs_redraw = true;
ModalButtonHelper::set_monopoly_regions(input_manager, width, height);
return needs_redraw;
}
if (dice_modal && dice_modal->is_dismissed()) {
delete active_modal;
@@ -165,7 +177,8 @@ bool MonopolyGame::update(const InputEvent& event) {
p->balance += card->value;
break;
case CHANCE_SPEND:
p->balance -= card->value;
active_modal = new PaymentModalGame(width, height, renderer, gui, input_manager, p, nullptr, card->value, "CHANCE CARD");
if (active_modal) active_modal->init();
break;
case CHANCE_ADVANCE: {
int target = card->value;
@@ -211,12 +224,12 @@ bool MonopolyGame::update(const InputEvent& event) {
break;
}
delete active_modal;
active_modal = nullptr;
needs_redraw = true;
ModalButtonHelper::set_monopoly_regions(input_manager, width, height);
if (position_changed) {
if (active_modal) {
active_modal->init();
} else if (position_changed) {
// If we moved, check if we landed on a property
const BoardTile* landed = &MONOPOLY_BOARD[p->position];
if (landed->type == TILE_PROPERTY || landed->type == TILE_RAILROAD || landed->type == TILE_UTILITY) {
@@ -250,7 +263,8 @@ bool MonopolyGame::update(const InputEvent& event) {
p->balance += card->value;
break;
case COMMUNITY_SPEND:
p->balance -= card->value;
active_modal = new PaymentModalGame(width, height, renderer, gui, input_manager, p, nullptr, card->value, "COMMUNITY CHEST");
if (active_modal) active_modal->init();
break;
case COMMUNITY_ADVANCE:
p->position = card->value;
@@ -277,12 +291,12 @@ bool MonopolyGame::update(const InputEvent& event) {
break;
}
delete active_modal;
active_modal = nullptr;
needs_redraw = true;
ModalButtonHelper::set_monopoly_regions(input_manager, width, height);
if (position_changed) {
if (active_modal) {
active_modal->init();
} else if (position_changed) {
const BoardTile* landed = &MONOPOLY_BOARD[p->position];
if (landed->type == TILE_PROPERTY || landed->type == TILE_RAILROAD || landed->type == TILE_UTILITY) {
bool is_owned = false;
@@ -304,28 +318,30 @@ bool MonopolyGame::update(const InputEvent& event) {
}
}
} else if (prop_modal && prop_modal->is_dismissed()) {
if (prop_modal->wants_to_buy()) {
bool wants_buy = prop_modal->wants_to_buy();
bool wants_rent = prop_modal->wants_to_pay_rent();
int owner_id_from_modal = prop_modal->get_owner_id();
delete active_modal;
active_modal = nullptr;
if (wants_buy) {
const BoardTile* tile = &MONOPOLY_BOARD[p->position];
if (p->balance >= tile->cost) {
p->balance -= tile->cost;
active_modal = new PaymentModalGame(width, height, renderer, gui, input_manager, p, nullptr, tile->cost, "BUY PROPERTY");
p->properties_owned[p->property_count++] = p->position;
}
} else if (prop_modal->wants_to_pay_rent()) {
} else if (wants_rent) {
const BoardTile* tile = &MONOPOLY_BOARD[p->position];
int rent = 0;
if (tile->type == TILE_PROPERTY) {
// Logic for rent: If owner has all properties of group, rent is doubled (base only)
// For now, let's just use rent[0] as requested, but we should probably eventually
// check for houses. Let's stick to rent[0] to match the modal's display.
rent = tile->rent[0];
}
else if (tile->type == TILE_RAILROAD) {
// Utility logic for Railroads: 1:25, 2:50, 3:100, 4:200
int owner_id = prop_modal->get_owner_id();
int rr_count = 0;
if (owner_id != -1) {
for (int i = 0; i < players[owner_id].property_count; ++i) {
if (MONOPOLY_BOARD[players[owner_id].properties_owned[i]].type == TILE_RAILROAD) {
if (owner_id_from_modal != -1) {
for (int i = 0; i < players[owner_id_from_modal].property_count; ++i) {
if (MONOPOLY_BOARD[players[owner_id_from_modal].properties_owned[i]].type == TILE_RAILROAD) {
rr_count++;
}
}
@@ -334,18 +350,14 @@ bool MonopolyGame::update(const InputEvent& event) {
else if (rr_count == 2) rent = 50;
else if (rr_count == 3) rent = 100;
else if (rr_count == 4) rent = 200;
else rent = 25; // Fallback
else rent = 25;
}
else if (tile->type == TILE_UTILITY) {
// Utility: 4x dice if 1 owned, 10x if both.
// Since we don't have the dice roll here, let's use a fixed 40 for now
// or calculate it from last_dice1 + last_dice2.
int total_dice = last_dice1 + last_dice2;
int owner_id = prop_modal->get_owner_id();
int utility_count = 0;
if (owner_id != -1) {
for (int i = 0; i < players[owner_id].property_count; ++i) {
if (MONOPOLY_BOARD[players[owner_id].properties_owned[i]].type == TILE_UTILITY) {
if (owner_id_from_modal != -1) {
for (int i = 0; i < players[owner_id_from_modal].property_count; ++i) {
if (MONOPOLY_BOARD[players[owner_id_from_modal].properties_owned[i]].type == TILE_UTILITY) {
utility_count++;
}
}
@@ -359,20 +371,17 @@ bool MonopolyGame::update(const InputEvent& event) {
rent *= rent_multiplier;
int o_id = prop_modal->get_owner_id();
if (o_id != -1 && (int)current_player_idx != o_id) {
p->balance -= rent;
players[o_id].balance += rent;
if (owner_id_from_modal != -1 && (int)current_player_idx != owner_id_from_modal) {
active_modal = new PaymentModalGame(width, height, renderer, gui, input_manager, p, &players[owner_id_from_modal], rent, "RENT");
}
}
// Reset multipliers
rent_multiplier = 1;
force_utility_10x = false;
delete active_modal;
active_modal = nullptr;
needs_redraw = true;
ModalButtonHelper::set_monopoly_regions(input_manager, width, height);
if (active_modal) active_modal->init();
} else if (board_modal && board_modal->is_dismissed()) {
delete active_modal;
active_modal = nullptr;
@@ -400,7 +409,8 @@ bool MonopolyGame::update(const InputEvent& event) {
if (selected_action == -1) return false;
if (p->is_in_jail && !has_rolled && selected_action == 1) {
p->balance -= 50;
active_modal = new PaymentModalGame(width, height, renderer, gui, input_manager, p, nullptr, 50, "JAIL BAIL");
if (active_modal) active_modal->init();
p->is_in_jail = false;
p->jail_turns = 0;
selected_action = -1;
@@ -423,7 +433,9 @@ roll_dice_logic:
} else {
p->jail_turns++;
if (p->jail_turns >= 3) {
p->balance -= 50; p->is_in_jail = false; p->jail_turns = 0;
active_modal = new PaymentModalGame(width, height, renderer, gui, input_manager, p, nullptr, 50, "JAIL BAIL (FORCED)");
if (active_modal) active_modal->init();
p->is_in_jail = false; p->jail_turns = 0;
} else {
has_rolled = true;
last_dice1 = d1; last_dice2 = d2;
@@ -468,7 +480,8 @@ roll_dice_logic:
current_community_idx = (current_community_idx + 1) % COMMUNITY_DECK_SIZE;
if (current_community_idx == 0) shuffle_community_deck();
} else if (lnd->type == TILE_TAX) {
p->balance -= lnd->cost;
active_modal = new PaymentModalGame(width, height, renderer, gui, input_manager, p, nullptr, lnd->cost, "TAXES");
if (active_modal) active_modal->init();
}
needs_redraw = true;
} else {