Compare commits

..

No commits in common. "7272f2a00a75b728112ca488d92fe7d0b674d06b" and "1f2ba92bea16df4754fc4bda2851c0dd63a56c0b" have entirely different histories.

19 changed files with 65 additions and 341 deletions

View File

@ -17,7 +17,6 @@
- fps textbox positioning - fps textbox positioning
- shield generation curve - shield generation curve
- clippy & rules - clippy & rules
- reject unknown toml
## Small jobs ## Small jobs
- Better planet icons in radar - Better planet icons in radar

View File

@ -1,7 +1,6 @@
[outfit."plasma engines"] [outfit."plasma engines"]
name = "Plasma Engines" name = "Plasma Engines"
thumbnail = "icon::engine" thumbnail = "icon::engine"
cost = 30
desc = """ desc = """
This is the smallest of the plasma propulsion systems produced by This is the smallest of the plasma propulsion systems produced by
@ -22,7 +21,6 @@ steering.power = 20
[outfit."shield generator"] [outfit."shield generator"]
thumbnail = "icon::shield" thumbnail = "icon::shield"
name = "Shield Generator" name = "Shield Generator"
cost = 10
desc = """ desc = """
This is the standard shield generator for fighters and interceptors, This is the standard shield generator for fighters and interceptors,
@ -42,7 +40,6 @@ shield.delay = 2.0
[outfit."blaster"] [outfit."blaster"]
thumbnail = "icon::blaster" thumbnail = "icon::blaster"
name = "Blaster" name = "Blaster"
cost = 20
desc = """ desc = """
Although not the most accurate or damaging of weapons, the Energy Blaster is popular because it Although not the most accurate or damaging of weapons, the Energy Blaster is popular because it

View File

