Skip to content

Commit 6ddfe30

Browse files
committed
v1.0.25
1 parent 90bdaac commit 6ddfe30

24 files changed

+692
-531
lines changed

Cargo.lock

+80-80
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rebels"
3-
version = "1.0.24"
3+
version = "1.0.25"
44
edition = "2021"
55
authors = ["Alessandro Ricottone <[email protected]>"]
66
license = "GPL-3.0-or-later"

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ You need to have the [rust toolchain](https://www.rust-lang.org/tools/install).
6161
pacman -S rebels-in-the-sky
6262
```
6363

64+
#### MacPorts
65+
66+
`rebels-in-the-sky` can be installed from the [available ports](https://ports.macports.org/port/rebels-in-the-sky/):
67+
68+
```sh
69+
sudo port install rebels-in-the-sky
70+
```
71+
6472
## Run
6573

6674
This game runs as a terminal application, meaning that you just need to run the executable from your terminal with

assets/data/planets_data.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@
217217
"resources": {
218218
"1": 1,
219219
"2": 7,
220-
"3": 16
220+
"3": 12
221221
},
222222
"filename": "gas",
223223
"rotation_period": 9,
@@ -344,7 +344,7 @@
344344
},
345345
"resources": {
346346
"2": 2,
347-
"3": 18,
347+
"3": 14,
348348
"4": 2
349349
},
350350
"filename": "deimos",

src/game_engine/action.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ pub trait EngineAction {
118118
fn tactic_modifier(game: &Game, action: &Action) -> i16 {
119119
let attack_tactic = game.home_team_in_game.tactic;
120120
let defense_tactic = game.home_team_in_game.tactic;
121-
attack_tactic.atk_roll_bonus(&defense_tactic, &action)
121+
attack_tactic.attack_roll_bonus(&action) - defense_tactic.defense_roll_bonus(&action)
122122
}
123123
fn execute(input: &ActionOutput, game: &Game, rng: &mut ChaCha8Rng) -> Option<ActionOutput>;
124124
fn sample(rng: &mut ChaCha8Rng, weights: [u8; 5]) -> Option<usize> {

src/game_engine/game.rs

+90-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::{
1717
},
1818
};
1919
use itertools::Itertools;
20-
use rand::{Rng, SeedableRng};
20+
use rand::{seq::SliceRandom, Rng, SeedableRng};
2121
use rand_chacha::ChaCha8Rng;
2222
use serde::{Deserialize, Serialize};
2323
use std::fmt::Debug;
@@ -125,6 +125,10 @@ pub struct Game {
125125
}
126126

127127
impl<'game> Game {
128+
pub fn is_network(&self) -> bool {
129+
self.home_team_in_game.peer_id.is_some() && self.away_team_in_game.peer_id.is_some()
130+
}
131+
128132
pub fn new(
129133
id: GameId,
130134
home_team_in_game: TeamInGame,
@@ -188,14 +192,91 @@ impl<'game> Game {
188192
* (1.0 + bonus_attendance);
189193
game.attendance = attendance as u32;
190194
let mut default_output = ActionOutput::default();
191-
default_output.description = format!(
192-
"{} vs {}. Game is about to start here on {}! There are {} {}people in the stadium.",
193-
home_name,
194-
away_name,
195-
planet.name,
196-
game.attendance,
197-
if game.attendance == 69 { "(nice) " } else { "" }
198-
);
195+
196+
let opening_text = [
197+
format!(
198+
"{} vs {}. The intergalactic showdown is kicking off on {}! {} fans have packed the arena{}.",
199+
home_name,
200+
away_name,
201+
planet.name,
202+
game.attendance,
203+
if game.attendance == 69 { " (nice)" } else { "" }
204+
),
205+
format!(
206+
"It's {} against {}! We're live here on {} where {} spectators{} are buzzing with excitement.",
207+
home_name,
208+
away_name,
209+
planet.name,
210+
game.attendance,
211+
if game.attendance == 69 { " (nice)" } else { "" }
212+
),
213+
format!(
214+
"The stage is set on {} for {} vs {}. A crowd of {}{} fans is ready for the action to unfold!",
215+
planet.name,
216+
home_name,
217+
away_name,
218+
game.attendance,
219+
if game.attendance == 69 { " (nice)" } else { "" }
220+
),
221+
format!(
222+
"{} and {} clash today on {}! An electric atmosphere fills the stadium with {} fans{} watching closely.",
223+
home_name,
224+
away_name,
225+
planet.name,
226+
game.attendance,
227+
if game.attendance == 69 { " (nice)" } else { "" }
228+
),
229+
format!(
230+
"Welcome to {} for an epic battle: {} vs {}. The crowd of {} fans{} is ready to witness greatness!",
231+
planet.name,
232+
home_name,
233+
away_name,
234+
game.attendance,
235+
if game.attendance == 69 { " (nice)" } else { "" }
236+
),
237+
format!(
238+
"Tonight on {}, it's {} taking on {}. With {} passionate fans{} in attendance, the game is about to ignite!",
239+
planet.name,
240+
home_name,
241+
away_name,
242+
game.attendance,
243+
if game.attendance == 69 { " (nice)" } else { "" }
244+
),
245+
format!(
246+
"Game night on {}! {} faces off against {} before {} eager fans{} under the starry skies.",
247+
planet.name,
248+
home_name,
249+
away_name,
250+
game.attendance,
251+
if game.attendance == 69 { " (nice)" } else { "" }
252+
),
253+
format!(
254+
"The rivalry continues on {}: {} vs {}. The crowd of {} fans{} is fired up for this clash!",
255+
planet.name,
256+
home_name,
257+
away_name,
258+
game.attendance,
259+
if game.attendance == 69 { " (nice)" } else { "" }
260+
),
261+
format!(
262+
"All eyes are on {} as {} battles {}. An audience of {}{} is here to cheer for their team!",
263+
planet.name,
264+
home_name,
265+
away_name,
266+
game.attendance,
267+
if game.attendance == 69 { " (nice)" } else { "" }
268+
),
269+
format!(
270+
"Here on {}, it's {} vs {}. A roaring crowd of {} fans{} awaits the start of the showdown!",
271+
planet.name,
272+
home_name,
273+
away_name,
274+
game.attendance,
275+
if game.attendance == 69 { " (nice)" } else { "" }
276+
),
277+
].choose(&mut rng).expect("There should be one option").clone();
278+
279+
default_output.description = opening_text;
199280
default_output.random_seed = seed;
200281
game.action_results.push(default_output);
201282
game

src/game_engine/tactic.rs

+23-23
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ impl Tactic {
8181
}
8282
}
8383

84-
pub fn atk_roll_bonus(&self, defense_tactic: &Tactic, action: &Action) -> i16 {
85-
let defense_bonus = match defense_tactic {
84+
pub fn attack_roll_bonus(&self, action: &Action) -> i16 {
85+
match self {
8686
Self::Balanced => 0,
8787
Self::BigPirates => match action {
8888
Action::Isolation => -2,
@@ -94,26 +94,28 @@ impl Tactic {
9494
_ => 0,
9595
},
9696
Self::Arrembaggio => match action {
97-
Action::Isolation => 0,
97+
Action::Isolation => 2,
9898
Action::PickAndRoll => -2,
99-
Action::OffTheScreen => 2,
99+
Action::OffTheScreen => 0,
100100
Action::Post => -2,
101-
Action::Brawl => 2,
101+
Action::Brawl => 4,
102102
Action::Rebound => -2,
103103
_ => 0,
104104
},
105105
Self::Shooters => match action {
106-
Action::Isolation => 2,
107-
Action::PickAndRoll => 0,
108-
Action::OffTheScreen => 2,
106+
Action::Isolation => 0,
107+
Action::PickAndRoll => 2,
108+
Action::OffTheScreen => 4,
109109
Action::Post => -2,
110-
Action::Brawl => -2,
111-
Action::Rebound => 0,
110+
Action::Brawl => 0,
111+
Action::Rebound => -4,
112112
_ => 0,
113113
},
114-
};
114+
}
115+
}
115116

116-
let attack_bonus = match self {
117+
pub fn defense_roll_bonus(&self, action: &Action) -> i16 {
118+
match self {
117119
Self::Balanced => 0,
118120
Self::BigPirates => match action {
119121
Action::Isolation => -2,
@@ -125,25 +127,23 @@ impl Tactic {
125127
_ => 0,
126128
},
127129
Self::Arrembaggio => match action {
128-
Action::Isolation => 2,
130+
Action::Isolation => 0,
129131
Action::PickAndRoll => -2,
130-
Action::OffTheScreen => 0,
132+
Action::OffTheScreen => 2,
131133
Action::Post => -2,
132-
Action::Brawl => 4,
134+
Action::Brawl => 2,
133135
Action::Rebound => -2,
134136
_ => 0,
135137
},
136138
Self::Shooters => match action {
137-
Action::Isolation => 0,
138-
Action::PickAndRoll => 2,
139-
Action::OffTheScreen => 4,
139+
Action::Isolation => 2,
140+
Action::PickAndRoll => 0,
141+
Action::OffTheScreen => 2,
140142
Action::Post => -2,
141-
Action::Brawl => 0,
142-
Action::Rebound => -4,
143+
Action::Brawl => -2,
144+
Action::Rebound => 0,
143145
_ => 0,
144146
},
145-
};
146-
147-
attack_bonus - defense_bonus
147+
}
148148
}
149149
}

src/network/network_callback.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,9 @@ impl NetworkCallback {
301301
let own_team = app.world.get_own_team_mut()?;
302302
own_team.add_received_trade(trade.clone());
303303

304-
return Ok(Some("Trade received.\nCheck the swarm panel".to_string()));
304+
return Ok(Some(
305+
"Trade offer received.\nCheck the swarm panel".to_string(),
306+
));
305307
}
306308
NetworkRequestState::SynAck => {
307309
if trade.target_peer_id == *self_peer_id {

src/space_adventure/constants.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::ui::UI_SCREEN_SIZE;
55
pub(crate) const FRICTION_COEFF: f32 = 0.1;
66
pub(crate) const THRUST_MOD: f32 = 1.5;
77
pub(crate) const FUEL_CONSUMPTION_MOD: f32 = 215_000.0;
8-
pub(crate) const MAX_SPACESHIP_SPEED_MOD: f32 = 0.135;
8+
pub(crate) const MAX_SPACESHIP_SPEED_MOD: f32 = 0.125;
99

1010
pub(crate) const ASTEROID_GENERATION_PROBABILITY: f64 = 0.05;
1111
pub(crate) const DIFFICULTY_FOR_ASTEROID_PLANET_GENERATION: usize = 60;

src/space_adventure/space.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl SpaceAdventureState {
4545

4646
#[derive(Debug, Display, Clone, Copy, PartialEq)]
4747
enum AsteroidPlanetState {
48-
NotSpawned { asteroid_planet_probability: f64 },
48+
NotSpawned { should_spawn_asteroid: bool },
4949
Spawned { image_number: usize },
5050
Landed { image_number: usize },
5151
}
@@ -252,7 +252,7 @@ impl SpaceAdventure {
252252
}
253253
}
254254

255-
pub fn new(asteroid_planet_probability: f64) -> AppResult<Self> {
255+
pub fn new(should_spawn_asteroid: bool) -> AppResult<Self> {
256256
let bg = TRAVELLING_BACKGROUND.clone();
257257
let mut background = RgbaImage::new(bg.width() * 2, bg.height() * 3);
258258
background.copy_non_trasparent_from(&bg, 0, 0)?;
@@ -288,7 +288,7 @@ impl SpaceAdventure {
288288
id_to_layer: HashMap::new(),
289289
player_id: None,
290290
asteroid_planet_state: AsteroidPlanetState::NotSpawned {
291-
asteroid_planet_probability,
291+
should_spawn_asteroid,
292292
},
293293
enemy_ship_spawned: false,
294294
})
@@ -297,14 +297,12 @@ impl SpaceAdventure {
297297
pub fn with_player(
298298
mut self,
299299
spaceship: &Spaceship,
300-
team_speed_bonus: f32,
301300
resources: ResourceMap,
302301
fuel: u32,
303302
) -> AppResult<Self> {
304303
let collector_id = self.insert_entity(Box::new(CollectorEntity::new()));
305304
let id = self.insert_entity(Box::new(SpaceshipEntity::from_spaceship(
306305
spaceship,
307-
team_speed_bonus,
308306
resources,
309307
fuel,
310308
collector_id,
@@ -462,9 +460,9 @@ impl SpaceAdventure {
462460
if difficulty_level > DIFFICULTY_FOR_ASTEROID_PLANET_GENERATION {
463461
match self.asteroid_planet_state {
464462
AsteroidPlanetState::NotSpawned {
465-
asteroid_planet_probability,
463+
should_spawn_asteroid,
466464
} => {
467-
if asteroid_planet_probability > 0.0 {
465+
if should_spawn_asteroid {
468466
let asteroid = AsteroidEntity::planet();
469467
let id = self.insert_entity(Box::new(asteroid));
470468
self.asteroid_planet_state = AsteroidPlanetState::Spawned {

src/space_adventure/spaceship.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub struct SpaceshipEntity {
7777
is_player: bool,
7878
base_spaceship: Spaceship,
7979
resources: ResourceMap,
80-
used_storage_capacity: u32,
80+
used_storage_capacity: u32, // Not necessary, we keep it to avoid recalculating them every time.
8181
storage_capacity: u32,
8282
fuel_capacity: u32,
8383
previous_position: Vec2,
@@ -567,7 +567,6 @@ impl SpaceshipEntity {
567567

568568
pub fn from_spaceship(
569569
spaceship: &Spaceship,
570-
team_speed_bonus: f32,
571570
resources: ResourceMap,
572571
fuel: u32,
573572
collector_id: usize,
@@ -638,7 +637,7 @@ impl SpaceshipEntity {
638637
hit_boxes,
639638
current_durability: spaceship.current_durability() as f32,
640639
durability: spaceship.durability() as f32,
641-
base_thrust: spaceship.speed(0) * THRUST_MOD * team_speed_bonus,
640+
base_thrust: spaceship.speed(0) * THRUST_MOD,
642641
base_speed: spaceship.speed(0) * MAX_SPACESHIP_SPEED_MOD,
643642
maneuverability: 0.0,
644643
fuel: fuel as f32,

src/types.rs

+1-16
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ pub trait StorableResourceMap {
4141
fn value(&self, resource: &Resource) -> u32;
4242
fn used_storage_capacity(&self) -> u32;
4343
fn used_fuel_capacity(&self) -> u32;
44-
fn update(&mut self, resource: Resource, amount: i32, max_capacity: u32) -> AppResult<()>;
4544
fn add(&mut self, resource: Resource, amount: u32, max_capacity: u32) -> AppResult<()>;
4645
fn saturating_add(&mut self, resource: Resource, amount: u32, max_capacity: u32);
4746
fn sub(&mut self, resource: Resource, amount: u32) -> AppResult<()>;
@@ -68,16 +67,6 @@ impl StorableResourceMap for ResourceMap {
6867
self.value(&Resource::FUEL)
6968
}
7069

71-
fn update(&mut self, resource: Resource, amount: i32, max_capacity: u32) -> AppResult<()> {
72-
if amount > 0 {
73-
self.add(resource, amount as u32, max_capacity)?;
74-
} else if amount < 0 {
75-
self.sub(resource, (-amount) as u32)?;
76-
}
77-
78-
Ok(())
79-
}
80-
8170
fn add(&mut self, resource: Resource, amount: u32, max_capacity: u32) -> AppResult<()> {
8271
if resource == Resource::FUEL {
8372
if self.used_fuel_capacity() + amount > max_capacity {
@@ -139,11 +128,7 @@ impl StorableResourceMap for ResourceMap {
139128
return Err(anyhow!("Not enough resources to remove"));
140129
}
141130

142-
self.entry(resource)
143-
.and_modify(|e| {
144-
*e = e.saturating_sub(amount);
145-
})
146-
.or_insert(0);
131+
self.saturating_sub(resource, amount);
147132
Ok(())
148133
}
149134

0 commit comments

Comments
 (0)