From 6ba5efef9af79669e6f784d2b6b913ecac939e99 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sat, 15 Apr 2023 00:12:56 +0200 Subject: Always place first available piece for smoother animations. --- rules.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/rules.js b/rules.js index e46a1e5..278dded 100644 --- a/rules.js +++ b/rules.js @@ -499,6 +499,28 @@ function set_piece_space(p, s) { game.pieces[p] = s } +function piece_type(p) { + if (p >= first_piece[GOVT][TROOPS] && p <= last_piece[GOVT][TROOPS]) + return TROOPS + if (p >= first_piece[GOVT][POLICE] && p <= last_piece[GOVT][POLICE]) + return POLICE + if (p >= first_piece[GOVT][BASE] && p <= last_piece[GOVT][BASE]) + return BASE + if (p >= first_piece[FARC][GUERRILLA] && p <= last_piece[FARC][GUERRILLA]) + return GUERRILLA + if (p >= first_piece[FARC][BASE] && p <= last_piece[FARC][BASE]) + return BASE + if (p >= first_piece[AUC][GUERRILLA] && p <= last_piece[AUC][GUERRILLA]) + return GUERRILLA + if (p >= first_piece[AUC][BASE] && p <= last_piece[AUC][BASE]) + return BASE + if (p >= first_piece[CARTELS][GUERRILLA] && p <= last_piece[CARTELS][GUERRILLA]) + return GUERRILLA + if (p >= first_piece[CARTELS][BASE] && p <= last_piece[CARTELS][BASE]) + return BASE + throw "IMPOSSIBLE" +} + function piece_faction(p) { if (p >= first_piece[GOVT][TROOPS] && p <= last_piece[GOVT][TROOPS]) return GOVT @@ -1205,6 +1227,8 @@ function move_piece(p, s) { } function place_piece(p, s) { + if (piece_space(p) === AVAILABLE) + p = find_piece(AVAILABLE, piece_faction(p), piece_type(p)) log(`Placed ${piece_name(p)} in S${s}.`) set_underground(p) set_piece_space(p, s) -- cgit v1.2.3