Skip to content

Commit

Permalink
v1.0.25
Browse files Browse the repository at this point in the history
  • Loading branch information
ricott1 committed Nov 29, 2024
1 parent 90bdaac commit 6ddfe30
Show file tree
Hide file tree
Showing 24 changed files with 692 additions and 531 deletions.
160 changes: 80 additions & 80 deletions Cargo.lock

Large diffs are not rendered by default.

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.24"
version = "1.0.25"
edition = "2021"
authors = ["Alessandro Ricottone <[email protected]>"]
license = "GPL-3.0-or-later"
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ You need to have the [rust toolchain](https://www.rust-lang.org/tools/install).
pacman -S rebels-in-the-sky
```

#### MacPorts

`rebels-in-the-sky` can be installed from the [available ports](https://ports.macports.org/port/rebels-in-the-sky/):

```sh
sudo port install rebels-in-the-sky
```

## Run

This game runs as a terminal application, meaning that you just need to run the executable from your terminal with
Expand Down
4 changes: 2 additions & 2 deletions assets/data/planets_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@
"resources": {
"1": 1,
"2": 7,
"3": 16
"3": 12
},
"filename": "gas",
"rotation_period": 9,
Expand Down Expand Up @@ -344,7 +344,7 @@
},
"resources": {
"2": 2,
"3": 18,
"3": 14,
"4": 2
},
"filename": "deimos",
Expand Down
2 changes: 1 addition & 1 deletion src/game_engine/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ 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)
attack_tactic.attack_roll_bonus(&action) - defense_tactic.defense_roll_bonus(&action)
}
fn execute(input: &ActionOutput, game: &Game, rng: &mut ChaCha8Rng) -> Option<ActionOutput>;
fn sample(rng: &mut ChaCha8Rng, weights: [u8; 5]) -> Option<usize> {
Expand Down
99 changes: 90 additions & 9 deletions src/game_engine/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
},
};
use itertools::Itertools;
use rand::{Rng, SeedableRng};
use rand::{seq::SliceRandom, Rng, SeedableRng};
use rand_chacha::ChaCha8Rng;
use serde::{Deserialize, Serialize};
use std::fmt::Debug;
Expand Down Expand Up @@ -125,6 +125,10 @@ pub struct Game {
}

impl<'game> Game {
pub fn is_network(&self) -> bool {
self.home_team_in_game.peer_id.is_some() && self.away_team_in_game.peer_id.is_some()
}

pub fn new(
id: GameId,
home_team_in_game: TeamInGame,
Expand Down Expand Up @@ -188,14 +192,91 @@ impl<'game> Game {
* (1.0 + bonus_attendance);
game.attendance = attendance as u32;
let mut default_output = ActionOutput::default();
default_output.description = format!(
"{} vs {}. Game is about to start here on {}! There are {} {}people in the stadium.",
home_name,
away_name,
planet.name,
game.attendance,
if game.attendance == 69 { "(nice) " } else { "" }
);

let opening_text = [
format!(
"{} vs {}. The intergalactic showdown is kicking off on {}! {} fans have packed the arena{}.",
home_name,
away_name,
planet.name,
game.attendance,
if game.attendance == 69 { " (nice)" } else { "" }
),
format!(
"It's {} against {}! We're live here on {} where {} spectators{} are buzzing with excitement.",
home_name,
away_name,
planet.name,
game.attendance,
if game.attendance == 69 { " (nice)" } else { "" }
),
format!(
"The stage is set on {} for {} vs {}. A crowd of {}{} fans is ready for the action to unfold!",
planet.name,
home_name,
away_name,
game.attendance,
if game.attendance == 69 { " (nice)" } else { "" }
),
format!(
"{} and {} clash today on {}! An electric atmosphere fills the stadium with {} fans{} watching closely.",
home_name,
away_name,
planet.name,
game.attendance,
if game.attendance == 69 { " (nice)" } else { "" }
),
format!(
"Welcome to {} for an epic battle: {} vs {}. The crowd of {} fans{} is ready to witness greatness!",
planet.name,
home_name,
away_name,
game.attendance,
if game.attendance == 69 { " (nice)" } else { "" }
),
format!(
"Tonight on {}, it's {} taking on {}. With {} passionate fans{} in attendance, the game is about to ignite!",
planet.name,
home_name,
away_name,
game.attendance,
if game.attendance == 69 { " (nice)" } else { "" }
),
format!(
"Game night on {}! {} faces off against {} before {} eager fans{} under the starry skies.",
planet.name,
home_name,
away_name,
game.attendance,
if game.attendance == 69 { " (nice)" } else { "" }
),
format!(
"The rivalry continues on {}: {} vs {}. The crowd of {} fans{} is fired up for this clash!",
planet.name,
home_name,
away_name,
game.attendance,
if game.attendance == 69 { " (nice)" } else { "" }
),
format!(
"All eyes are on {} as {} battles {}. An audience of {}{} is here to cheer for their team!",
planet.name,
home_name,
away_name,
game.attendance,
if game.attendance == 69 { " (nice)" } else { "" }
),
format!(
"Here on {}, it's {} vs {}. A roaring crowd of {} fans{} awaits the start of the showdown!",
planet.name,
home_name,
away_name,
game.attendance,
if game.attendance == 69 { " (nice)" } else { "" }
),
].choose(&mut rng).expect("There should be one option").clone();

default_output.description = opening_text;
default_output.random_seed = seed;
game.action_results.push(default_output);
game
Expand Down
46 changes: 23 additions & 23 deletions src/game_engine/tactic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ impl Tactic {
}
}

pub fn atk_roll_bonus(&self, defense_tactic: &Tactic, action: &Action) -> i16 {
let defense_bonus = match defense_tactic {
pub fn attack_roll_bonus(&self, action: &Action) -> i16 {
match self {
Self::Balanced => 0,
Self::BigPirates => match action {
Action::Isolation => -2,
Expand All @@ -94,26 +94,28 @@ impl Tactic {
_ => 0,
},
Self::Arrembaggio => match action {
Action::Isolation => 0,
Action::Isolation => 2,
Action::PickAndRoll => -2,
Action::OffTheScreen => 2,
Action::OffTheScreen => 0,
Action::Post => -2,
Action::Brawl => 2,
Action::Brawl => 4,
Action::Rebound => -2,
_ => 0,
},
Self::Shooters => match action {
Action::Isolation => 2,
Action::PickAndRoll => 0,
Action::OffTheScreen => 2,
Action::Isolation => 0,
Action::PickAndRoll => 2,
Action::OffTheScreen => 4,
Action::Post => -2,
Action::Brawl => -2,
Action::Rebound => 0,
Action::Brawl => 0,
Action::Rebound => -4,
_ => 0,
},
};
}
}

let attack_bonus = match self {
pub fn defense_roll_bonus(&self, action: &Action) -> i16 {
match self {
Self::Balanced => 0,
Self::BigPirates => match action {
Action::Isolation => -2,
Expand All @@ -125,25 +127,23 @@ impl Tactic {
_ => 0,
},
Self::Arrembaggio => match action {
Action::Isolation => 2,
Action::Isolation => 0,
Action::PickAndRoll => -2,
Action::OffTheScreen => 0,
Action::OffTheScreen => 2,
Action::Post => -2,
Action::Brawl => 4,
Action::Brawl => 2,
Action::Rebound => -2,
_ => 0,
},
Self::Shooters => match action {
Action::Isolation => 0,
Action::PickAndRoll => 2,
Action::OffTheScreen => 4,
Action::Isolation => 2,
Action::PickAndRoll => 0,
Action::OffTheScreen => 2,
Action::Post => -2,
Action::Brawl => 0,
Action::Rebound => -4,
Action::Brawl => -2,
Action::Rebound => 0,
_ => 0,
},
};

attack_bonus - defense_bonus
}
}
}
4 changes: 3 additions & 1 deletion src/network/network_callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,9 @@ impl NetworkCallback {
let own_team = app.world.get_own_team_mut()?;
own_team.add_received_trade(trade.clone());

return Ok(Some("Trade received.\nCheck the swarm panel".to_string()));
return Ok(Some(
"Trade offer received.\nCheck the swarm panel".to_string(),
));
}
NetworkRequestState::SynAck => {
if trade.target_peer_id == *self_peer_id {
Expand Down
2 changes: 1 addition & 1 deletion src/space_adventure/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::ui::UI_SCREEN_SIZE;
pub(crate) const FRICTION_COEFF: f32 = 0.1;
pub(crate) const THRUST_MOD: f32 = 1.5;
pub(crate) const FUEL_CONSUMPTION_MOD: f32 = 215_000.0;
pub(crate) const MAX_SPACESHIP_SPEED_MOD: f32 = 0.135;
pub(crate) const MAX_SPACESHIP_SPEED_MOD: f32 = 0.125;

pub(crate) const ASTEROID_GENERATION_PROBABILITY: f64 = 0.05;
pub(crate) const DIFFICULTY_FOR_ASTEROID_PLANET_GENERATION: usize = 60;
Expand Down
12 changes: 5 additions & 7 deletions src/space_adventure/space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl SpaceAdventureState {

#[derive(Debug, Display, Clone, Copy, PartialEq)]
enum AsteroidPlanetState {
NotSpawned { asteroid_planet_probability: f64 },
NotSpawned { should_spawn_asteroid: bool },
Spawned { image_number: usize },
Landed { image_number: usize },
}
Expand Down Expand Up @@ -252,7 +252,7 @@ impl SpaceAdventure {
}
}

pub fn new(asteroid_planet_probability: f64) -> AppResult<Self> {
pub fn new(should_spawn_asteroid: bool) -> AppResult<Self> {
let bg = TRAVELLING_BACKGROUND.clone();
let mut background = RgbaImage::new(bg.width() * 2, bg.height() * 3);
background.copy_non_trasparent_from(&bg, 0, 0)?;
Expand Down Expand Up @@ -288,7 +288,7 @@ impl SpaceAdventure {
id_to_layer: HashMap::new(),
player_id: None,
asteroid_planet_state: AsteroidPlanetState::NotSpawned {
asteroid_planet_probability,
should_spawn_asteroid,
},
enemy_ship_spawned: false,
})
Expand All @@ -297,14 +297,12 @@ impl SpaceAdventure {
pub fn with_player(
mut self,
spaceship: &Spaceship,
team_speed_bonus: f32,
resources: ResourceMap,
fuel: u32,
) -> AppResult<Self> {
let collector_id = self.insert_entity(Box::new(CollectorEntity::new()));
let id = self.insert_entity(Box::new(SpaceshipEntity::from_spaceship(
spaceship,
team_speed_bonus,
resources,
fuel,
collector_id,
Expand Down Expand Up @@ -462,9 +460,9 @@ impl SpaceAdventure {
if difficulty_level > DIFFICULTY_FOR_ASTEROID_PLANET_GENERATION {
match self.asteroid_planet_state {
AsteroidPlanetState::NotSpawned {
asteroid_planet_probability,
should_spawn_asteroid,
} => {
if asteroid_planet_probability > 0.0 {
if should_spawn_asteroid {
let asteroid = AsteroidEntity::planet();
let id = self.insert_entity(Box::new(asteroid));
self.asteroid_planet_state = AsteroidPlanetState::Spawned {
Expand Down
5 changes: 2 additions & 3 deletions src/space_adventure/spaceship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub struct SpaceshipEntity {
is_player: bool,
base_spaceship: Spaceship,
resources: ResourceMap,
used_storage_capacity: u32,
used_storage_capacity: u32, // Not necessary, we keep it to avoid recalculating them every time.
storage_capacity: u32,
fuel_capacity: u32,
previous_position: Vec2,
Expand Down Expand Up @@ -567,7 +567,6 @@ impl SpaceshipEntity {

pub fn from_spaceship(
spaceship: &Spaceship,
team_speed_bonus: f32,
resources: ResourceMap,
fuel: u32,
collector_id: usize,
Expand Down Expand Up @@ -638,7 +637,7 @@ impl SpaceshipEntity {
hit_boxes,
current_durability: spaceship.current_durability() as f32,
durability: spaceship.durability() as f32,
base_thrust: spaceship.speed(0) * THRUST_MOD * team_speed_bonus,
base_thrust: spaceship.speed(0) * THRUST_MOD,
base_speed: spaceship.speed(0) * MAX_SPACESHIP_SPEED_MOD,
maneuverability: 0.0,
fuel: fuel as f32,
Expand Down
17 changes: 1 addition & 16 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ pub trait StorableResourceMap {
fn value(&self, resource: &Resource) -> u32;
fn used_storage_capacity(&self) -> u32;
fn used_fuel_capacity(&self) -> u32;
fn update(&mut self, resource: Resource, amount: i32, max_capacity: u32) -> AppResult<()>;
fn add(&mut self, resource: Resource, amount: u32, max_capacity: u32) -> AppResult<()>;
fn saturating_add(&mut self, resource: Resource, amount: u32, max_capacity: u32);
fn sub(&mut self, resource: Resource, amount: u32) -> AppResult<()>;
Expand All @@ -68,16 +67,6 @@ impl StorableResourceMap for ResourceMap {
self.value(&Resource::FUEL)
}

fn update(&mut self, resource: Resource, amount: i32, max_capacity: u32) -> AppResult<()> {
if amount > 0 {
self.add(resource, amount as u32, max_capacity)?;
} else if amount < 0 {
self.sub(resource, (-amount) as u32)?;
}

Ok(())
}

fn add(&mut self, resource: Resource, amount: u32, max_capacity: u32) -> AppResult<()> {
if resource == Resource::FUEL {
if self.used_fuel_capacity() + amount > max_capacity {
Expand Down Expand Up @@ -139,11 +128,7 @@ impl StorableResourceMap for ResourceMap {
return Err(anyhow!("Not enough resources to remove"));
}

self.entry(resource)
.and_modify(|e| {
*e = e.saturating_sub(amount);
})
.or_insert(0);
self.saturating_sub(resource, amount);
Ok(())
}

Expand Down
Loading

0 comments on commit 6ddfe30

Please sign in to comment.