diff --git a/lib/entities/buildings/barracks.rb b/lib/entities/buildings/barracks.rb index e29434f..29ffbac 100644 --- a/lib/entities/buildings/barracks.rb +++ b/lib/entities/buildings/barracks.rb @@ -3,7 +3,7 @@ tiles = [ [false, true, true, true, false], [false, true, true, true, false], [false, true, true, true, false], - [false, true, true, true, false], + [false, :path, :path, :path, false], ] IMICRTS::Entity.define_entity(:barracks, :building, 400, "Builds and soldiers", tiles) do |entity| diff --git a/lib/entities/buildings/construction_yard.rb b/lib/entities/buildings/construction_yard.rb index d4756e7..ab05f06 100644 --- a/lib/entities/buildings/construction_yard.rb +++ b/lib/entities/buildings/construction_yard.rb @@ -1,9 +1,9 @@ tiles = [ [false, false, false, false, false], - [false, true, true, true, false], - [false, true, true, true, false], - [false, true, true, true, false], - [false, true, true, true, false], + [false, true, true, true, false], + [false, true, true, true, false], + [false, true, true, true, false], + [false, :path, :path, :path, false], ] IMICRTS::Entity.define_entity(:construction_yard, :building, 2_000, "Provides radar and builds construction workers", tiles) do |entity| diff --git a/lib/entities/buildings/power_plant.rb b/lib/entities/buildings/power_plant.rb index eb5b599..ea371a6 100644 --- a/lib/entities/buildings/power_plant.rb +++ b/lib/entities/buildings/power_plant.rb @@ -3,7 +3,7 @@ tiles = [ [false, false, true, false, false], [false, false, true, false, false], [false, false, true, false, false], - [false, false, true, false, false], + [false, false, :path, false, false], ] IMICRTS::Entity.define_entity(:power_plant, :building, 800, "Generates power", tiles) do |entity| diff --git a/lib/entities/buildings/refinery.rb b/lib/entities/buildings/refinery.rb index 34fbcc8..9e6d9ca 100644 --- a/lib/entities/buildings/refinery.rb +++ b/lib/entities/buildings/refinery.rb @@ -3,7 +3,7 @@ tiles = [ [false, true, true, false, false], [false, true, true, true, false], [false, true, true, true, false], - [false, false, true, true, false], + [false, false, :path, :path, false], ] IMICRTS::Entity.define_entity(:refinery, :building, 1_400, "Generates credits", tiles) do |entity| diff --git a/lib/entities/buildings/war_factory.rb b/lib/entities/buildings/war_factory.rb index a2438ae..69d8490 100644 --- a/lib/entities/buildings/war_factory.rb +++ b/lib/entities/buildings/war_factory.rb @@ -1,9 +1,9 @@ tiles = [ [false, false, false, false, false], - [false, true, true, true, false], - [false, true, true, true, false], - [false, true, true, true, false], - [false, true, true, true, false], + [false, true, true, true, false], + [false, true, true, true, false], + [false, true, true, true, false], + [false, :path, :path, :path, false], ] IMICRTS::Entity.define_entity(:war_factory, :building, 2_000, "Builds units", tiles) do |entity| diff --git a/lib/map.rb b/lib/map.rb index bc55c62..239673d 100644 --- a/lib/map.rb +++ b/lib/map.rb @@ -104,7 +104,7 @@ class IMICRTS end class Tile - attr_accessor :position, :grid_position, :image, :visible, :entity, :type + attr_accessor :position, :grid_position, :image, :visible, :entity, :reserved, :type def initialize(position:, image:, visible:, type:, tile_size:) @position = position @grid_position = position.clone @@ -114,6 +114,7 @@ class IMICRTS @image = image @visible = visible @entity = nil + @reserved = nil @type = type end end diff --git a/lib/tools/place_entity.rb b/lib/tools/place_entity.rb index fd56f43..de396e3 100644 --- a/lib/tools/place_entity.rb +++ b/lib/tools/place_entity.rb @@ -10,8 +10,8 @@ class IMICRTS end def draw - each_tile(vector_to_grid(@game.window.mouse)) do |x, y, tile| - if tile.entity || tile.type != :ground || @director.map.ore_at(x, y) # tile unavailable + each_tile(vector_to_grid(@game.window.mouse)) do |tile, _data, x, y| + if tile.entity || tile.reserved || tile.type != :ground || @director.map.ore_at(x, y) # tile unavailable Gosu.draw_rect( tile.position.x + 2, tile.position.y + 2, @director.map.tile_size - 4, @director.map.tile_size - 4, @@ -57,8 +57,12 @@ class IMICRTS position: CyberarmEngine::Vector.new(position.x, position.y, ZOrder::BUILDING) ) - each_tile(vector) do |x, y, tile| - tile.entity = ent + each_tile(vector) do |tile, space_required| + if space_required == true + tile.entity = ent + else + tile.reserved = ent + end end cancel_tool @@ -73,8 +77,8 @@ class IMICRTS ent = Entity.get(@entity) origin = (tile.grid_position - 2) - each_tile(vector) do |x, y, tile| - if tile.entity || tile.type != :ground || @director.map.ore_at(x, y) + each_tile(vector) do |tile, _data, x, y| + if tile.entity || tile.reserved || tile.type != :ground || @director.map.ore_at(x, y) useable = false break end @@ -97,7 +101,7 @@ class IMICRTS other_tile = @director.map.tile_at(origin.x + x, origin.y + y) if other_tile - block.call(origin.x + x, origin.y + y, other_tile) + block.call(other_tile, space_required, origin.x + x, origin.y + y) end end end