|
|
|
@ -270,6 +270,20 @@ impl PlacedSprites {
|
|
|
|
|
struct BeltMarker(); |
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Copy)] |
|
|
|
|
struct Recipe { |
|
|
|
|
inputs: [(u32, Chem); 4], |
|
|
|
|
outputs: [(u32, Chem); 4], |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Copy)] |
|
|
|
|
struct Producer { |
|
|
|
|
recipe: Recipe, |
|
|
|
|
blocked: bool, |
|
|
|
|
items_per_tick: f32, |
|
|
|
|
generate_progress: f32, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Copy)] |
|
|
|
|
struct SourceGenerator { |
|
|
|
|
center_pos_px: (i32, i32), |
|
|
|
|
chem: Chem, |
|
|
|
@ -323,15 +337,16 @@ impl Chemtorio {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn tick_sources(&mut self) { |
|
|
|
|
for (_ent, (source_gen, out_slots)) in |
|
|
|
|
self.world |
|
|
|
|
.query_mut::<(&mut SourceGenerator, &mut OutputSlots)>() |
|
|
|
|
for (_ent, (source_gen, out_slots)) in self |
|
|
|
|
.world |
|
|
|
|
.query_mut::<(&mut SourceGenerator, &mut OutputSlots)>() |
|
|
|
|
{ |
|
|
|
|
source_gen.generate_progress += source_gen.items_per_tick; |
|
|
|
|
|
|
|
|
|
while source_gen.generate_progress >= 1.0 { |
|
|
|
|
if out_slots.slots[0].0 < out_slots.max[0] { |
|
|
|
|
out_slots.slots[0].0 += 1; |
|
|
|
|
println!("OUT GEN: {:?}", out_slots); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
source_gen.generate_progress -= 1.0; |
|
|
|
@ -340,11 +355,12 @@ impl Chemtorio {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn tick_pickers(&mut self) { |
|
|
|
|
// let mut outputs = self.world.query::<(&OutputSlots)>();
|
|
|
|
|
let mut outputs = self.world.query::<(&mut OutputSlots)>(); |
|
|
|
|
|
|
|
|
|
for (_ent, (pp, slots, flying)) in |
|
|
|
|
self.world |
|
|
|
|
.query_mut::<(&mut PickerProbes, &mut InputSlots, &mut FlyingItem)>() |
|
|
|
|
&mut self |
|
|
|
|
.world |
|
|
|
|
.query::<(&mut PickerProbes, &mut InputSlots, &mut FlyingItem)>() |
|
|
|
|
{ |
|
|
|
|
if slots.has_any() { |
|
|
|
|
if let Some(chem) = flying.chem { |
|
|
|
@ -355,7 +371,6 @@ impl Chemtorio {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
let mut fly = None; |
|
|
|
|
|
|
|
|
@ -364,25 +379,49 @@ impl Chemtorio {
|
|
|
|
|
self.belts.belts.probe_take(&mut pp.src1_probe); |
|
|
|
|
fly = Some((pp.src1_probe.tile_pos(), chem)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} else if let Some(chem) = self.belts.belts.probe_peek(&mut pp.src2_probe) { |
|
|
|
|
if slots.try_insert(chem) { |
|
|
|
|
self.belts.belts.probe_take(&mut pp.src2_probe); |
|
|
|
|
fly = Some((pp.src2_probe.tile_pos(), chem)); |
|
|
|
|
if fly.is_none() { |
|
|
|
|
if let Some(chem) = self.belts.belts.probe_peek(&mut pp.src2_probe) { |
|
|
|
|
if slots.try_insert(chem) { |
|
|
|
|
self.belts.belts.probe_take(&mut pp.src2_probe); |
|
|
|
|
fly = Some((pp.src2_probe.tile_pos(), chem)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if fly.is_none() { |
|
|
|
|
if let Some(slots_ent) = self |
|
|
|
|
.spatial |
|
|
|
|
.get_entity_at(pp.src1_probe.tile_pos(), TileLayer::OutputInventory) |
|
|
|
|
{ |
|
|
|
|
if let Some(out_slots) = &mut outputs.view().get_mut(slots_ent) { |
|
|
|
|
for (count, chem) in out_slots.slots.iter_mut() { |
|
|
|
|
if *count > 0 && slots.try_insert(*chem) { |
|
|
|
|
*count -= 1; |
|
|
|
|
fly = Some((pp.src1_probe.tile_pos(), *chem)); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if fly.is_none() { |
|
|
|
|
if let Some(slots_ent) = self |
|
|
|
|
.spatial |
|
|
|
|
.get_entity_at(pp.src2_probe.tile_pos(), TileLayer::OutputInventory) |
|
|
|
|
{ |
|
|
|
|
if let Some(out_slots) = &mut outputs.view().get_mut(slots_ent) { |
|
|
|
|
for (count, chem) in out_slots.slots.iter_mut() { |
|
|
|
|
if *count > 0 && slots.try_insert(*chem) { |
|
|
|
|
*count -= 1; |
|
|
|
|
fly = Some((pp.src2_probe.tile_pos(), *chem)); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else if let Some(slots_ent) = self.spatial.get_entity_at(pp.src1_probe.tile_pos(), TileLayer::OutputInventory) { |
|
|
|
|
println!("PICK FROM ENT1: {:?}", slots_ent); |
|
|
|
|
} else if let Some(slots_ent) = self.spatial.get_entity_at(pp.src2_probe.tile_pos(), TileLayer::OutputInventory) { |
|
|
|
|
println!("PICK FROM ENT2: {:?}", slots_ent); |
|
|
|
|
// if let Some(out_slots) = outputs.view().get(slots_ent) {
|
|
|
|
|
// for (count, chem) in out_slots.slots.iter_mut() {
|
|
|
|
|
// if *count > 0 && slots.try_insert(*chem) {
|
|
|
|
|
// *count -= 1;
|
|
|
|
|
// fly = Some((pp.src1_probe.tile_pos(), *chem));
|
|
|
|
|
// break;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if let Some((tile, chem)) = fly { |
|
|
|
@ -411,6 +450,7 @@ impl Chemtorio {
|
|
|
|
|
|
|
|
|
|
pub fn tick(&mut self) { |
|
|
|
|
self.belts.tick(); |
|
|
|
|
self.tick_sources(); |
|
|
|
|
self.tick_pickers(); |
|
|
|
|
self.tick_flying_items(); |
|
|
|
|
} |
|
|
|
@ -508,17 +548,17 @@ impl Chemtorio {
|
|
|
|
|
self.visuals.remove(pos); |
|
|
|
|
|
|
|
|
|
(true, ents) |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
EntityTypeTag::Belt(pos) => { |
|
|
|
|
let ents = self.belts.belts.remove_belt_at_tile(pos); |
|
|
|
|
(true, ents) |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
EntityTypeTag::Source(pos) => { |
|
|
|
|
self.world.despawn(ent); |
|
|
|
|
self.spatial.remove_entity(ent); |
|
|
|
|
|
|
|
|
|
(true, None) |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
EntityTypeTag::Processor(pos) => { |
|
|
|
|
// TODO
|
|
|
|
|
(true, None) |
|
|
|
@ -538,7 +578,7 @@ impl Chemtorio {
|
|
|
|
|
|
|
|
|
|
builder.add(OutputSlots { |
|
|
|
|
max: [1, 0, 0, 0], |
|
|
|
|
slots: [(1, chem); 4], |
|
|
|
|
slots: [(1, chem), (0, Chem::H2), (0, Chem::H2), (0, Chem::H2)], |
|
|
|
|
}); |
|
|
|
|
builder.add(EntityTypeTag::Source(pos)); |
|
|
|
|
builder.add(SourceGenerator { |
|
|
|
@ -613,30 +653,21 @@ impl Chemtorio {
|
|
|
|
|
// TODO: We need to add a proper tile map at some point, that draws the ground layer
|
|
|
|
|
// and special tile entities in a layer on top!
|
|
|
|
|
r.render_ground((gen.center_pos_px.0 as i32, gen.center_pos_px.1 as i32), 16); |
|
|
|
|
r.render_chem((gen.center_pos_px.0 as i32, gen.center_pos_px.1 as i32), gen.chem); |
|
|
|
|
r.render_chem( |
|
|
|
|
(gen.center_pos_px.0 as i32, gen.center_pos_px.1 as i32), |
|
|
|
|
gen.chem, |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
self.belts.draw_shadows(r); |
|
|
|
|
self.belts.draw(r); |
|
|
|
|
|
|
|
|
|
self.visuals.for_each(|pos: (i32, i32), es| { |
|
|
|
|
r.render_entity_shadow( |
|
|
|
|
( |
|
|
|
|
pos.0 * BELT_TILE_SIZE_PX, |
|
|
|
|
pos.1 * BELT_TILE_SIZE_PX, |
|
|
|
|
), |
|
|
|
|
es, |
|
|
|
|
); |
|
|
|
|
r.render_entity_shadow((pos.0 * BELT_TILE_SIZE_PX, pos.1 * BELT_TILE_SIZE_PX), es); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
self.visuals.for_each(|pos: (i32, i32), es| { |
|
|
|
|
r.render_entity( |
|
|
|
|
( |
|
|
|
|
pos.0 * BELT_TILE_SIZE_PX, |
|
|
|
|
pos.1 * BELT_TILE_SIZE_PX, |
|
|
|
|
), |
|
|
|
|
es, |
|
|
|
|
); |
|
|
|
|
r.render_entity((pos.0 * BELT_TILE_SIZE_PX, pos.1 * BELT_TILE_SIZE_PX), es); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
for (_ent, flying) in self.world.query_mut::<&mut FlyingItem>() { |
|
|
|
|