Skip to content

Commit

Permalink
v1.0.24
Browse files Browse the repository at this point in the history
  • Loading branch information
ricott1 committed Nov 27, 2024
1 parent f3aaa22 commit 90bdaac
Show file tree
Hide file tree
Showing 40 changed files with 524 additions and 290 deletions.
18 changes: 9 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rebels"
version = "1.0.23"
version = "1.0.24"
edition = "2021"
authors = ["Alessandro Ricottone <[email protected]>"]
license = "GPL-3.0-or-later"
Expand Down
8 changes: 4 additions & 4 deletions assets/data/planets_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"revolution_period": 180,
"gravity": 2,
"asteroid_probability": 0.3,
"planet_type": 8,
"planet_type": 2,
"satellites": [],
"satellite_of": "71a43700-0000-0000-0001-000000000001",
"axis": [31.0, 69.0]
Expand All @@ -101,7 +101,7 @@
"revolution_period": 360,
"gravity": 3,
"asteroid_probability": 0.1,
"planet_type": 8,
"planet_type": 5,
"satellites": ["71a43700-0000-0000-0003-000000000003", "71a43700-0000-0000-0003-000000000004"],
"satellite_of": "71a43700-0000-0000-0001-000000000001",
"axis": [68.0, 24.0]
Expand All @@ -123,7 +123,7 @@
"revolution_period": 360,
"gravity": 3,
"asteroid_probability": 0.3,
"planet_type": 8,
"planet_type": 2,
"satellites": [],
"satellite_of": "71a43700-0000-0000-0002-000000000006",
"axis": [44.0, 44.0]
Expand All @@ -145,7 +145,7 @@
"revolution_period": 360,
"gravity": 2,
"asteroid_probability": 0.15,
"planet_type": 8,
"planet_type": 2,
"satellites": [],
"satellite_of": "71a43700-0000-0000-0002-000000000006",
"axis": [40.0, 46.0]
Expand Down
Binary file modified assets/planets/.DS_Store
Binary file not shown.
Binary file modified assets/planets/venom_zoomout.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/planets/venom_zoomout2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ impl App {
if self.state == AppState::Simulating {
info!("Starting world simulation...");
self.simulate_loaded_world(&mut tui).await;
info!("...Done");
}

if self.network_port.is_some()
Expand All @@ -243,6 +244,8 @@ impl App {
if let Err(e) = self.initialize_network_handler() {
error!("Could not initialize network handler: {}", e);
last_network_handler_init = now;
} else {
info!("...Done");
}
}

Expand All @@ -265,9 +268,6 @@ impl App {
},
TerminalEvent::Mouse(mouse_event) => {
self.handle_mouse_events(mouse_event)?;
// if let Err(e) = tui.draw(&mut self.ui, &self.world, self.audio_player.as_ref()).await {
// error!("Drawing error: {e}");
// }
},
TerminalEvent::Resize(w, h) => tui.resize((w, h))?,
TerminalEvent::Quit => self.quit()?,
Expand Down
8 changes: 6 additions & 2 deletions src/crossterm_event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl CrosstermEventHandler {
tokio::task::spawn(async move {
loop {
if event::poll(time_step).expect("no events available") {
match event::read().expect("unable to read event") {
let result = match event::read().expect("unable to read event") {
CrosstermEvent::Key(key) => {
if key.kind == KeyEventKind::Press {
sender.send(TerminalEvent::Key(key)).await
Expand All @@ -56,8 +56,12 @@ impl CrosstermEventHandler {
log::info!("Crossterm event not implemented");
Ok(())
}
};

if let Err(e) = result {
error!("Failed to send terminal event: {e}");
break;
}
.expect("failed to send terminal event")
}

let now = Tick::now();
Expand Down
7 changes: 6 additions & 1 deletion src/game_engine/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ pub enum Action {
PickAndRoll,
OffTheScreen,
Post,
Brawl,
Rebound,
CloseShot,
MediumShot,
LongShot,
Substitution,
Brawl,
}

impl Action {
Expand Down Expand Up @@ -115,6 +115,11 @@ impl Action {
}

pub trait EngineAction {
fn tactic_modifier(game: &Game, action: &Action) -> i16 {
let attack_tactic = game.home_team_in_game.tactic;
let defense_tactic = game.home_team_in_game.tactic;
attack_tactic.atk_roll_bonus(&defense_tactic, &action)
}
fn execute(input: &ActionOutput, game: &Game, rng: &mut ChaCha8Rng) -> Option<ActionOutput>;
fn sample(rng: &mut ChaCha8Rng, weights: [u8; 5]) -> Option<usize> {
Some(WeightedIndex::new(&weights).ok()?.sample(rng))
Expand Down
6 changes: 4 additions & 2 deletions src/game_engine/brawl.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{
action::{ActionOutput, EngineAction},
action::{Action, ActionOutput, EngineAction},
game::Game,
types::GameStats,
};
Expand Down Expand Up @@ -84,7 +84,9 @@ impl EngineAction for Brawl {
def_result += defender.reputation.value();
}

let description = match atk_result as i16 - def_result as i16 {
let description = match atk_result as i16 - def_result as i16
+ Self::tactic_modifier(game, &Action::Brawl)
{
x if x > 0 => {
defender_update.extra_morale += MoraleModifier::SEVERE_MALUS;
attacker_update.extra_morale += MoraleModifier::SEVERE_BONUS;
Expand Down
14 changes: 14 additions & 0 deletions src/game_engine/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,20 @@ impl<'game> Game {
}
}

pub fn attacking_team(&self) -> &TeamInGame {
match self.possession {
Possession::Home => &self.home_team_in_game,
Possession::Away => &self.away_team_in_game,
}
}

pub fn defending_team(&self) -> &TeamInGame {
match self.possession {
Possession::Home => &self.away_team_in_game,
Possession::Away => &self.home_team_in_game,
}
}

fn get_rng_seed(&self) -> [u8; 32] {
let mut seed = [0; 32];
seed[0..16].copy_from_slice(self.id.as_bytes());
Expand Down
4 changes: 2 additions & 2 deletions src/game_engine/isolation.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{
action::{ActionOutput, ActionSituation, Advantage, EngineAction},
action::{Action, ActionOutput, ActionSituation, Advantage, EngineAction},
constants::*,
game::Game,
types::{GameStats, Possession},
Expand Down Expand Up @@ -69,7 +69,7 @@ impl EngineAction for Isolation {
+ defender.defense.perimeter_defense.value()
+ defender.athletics.quickness.value();

let mut result = match atk_result as i16 - def_result as i16 {
let mut result = match atk_result as i16 - def_result as i16 + Self::tactic_modifier(game, &Action::Isolation) {
x if x > ADV_ATTACK_LIMIT => ActionOutput {
possession: input.possession,
advantage: Advantage::Attack,
Expand Down
9 changes: 4 additions & 5 deletions src/game_engine/off_the_screen.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{
action::{ActionOutput, ActionSituation, Advantage, EngineAction},
action::{Action, ActionOutput, ActionSituation, Advantage, EngineAction},
constants::*,
game::Game,
types::{GameStats, GameStatsMap},
Expand All @@ -25,13 +25,12 @@ impl EngineAction for OffTheScreen {
_ => input.attackers[0],
};
let target_idx = match input.attackers.len() {
0 => Self::sample(rng, [1, 2, 3, 3, 2])?,
1 => {
2 => input.attackers[1],
_ => {
let mut weights = [1, 2, 3, 3, 2];
weights[play_idx] = 0;
Self::sample(rng, weights)?
}
_ => input.attackers[1],
};

let playmaker = attacking_players[play_idx];
Expand Down Expand Up @@ -59,7 +58,7 @@ impl EngineAction for OffTheScreen {
+ target_defender.defense.perimeter_defense.value()
+ target_defender.athletics.quickness.value();

let mut result = match atk_result as i16 - def_result as i16 {
let mut result = match atk_result as i16 - def_result as i16 + Self::tactic_modifier(game, &Action::OffTheScreen) {
x if x > ADV_ATTACK_LIMIT => ActionOutput {
possession: input.possession,
advantage: Advantage::Attack,
Expand Down
6 changes: 3 additions & 3 deletions src/game_engine/pick_and_roll.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{
action::{ActionOutput, ActionSituation, Advantage, EngineAction},
action::{Action, ActionOutput, ActionSituation, Advantage, EngineAction},
constants::*,
game::Game,
types::{GameStats, GameStatsMap},
Expand Down Expand Up @@ -60,7 +60,7 @@ impl EngineAction for PickAndRoll {
+ playmaker_defender.defense.perimeter_defense.value()
+ playmaker_defender.mental.vision.value();

result = match atk_result as i16 - def_result as i16 {
result = match atk_result as i16 - def_result as i16 + Self::tactic_modifier(game, &Action::PickAndRoll) {
x if x > ADV_ATTACK_LIMIT => ActionOutput {
possession: input.possession,
advantage: Advantage::Attack,
Expand Down Expand Up @@ -238,7 +238,7 @@ impl EngineAction for PickAndRoll {
+ playmaker_defender.defense.perimeter_defense.value()
+ target_defender.athletics.quickness.value();

result = match atk_result as i16 - def_result as i16 {
result = match atk_result as i16 - def_result as i16 + Self::tactic_modifier(game, &Action::PickAndRoll){
x if x > ADV_ATTACK_LIMIT => ActionOutput {
possession: input.possession,
advantage: Advantage::Attack,
Expand Down
8 changes: 5 additions & 3 deletions src/game_engine/post.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{
action::{ActionOutput, ActionSituation, Advantage, EngineAction},
action::{Action, ActionOutput, ActionSituation, Advantage, EngineAction},
constants::*,
game::Game,
types::GameStats,
Expand Down Expand Up @@ -48,7 +48,9 @@ impl EngineAction for Post {
+ defender.defense.interior_defense.value()
+ defender.athletics.strength.value();

let mut result = match atk_result as i16 - def_result as i16 {
let mut result = match atk_result as i16 - def_result as i16
+ Self::tactic_modifier(game, &Action::Post)
{
x if x > ADV_ATTACK_LIMIT => ActionOutput {
possession: input.possession,
advantage: Advantage::Attack,
Expand All @@ -62,7 +64,7 @@ impl EngineAction for Post {
defender.info.shortened_name()
),
format!(
"{} used {}'s defense to create space and drive to the hoop.",
"{} beats {}'s defense to create space and drive to the hoop.",
poster.info.shortened_name(),
defender.info.shortened_name()
),
Expand Down
10 changes: 7 additions & 3 deletions src/game_engine/rebound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ use super::{
types::GameStats,
};
use crate::{
game_engine::{action::Advantage, constants::*, types::GameStatsMap},
game_engine::{
action::{Action, Advantage},
constants::*,
types::GameStatsMap,
},
world::constants::TirednessCost,
};
use rand::{seq::SliceRandom, Rng};
Expand Down Expand Up @@ -99,7 +103,7 @@ impl EngineAction for Rebound {
defence_result,
MIN_REBOUND_VALUE
);
let result = match attack_result as i16 - defence_result as i16 {
let result = match attack_result as i16 - defence_result as i16 + Self::tactic_modifier(game, &Action::Rebound){
x if x > ADV_ATTACK_LIMIT
|| (x > 0
&& attack_result >= MIN_REBOUND_VALUE
Expand Down Expand Up @@ -266,7 +270,7 @@ impl EngineAction for Rebound {
}
_ => ActionOutput {
possession: !input.possession,
situation: ActionSituation::BallInBackcourt,
situation: ActionSituation::AfterDefensiveRebound,
description: [
"Nobody got the rebound, ball goes to defence.",
"Neither team secures the board, and the ball rolls to the defensive side.",
Expand Down
Loading

0 comments on commit 90bdaac

Please sign in to comment.