fix rent calculation
This commit is contained in:
@@ -59,20 +59,92 @@ bool MonopolyGame::update(const InputEvent& event) {
|
||||
bool modal_redraw = active_modal->update(event);
|
||||
if (modal_redraw) needs_redraw = true;
|
||||
|
||||
// Check for specific modal types to handle their results
|
||||
auto dice_modal = dynamic_cast<DiceModalGame*>(active_modal);
|
||||
auto prop_modal = dynamic_cast<PropertyModalGame*>(active_modal);
|
||||
auto board_modal = dynamic_cast<BoardModalGame*>(active_modal);
|
||||
// Check for specific modal types to handle their results using custom get_type()
|
||||
DiceModalGame* dice_modal = (active_modal->get_type() == Game::Type::MONOPOLY_DICE) ? static_cast<DiceModalGame*>(active_modal) : nullptr;
|
||||
PropertyModalGame* prop_modal = (active_modal->get_type() == Game::Type::MONOPOLY_PROPERTY) ? static_cast<PropertyModalGame*>(active_modal) : nullptr;
|
||||
BoardModalGame* board_modal = (active_modal->get_type() == Game::Type::MONOPOLY_BOARD) ? static_cast<BoardModalGame*>(active_modal) : nullptr;
|
||||
|
||||
if (dice_modal && dice_modal->is_dismissed()) {
|
||||
delete active_modal;
|
||||
active_modal = nullptr;
|
||||
needs_redraw = true;
|
||||
} else if (prop_modal && prop_modal->is_dismissed()) {
|
||||
|
||||
// Immediately check if we need to show a property modal
|
||||
if (modal_property_index >= 0) {
|
||||
bool is_owned = false;
|
||||
const char* owner_name = nullptr;
|
||||
int owner_id = -1;
|
||||
for (int i = 0; i < players_count; ++i) {
|
||||
for (int j = 0; j < players[i].property_count; ++j) {
|
||||
if (players[i].properties_owned[j] == modal_property_index) {
|
||||
is_owned = true;
|
||||
owner_name = players[i].name;
|
||||
owner_id = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (is_owned) break;
|
||||
}
|
||||
bool can_afford = (p->balance >= MONOPOLY_BOARD[modal_property_index].cost);
|
||||
active_modal = new PropertyModalGame(width, height, renderer, gui, input_manager, &MONOPOLY_BOARD[modal_property_index], is_owned, owner_name, owner_id, can_afford, players, players_count);
|
||||
modal_property_index = -1;
|
||||
}
|
||||
return needs_redraw;
|
||||
} else if (prop_modal && prop_modal->is_dismissed()) {
|
||||
if (prop_modal->wants_to_buy()) {
|
||||
const BoardTile* tile = &MONOPOLY_BOARD[p->position];
|
||||
p->balance -= tile->cost;
|
||||
p->properties_owned[p->property_count++] = p->position;
|
||||
if (p->balance >= tile->cost) {
|
||||
p->balance -= tile->cost;
|
||||
p->properties_owned[p->property_count++] = p->position;
|
||||
}
|
||||
} else if (prop_modal->wants_to_pay_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) {
|
||||
rr_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rr_count == 1) rent = 25;
|
||||
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 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) {
|
||||
utility_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
rent = (utility_count == 2) ? (total_dice * 10) : (total_dice * 4);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
delete active_modal;
|
||||
active_modal = nullptr;
|
||||
@@ -135,27 +207,6 @@ bool MonopolyGame::update(const InputEvent& event) {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// If dice modal was just dismissed and a property modal is queued, show it
|
||||
if (!active_modal && modal_property_index >= 0) {
|
||||
// Evaluate ownership and affordability
|
||||
bool is_owned = false;
|
||||
const char* owner_name = nullptr;
|
||||
for (int i = 0; i < players_count; ++i) {
|
||||
for (int j = 0; j < players[i].property_count; ++j) {
|
||||
if (players[i].properties_owned[j] == modal_property_index) {
|
||||
is_owned = true;
|
||||
owner_name = players[i].name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (is_owned) break;
|
||||
}
|
||||
bool can_afford = (p->balance >= MONOPOLY_BOARD[modal_property_index].cost);
|
||||
|
||||
active_modal = new PropertyModalGame(width, height, renderer, gui, input_manager, &MONOPOLY_BOARD[modal_property_index], is_owned, owner_name, can_afford, players, players_count);
|
||||
modal_property_index = -1;
|
||||
needs_redraw = true;
|
||||
}
|
||||
return needs_redraw;
|
||||
}
|
||||
|
||||
@@ -169,8 +220,11 @@ void MonopolyGame::draw() {
|
||||
|
||||
renderer->clear_buffer();
|
||||
|
||||
Player* p = &players[current_player_idx];
|
||||
const BoardTile* tile = &MONOPOLY_BOARD[p->position];
|
||||
|
||||
// --- Draw Board Perimeter ---
|
||||
MonopolyBoardRenderer::draw_board_perimeter(renderer, width, height, players, players_count);
|
||||
MonopolyBoardRenderer::draw_board_perimeter(renderer, width, height, players, players_count, p->position);
|
||||
|
||||
// --- Inner Dashboard (Center Area) ---
|
||||
int cw = width / 7;
|
||||
@@ -178,17 +232,14 @@ void MonopolyGame::draw() {
|
||||
int ix = cw + 2, iy = ch + 2;
|
||||
int iw = width - 2 * cw - 4, ih = height - 2 * ch - 4;
|
||||
|
||||
Player* p = &players[current_player_idx];
|
||||
const BoardTile* tile = &MONOPOLY_BOARD[p->position];
|
||||
|
||||
// Stats Window in center
|
||||
char buf[128];
|
||||
renderer->draw_string_scaled(ix + 5, iy + 5, "Monopoly", 2);
|
||||
|
||||
int content_y = iy + 25;
|
||||
snprintf(buf, sizeof(buf), "TURN: %s", p->name);
|
||||
renderer->draw_string_scaled(ix + 5, content_y, buf, 1);
|
||||
content_y += 12;
|
||||
snprintf(buf, sizeof(buf), "%s", p->name);
|
||||
renderer->draw_string_scaled(ix + 5, content_y, buf, 2);
|
||||
content_y += 20;
|
||||
|
||||
snprintf(buf, sizeof(buf), "BAL: $%d", p->balance);
|
||||
renderer->draw_string_scaled(ix + 5, content_y, buf, 1);
|
||||
|
||||
Reference in New Issue
Block a user