@ -113,15 +113,10 @@ fn event(state, event) {
} }
fn step(state) { fn step(state) {
if state.player_ship().stat_shield_strength() == 0.0 { radialbar::set_val("shield",
radialbar::set_val("shield", 0.0); state.player_ship().current_shields()
} else { / state.player_ship().stat_shield_strength()
radialbar::set_val("shield", );
state.player_ship().current_shields()
/ state.player_ship().stat_shield_strength()
);
}
radialbar::set_val("hull", radialbar::set_val("hull",
state.player_ship().current_hull() state.player_ship().current_hull()
/ state.player_ship().total_hull() / state.player_ship().total_hull()

View File

@ -347,9 +347,6 @@ fn init(state) {
fn event(state, event) { fn event(state, event) {
// TODO: update on ship outfit change only
update_ship_info(state);
if type_of(event) == "MouseHoverEvent" { if type_of(event) == "MouseHoverEvent" {
let element = event.element(); let element = event.element();
@ -397,24 +394,6 @@ fn event(state, event) {
return PlayerDirective::None; return PlayerDirective::None;
} }
if element == "buy_button" {
if selected_outfit != false {
let outfit = ct::get_outfit(selected_outfit);
if outfit.is_some() {
return PlayerDirective::BuyOutfit(outfit, 1);
}
}
}
if element == "sell_button" {
if selected_outfit != false {
let outfit = ct::get_outfit(selected_outfit);
if outfit.is_some() {
return PlayerDirective::SellOutfit(outfit, 1);
}
}
}
if ( if (
element.starts_with("outfit.backg.") && element.starts_with("outfit.backg.") &&
event.element().split("outfit.backg.".len())[1] != selected_outfit event.element().split("outfit.backg.".len())[1] != selected_outfit
@ -496,41 +475,6 @@ fn update_outfit_info(selected_outfit) {
let stats = ""; let stats = "";
let tlen = 20; let tlen = 20;
{
let s = "cost ";
s.pad(tlen, " ");
stats += s + outfit.cost();
stats += "\n";
}
{
let s = "needs gun port ";
s.pad(tlen, " ");
if outfit.stat_is_gun() {
stats += s + "yes";
} else {
stats += s + "no"
}
stats += "\n";
}
{
let s = outfit.required_space();
for k in s.keys() {
let v = s[k];
let s = k + " space needed ";
s.pad(tlen, " ");
if v != 0 {
stats += s + v;
stats += "\n";
}
}
}
stats += "\n";
if outfit.stat_thrust() != 0 { if outfit.stat_thrust() != 0 {
let s = "thrust "; let s = "thrust ";
s.pad(tlen, " "); s.pad(tlen, " ");
@ -583,28 +527,8 @@ fn update_ship_info(state) {
let tlen = 20; let tlen = 20;
{
let u = ship.used_space();
let t = ship.total_space();
for k in u.keys() {
let vu = u[k];
let vt = t[k];
let s = k + " space ";
s.pad(tlen, " ");
stats += s + (vt - vu) + "/" + vt;
stats += "\n";
}
}
{
let s = "gun points ";
s.pad(tlen, " ");
stats += s + ship.free_gun_points() + "/" + ship.total_gun_points();
stats += "\n\n";
}
// TODO: outfits add mass // TODO: outfits add mass
// TODO: calculate acceleration // TODO: calculate radial acceleration
{ {
let s = "shield strength "; let s = "shield strength ";
s.pad(tlen, " "); s.pad(tlen, " ");

View File

@ -24,7 +24,6 @@ pub(crate) mod syntax {
pub thumbnail: ContentIndex, pub thumbnail: ContentIndex,
pub name: String, pub name: String,
pub desc: String, pub desc: String,
pub cost: u32,
pub engine: Option<Engine>, pub engine: Option<Engine>,
pub steering: Option<Steering>, pub steering: Option<Steering>,
pub space: outfitspace::syntax::OutfitSpace, pub space: outfitspace::syntax::OutfitSpace,
@ -141,9 +140,6 @@ pub struct Outfit {
/// This outfit's thumbnail /// This outfit's thumbnail
pub thumbnail: Arc<Sprite>, pub thumbnail: Arc<Sprite>,
/// The cost of this outfit, in credits
pub cost: u32,
/// How much space this outfit requires /// How much space this outfit requires
pub space: OutfitSpace, pub space: OutfitSpace,
@ -328,7 +324,6 @@ impl crate::Build for Outfit {
let mut o = Self { let mut o = Self {
index: ContentIndex::new(&outfit_name), index: ContentIndex::new(&outfit_name),
display_name: outfit.name, display_name: outfit.name,
cost: outfit.cost,
thumbnail, thumbnail,
gun, gun,
desc: outfit.desc, desc: outfit.desc,

View File

@ -1,7 +1,4 @@
use std::{ use std::ops::{Add, AddAssign, Sub, SubAssign};
collections::HashMap,
ops::{Add, AddAssign, Sub, SubAssign},
};
pub(crate) mod syntax { pub(crate) mod syntax {
use serde::Deserialize; use serde::Deserialize;
@ -47,15 +44,6 @@ impl OutfitSpace {
&& self.weapon >= smaller.weapon && self.weapon >= smaller.weapon
&& self.engine >= smaller.engine && self.engine >= smaller.engine
} }
/// Return a map of "space name" -> number
pub fn to_hashmap(&self) -> HashMap<String, u32> {
let mut m = HashMap::new();
m.insert("outfit".to_string(), self.outfit);
m.insert("weapon".to_string(), self.weapon);
m.insert("engine".to_string(), self.engine);
m
}
} }
impl Sub for OutfitSpace { impl Sub for OutfitSpace {

View File

@ -5,7 +5,6 @@ use galactica_system::phys::{PhysImage, PhysSim, PhysSimShipHandle, PhysStepReso
use galactica_system::PlayerDirective; use galactica_system::PlayerDirective;
use galactica_util::timing::Timing; use galactica_util::timing::Timing;
use nalgebra::Point2; use nalgebra::Point2;
use std::iter;
use std::sync::Arc; use std::sync::Arc;
use std::time::Instant; use std::time::Instant;
@ -52,6 +51,16 @@ impl<'a> Game {
.get(&ContentIndex::new("shield generator")) .get(&ContentIndex::new("shield generator"))
.unwrap() .unwrap()
.clone(), .clone(),
self.ct
.outfits
.get(&ContentIndex::new("blaster"))
.unwrap()
.clone(),
self.ct
.outfits
.get(&ContentIndex::new("blaster"))
.unwrap()
.clone(),
]); ]);
return player; return player;
@ -122,43 +131,9 @@ impl<'a> Game {
} }
} }
pub fn apply_directive(&mut self, directive: PlayerDirective, player: &mut PlayerAgent) { pub fn apply_directive(&mut self, directive: PlayerDirective, player: &PlayerAgent) {
match directive { match directive {
PlayerDirective::None => {} _ => self.phys_sim.apply_directive(directive, player),
PlayerDirective::BuyOutfit { outfit, count } => {
let cost = outfit.cost * count;
if player.credits >= cost {
player.credits -= cost;
let ship = self
.phys_sim
.get_ship_mut(&PhysSimShipHandle(player.ship.unwrap()))
.unwrap();
ship.add_outfits(iter::repeat(outfit).take(count as usize))
}
}
PlayerDirective::SellOutfit { outfit, count } => {
let ship = self
.phys_sim
.get_ship_mut(&PhysSimShipHandle(player.ship.unwrap()))
.unwrap();
if ship.get_data().get_outfits().has_outfit(&outfit, count) {
for _ in 0..count {
ship.remove_outfit(&outfit);
}
}
player.credits += outfit.cost * count;
}
PlayerDirective::Engine(_)
| PlayerDirective::Guns(_)
| PlayerDirective::Land
| PlayerDirective::TurnLeft(_)
| PlayerDirective::TurnRight(_)
| PlayerDirective::UnLand => self.phys_sim.apply_directive(directive, player),
} }
} }

View File

@ -15,7 +15,6 @@ use log4rs::{
Config, Config,
}; };
use std::{ use std::{
cell::RefCell,
fs, fs,
path::{Path, PathBuf}, path::{Path, PathBuf},
sync::Arc, sync::Arc,
@ -128,7 +127,7 @@ fn try_main() -> Result<()> {
current_time: game.get_current_time(), current_time: game.get_current_time(),
ct: content.clone(), ct: content.clone(),
phys_img: PhysImage::new(), phys_img: PhysImage::new(),
player: RefCell::new(PlayerAgent::new(&content, p.0)), player: PlayerAgent::new(&content, p.0),
// TODO: this is a hack for testing. // TODO: this is a hack for testing.
current_system: content.systems.values().next().unwrap().clone(), current_system: content.systems.values().next().unwrap().clone(),
timing: game.get_timing().clone(), timing: game.get_timing().clone(),
@ -185,13 +184,13 @@ fn try_main() -> Result<()> {
}, },
) )
.unwrap(); .unwrap();
game.apply_directive(directive, &mut input.player.borrow_mut()); game.apply_directive(directive, &input.player);
} }
WindowEvent::CursorMoved { position, .. } => { WindowEvent::CursorMoved { position, .. } => {
let directive = gpu let directive = gpu
.process_input(&input, InputEvent::MouseMove(position.cast())) .process_input(&input, InputEvent::MouseMove(position.cast()))
.unwrap(); .unwrap();
game.apply_directive(directive, &mut input.player.borrow_mut()); game.apply_directive(directive, &input.player);
} }
WindowEvent::MouseInput { state, button, .. } => { WindowEvent::MouseInput { state, button, .. } => {
let down = state == &ElementState::Pressed; let down = state == &ElementState::Pressed;
@ -202,7 +201,7 @@ fn try_main() -> Result<()> {
}; };
if let Some(event) = event { if let Some(event) = event {
let directive = gpu.process_input(&input, event).unwrap(); let directive = gpu.process_input(&input, event).unwrap();
game.apply_directive(directive, &mut input.player.borrow_mut()); game.apply_directive(directive, &input.player);
} }
} }
WindowEvent::MouseWheel { delta, .. } => { WindowEvent::MouseWheel { delta, .. } => {
@ -215,7 +214,7 @@ fn try_main() -> Result<()> {
}), }),
) )
.unwrap(); .unwrap();
game.apply_directive(directive, &mut input.player.borrow_mut()); game.apply_directive(directive, &input.player);
} }
WindowEvent::Resized(_) => { WindowEvent::Resized(_) => {
gpu.resize(&content); gpu.resize(&content);

View File

@ -29,17 +29,13 @@ pub struct PlayerAgent {
/// Which ship this player is controlling /// Which ship this player is controlling
pub ship: Option<ColliderHandle>, pub ship: Option<ColliderHandle>,
/// What this player has selected /// What the player has selected
pub selection: PlayerSelection, pub selection: PlayerSelection,
/// The amount of money this player has
pub credits: u32,
} }
impl PlayerAgent { impl PlayerAgent {
pub fn new(ct: &Content, ship: ColliderHandle) -> Self { pub fn new(ct: &Content, ship: ColliderHandle) -> Self {
Self { Self {
credits: 1000,
ship: Some(ship), ship: Some(ship),
selection: PlayerSelection::OrbitingBody( selection: PlayerSelection::OrbitingBody(
ct.systems ct.systems

View File

@ -287,7 +287,7 @@ impl GPUState {
/// Main render function. Draws sprites on a window. /// Main render function. Draws sprites on a window.
pub fn render(&mut self, input: &Arc<RenderInput>) -> Result<(), wgpu::SurfaceError> { pub fn render(&mut self, input: &Arc<RenderInput>) -> Result<(), wgpu::SurfaceError> {
if let Some(ship) = input.player.borrow().ship { if let Some(ship) = input.player.ship {
let o = input.phys_img.get_ship(&PhysSimShipHandle(ship)); let o = input.phys_img.get_ship(&PhysSimShipHandle(ship));
if let Some(o) = o { if let Some(o) = o {
match o.ship.get_data().get_state() { match o.ship.get_data().get_state() {

View File

@ -1,4 +1,4 @@
use std::{cell::RefCell, sync::Arc}; use std::sync::Arc;
use galactica_content::{Content, System}; use galactica_content::{Content, System};
use galactica_playeragent::PlayerAgent; use galactica_playeragent::PlayerAgent;
@ -9,7 +9,7 @@ use galactica_util::timing::Timing;
#[derive(Debug)] #[derive(Debug)]
pub struct RenderInput { pub struct RenderInput {
/// Player ship data /// Player ship data
pub player: RefCell<PlayerAgent>, pub player: PlayerAgent,
/// The system we're currently in /// The system we're currently in
pub current_system: Arc<System>, pub current_system: Arc<System>,

View File

@ -4,7 +4,6 @@ use rhai::{plugin::*, Dynamic, Module};
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(non_upper_case_globals)] #[allow(non_upper_case_globals)]
pub mod player_directive_module { pub mod player_directive_module {
use crate::ui::api::OutfitState;
use galactica_system::PlayerDirective; use galactica_system::PlayerDirective;
pub const None: PlayerDirective = PlayerDirective::None; pub const None: PlayerDirective = PlayerDirective::None;
@ -26,24 +25,4 @@ pub mod player_directive_module {
pub fn Guns(state: bool) -> PlayerDirective { pub fn Guns(state: bool) -> PlayerDirective {
PlayerDirective::Guns(state) PlayerDirective::Guns(state)
} }
pub fn BuyOutfit(outfit: OutfitState, count: i64) -> PlayerDirective {
if count <= 0 {
return PlayerDirective::None;
}
PlayerDirective::BuyOutfit {
outfit: outfit.get_outfit().unwrap(),
count: count as u32,
}
}
pub fn SellOutfit(outfit: OutfitState, count: i64) -> PlayerDirective {
if count <= 0 {
return PlayerDirective::None;
}
PlayerDirective::SellOutfit {
outfit: outfit.get_outfit().unwrap(),
count: count as u32,
}
}
} }

View File

@ -1,8 +1,6 @@
use galactica_content::{Content, Outfit, OutfitSpace}; use galactica_content::{Content, Outfit};
use log::error; use log::error;
use rhai::{ use rhai::{CustomType, FnNamespace, FuncRegistration, ImmutableString, Module, TypeBuilder};
CustomType, Dynamic, FnNamespace, FuncRegistration, ImmutableString, Map, Module, TypeBuilder,
};
use std::sync::Arc; use std::sync::Arc;
pub fn build_ct_module(ct_src: Arc<Content>) -> Module { pub fn build_ct_module(ct_src: Arc<Content>) -> Module {
@ -42,10 +40,6 @@ impl OutfitState {
pub fn new_none() -> Self { pub fn new_none() -> Self {
Self { outfit: None } Self { outfit: None }
} }
pub fn get_outfit(&self) -> Option<Arc<Outfit>> {
self.outfit.as_ref().cloned()
}
} }
impl CustomType for OutfitState { impl CustomType for OutfitState {
@ -77,20 +71,6 @@ impl CustomType for OutfitState {
.map(|x| x.thumbnail.index.to_string()) .map(|x| x.thumbnail.index.to_string())
.unwrap_or("".to_string()) .unwrap_or("".to_string())
}) })
.with_fn("cost", |s: &mut Self| {
s.outfit.as_ref().map(|x| x.cost).unwrap_or(0)
})
.with_fn("required_space", |s: &mut Self| {
Map::from_iter(
s.outfit
.as_ref()
.map(|x| x.space)
.unwrap_or(OutfitSpace::new())
.to_hashmap()
.iter()
.map(|(k, v)| (ImmutableString::from(k).into(), Dynamic::from(*v as i64))),
)
})
// //
// Stat getters // Stat getters
// //
@ -124,9 +104,6 @@ impl CustomType for OutfitState {
.map(|x| x.stats.shield_delay) .map(|x| x.stats.shield_delay)
.unwrap_or(0.0) .unwrap_or(0.0)
}) })
.with_fn("stat_is_gun", |s: &mut Self| {
s.outfit.as_ref().map(|x| x.gun.is_some()).unwrap_or(false)
})
.with_fn("stat_shield_dps", |s: &mut Self| { .with_fn("stat_shield_dps", |s: &mut Self| {
s.outfit s.outfit
.as_ref() .as_ref()

View File

@ -7,7 +7,7 @@ use galactica_util::to_degrees;
use log::error; use log::error;
use nalgebra::Vector2; use nalgebra::Vector2;
use rapier2d::dynamics::RigidBody; use rapier2d::dynamics::RigidBody;
use rhai::{Array, CustomType, Dynamic, ImmutableString, Map, TypeBuilder}; use rhai::{Array, CustomType, Dynamic, ImmutableString, TypeBuilder};
use std::sync::Arc; use std::sync::Arc;
use super::{functions::OutfitState, Color, UiVector}; use super::{functions::OutfitState, Color, UiVector};
@ -94,6 +94,14 @@ impl CustomType for ShipState {
s.get_content().thumbnail.index.clone().into() s.get_content().thumbnail.index.clone().into()
}) })
.with_fn("landed_on", |s: &mut Self| s.landed_on()) .with_fn("landed_on", |s: &mut Self| s.landed_on())
.with_fn("current_shields", |s: &mut Self| {
s.get_ship().get_data().get_shields()
})
.with_fn("total_hull", |s: &mut Self| s.get_content().hull)
.with_fn("empty_mass", |s: &mut Self| s.get_content().mass)
.with_fn("current_hull", |s: &mut Self| {
s.get_ship().get_data().get_hull()
})
.with_fn("get_size", |s: &mut Self| s.get_content().size) .with_fn("get_size", |s: &mut Self| s.get_content().size)
.with_fn("phys_uid", |s: &mut Self| format!("{}", s.get_ship().uid)) .with_fn("phys_uid", |s: &mut Self| format!("{}", s.get_ship().uid))
.with_fn("get_pos", |s: &mut Self| { .with_fn("get_pos", |s: &mut Self| {
@ -106,46 +114,7 @@ impl CustomType for ShipState {
Color::new(c[0], c[1], c[2], 1.0) Color::new(c[0], c[1], c[2], 1.0)
}) })
// //
// Ship stat getters // Stat getters
//
.with_fn("used_space", |s: &mut Self| {
Map::from_iter(
s.get_ship()
.get_data()
.get_outfits()
.get_used_space()
.to_hashmap()
.iter()
.map(|(k, v)| (ImmutableString::from(k).into(), Dynamic::from(*v as i64))),
)
})
.with_fn("total_space", |s: &mut Self| {
Map::from_iter(
s.get_ship()
.get_data()
.get_outfits()
.get_total_space()
.to_hashmap()
.iter()
.map(|(k, v)| (ImmutableString::from(k).into(), Dynamic::from(*v as i64))),
)
})
.with_fn("total_gun_points", |s: &mut Self| {
s.get_ship().get_data().get_outfits().total_gun_points() as i64
})
.with_fn("free_gun_points", |s: &mut Self| {
s.get_ship().get_data().get_outfits().free_gun_points() as i64
})
.with_fn("current_shields", |s: &mut Self| {
s.get_ship().get_data().get_shields()
})
.with_fn("total_hull", |s: &mut Self| s.get_content().hull)
.with_fn("empty_mass", |s: &mut Self| s.get_content().mass)
.with_fn("current_hull", |s: &mut Self| {
s.get_ship().get_data().get_hull()
})
//
// Outfit stat getters
// //
.with_fn("stat_thrust", |s: &mut Self| { .with_fn("stat_thrust", |s: &mut Self| {
s.get_ship() s.get_ship()
@ -295,12 +264,7 @@ impl State {
pub fn player_ship(&mut self) -> ShipState { pub fn player_ship(&mut self) -> ShipState {
ShipState { ShipState {
input: self.input.clone(), input: self.input.clone(),
ship: self ship: self.input.player.ship.map(|x| PhysSimShipHandle(x)),
.input
.player
.borrow()
.ship
.map(|x| PhysSimShipHandle(x)),
} }
} }

View File

@ -301,7 +301,7 @@ impl UiScriptExecutor {
// Send player state change events // Send player state change events
if { if {
let player = input.player.borrow().ship; let player = input.player.ship;
if let Some(player) = player { if let Some(player) = player {
let ship = input.phys_img.get_ship(&PhysSimShipHandle(player)).unwrap(); let ship = input.phys_img.get_ship(&PhysSimShipHandle(player)).unwrap();
if self.last_player_state == 0 if self.last_player_state == 0

View File

@ -104,7 +104,6 @@ impl OutfitSet {
if outfit.is_none() { if outfit.is_none() {
*outfit = Some(o.clone()); *outfit = Some(o.clone());
added = true; added = true;
break;
} }
} }
if !added { if !added {
@ -113,15 +112,14 @@ impl OutfitSet {
} }
self.used_space += o.space; self.used_space += o.space;
self.stats.add(&o.stats); self.stats.add(&o.stats);
if o.stats.shield_generation != 0.0 { self.shield_generators.push(ShieldGenerator {
self.shield_generators.push(ShieldGenerator { outfit: o.clone(),
outfit: o.clone(), delay: o.stats.shield_delay,
delay: o.stats.shield_delay, generation: o.stats.shield_generation,
generation: o.stats.shield_generation, });
});
}
if self.outfits.contains_key(&o.index) { if self.outfits.contains_key(&o.index) {
self.outfits.get_mut(&o.index).unwrap().1 += 1; self.outfits.get_mut(&o.index).unwrap().1 += 1;
@ -135,32 +133,26 @@ impl OutfitSet {
pub(super) fn remove(&mut self, o: &Arc<Outfit>) -> OutfitRemoveResult { pub(super) fn remove(&mut self, o: &Arc<Outfit>) -> OutfitRemoveResult {
if !self.outfits.contains_key(&o.index) { if !self.outfits.contains_key(&o.index) {
return OutfitRemoveResult::NotExist; return OutfitRemoveResult::NotExist;
}
let n = self.outfits.get_mut(&o.index).unwrap();
if n.1 == 1u32 {
self.outfits.remove(&o.index);
} else { } else {
self.outfits.get_mut(&o.index).unwrap().1 -= 1; let n = self.outfits.get_mut(&o.index).unwrap();
} if n.1 == 1u32 {
self.outfits.remove(&o.index);
if o.gun.is_some() { } else {
let (_, x) = self self.outfits.get_mut(&o.index).unwrap().1 -= 1;
.gun_points }
.iter_mut()
.find(|(_, x)| x.is_some() && x.as_ref().unwrap().index == o.index)
.unwrap();
*x = None;
} }
self.used_space -= o.space; self.used_space -= o.space;
self.stats.subtract(&o.stats); self.stats.subtract(&o.stats);
let index = self {
.shield_generators // This index will exist, since we checked the hashmap
.iter() let index = self
.position(|g| g.outfit.index == o.index); .shield_generators
if let Some(index) = index { .iter()
.position(|g| g.outfit.index == o.index)
.unwrap();
self.shield_generators.remove(index); self.shield_generators.remove(index);
} }
@ -206,29 +198,6 @@ impl OutfitSet {
&self.used_space &self.used_space
} }
/// Number of available (used & free) gun points
pub fn total_gun_points(&self) -> usize {
self.gun_points.len()
}
/// Number of free gun points
pub fn free_gun_points(&self) -> usize {
self.iter_gun_points().filter(|(_, o)| o.is_none()).count()
}
/// Does this set contain `count` of `outfit`?
pub fn has_outfit(&self, outfit: &Arc<Outfit>, mut count: u32) -> bool {
for i in self.iter_outfits() {
if count <= 0 {
return true;
}
if i.0.index == outfit.index {
count -= 1;
}
}
return count <= 0;
}
/// Get the combined stats of all outfits in this set. /// Get the combined stats of all outfits in this set.
/// There are two things to note here: /// There are two things to note here:
/// First, shield_delay is always zero. That is handled /// First, shield_delay is always zero. That is handled

View File

@ -14,7 +14,7 @@ use rapier2d::{
use super::{autopilot, collapse::ShipCollapseSequence, controller::ShipController, ShipControls}; use super::{autopilot, collapse::ShipCollapseSequence, controller::ShipController, ShipControls};
use crate::{ use crate::{
data::{OutfitRemoveResult, ShipAutoPilot, ShipData, ShipPersonality, ShipState}, data::{ShipAutoPilot, ShipData, ShipPersonality, ShipState},
phys::{ phys::{
get_phys_id, get_phys_id,
objects::{PhysEffect, PhysProjectile}, objects::{PhysEffect, PhysProjectile},
@ -505,8 +505,8 @@ impl PhysShip {
} }
/// Add one outfit to this ship /// Add one outfit to this ship
pub fn add_outfit(&mut self, o: &Arc<Outfit>) { pub fn add_outfit(&mut self, o: Arc<Outfit>) {
self.data.add_outfit(o); self.data.add_outfit(&o);
self.update_flares(); self.update_flares();
} }
@ -517,13 +517,6 @@ impl PhysShip {
} }
self.update_flares(); self.update_flares();
} }
/// Remove one outfit from this ship
pub fn remove_outfit(&mut self, o: &Arc<Outfit>) -> OutfitRemoveResult {
let r = self.data.remove_outfit(o);
self.update_flares();
return r;
}
} }
/// Public immutable /// Public immutable

View File

@ -192,7 +192,7 @@ impl PhysSim {
} }
/// Update a player ship's controls /// Update a player ship's controls
pub fn apply_directive(&mut self, directive: PlayerDirective, player: &mut PlayerAgent) { pub fn apply_directive(&mut self, directive: PlayerDirective, player: &PlayerAgent) {
if player.ship.is_none() { if player.ship.is_none() {
return; return;
} }

View File

@ -1,7 +1,3 @@
use std::sync::Arc;
use galactica_content::Outfit;
/// An action the player wants to take in the game. /// An action the player wants to take in the game.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum PlayerDirective { pub enum PlayerDirective {
@ -25,26 +21,4 @@ pub enum PlayerDirective {
/// Take off from the planet we're landed on /// Take off from the planet we're landed on
UnLand, UnLand,
/// Buy an outfit.
/// This directive is ignored if the player does not have enough
/// credits to buy the given number of outfits.
BuyOutfit {
/// The outfit to buy
outfit: Arc<Outfit>,
/// How many of this outfit to buy
count: u32,
},
/// Sell an outfit.
/// This directive is ignored if the player does not have enough
/// outfits to sell.
SellOutfit {
/// The outfit to sell
outfit: Arc<Outfit>,
/// How many of this outfit to sell
count: u32,
},
} }