Building units now uses orders 😃

This commit is contained in:
2021-01-01 14:25:44 -06:00
parent 74458dbfd0
commit 5f301337b4
35 changed files with 171 additions and 100 deletions

View File

@@ -2,13 +2,13 @@ class IMICRTS
class BuildQueue < Component
attr_reader :queue
Item = Struct.new(:entity, :progress)
Item = Struct.new(:entity, :progress, :completed)
def setup
@queue = []
end
def add(type)
@queue << Item.new(Entity.get(type), 0.0)
@queue << Item.new(Entity.get(type), 0.0, false)
end
end
end

View File

@@ -2,7 +2,7 @@ class IMICRTS
class Building < Component
def setup
data.construction_progress ||= 0
data.construction_goal ||= 100
data.construction_goal ||= Entity.get(@parent.name).build_steps
@text = CyberarmEngine::Text.new("", y: @parent.position.y, z: Float::INFINITY, size: 12)
data.state = :construct # deconstruct, building, idle
@@ -48,8 +48,8 @@ class IMICRTS
end
def draw_construction
@fencing ||= Gosu::Image.new(IMICRTS::ASSETS_PATH + "/fencing/fencing.png")
@fencing_edge ||= Gosu::Image.new(IMICRTS::ASSETS_PATH + "/fencing/fencing_edge.png")
@fencing ||= get_image(IMICRTS::ASSETS_PATH + "/fencing/fencing.png")
@fencing_edge ||= get_image(IMICRTS::ASSETS_PATH + "/fencing/fencing_edge.png")
tiles = []
each_tile(@parent.position / @parent.director.map.tile_size) do |tile, data, x, y|

View File

@@ -16,12 +16,12 @@ class IMICRTS
end
def rotate_towards(vector)
_angle = Gosu.angle(@parent.position.x, @parent.position.y, vector.x, vector.y)
a = (360.0 + (_angle - @parent.angle)) % 360.0
angle = Gosu.angle(@parent.position.x, @parent.position.y, vector.x, vector.y)
a = (360.0 + (angle - @parent.angle)) % 360.0
# FIXME: Fails if vector is directly behind entity
if a.round == 180
@parent.angle = (_angle + 180.0) % 360.0
@parent.angle = (angle + 180.0) % 360.0
elsif a < 180
@parent.angle -= 1.0
else

View File

@@ -17,7 +17,9 @@ class IMICRTS
action.label = ent.name.to_s.split("_").map{ |s| s.capitalize }.join(" ")
action.description = "Cost: #{ent.cost}\n#{ent.description}"
action.block = proc { @parent.component(:build_queue).add(data[:entity]) }
action.block = proc do
@parent.director.schedule_order(IMICRTS::Order::BUILD_UNIT, @parent.player.id, @parent.id, data[:entity])
end
when :set_tool
ent = IMICRTS::Entity.get(data[:entity])

View File

@@ -1,21 +1,17 @@
class IMICRTS
class Spawner < Component
def tick(tick_id)
# TODO: Ensure that a build order is created before working on entity
item = @parent.component(:build_queue).queue.first
if item
item.progress += 1
return unless item
if item.progress >= 100 # TODO: Define work units required for construction
@parent.component(:build_queue).queue.shift
item.progress += 1
spawn_point = @parent.position.clone
spawn_point.y += 96 # TODO: Use one of entity's reserved tiles for spawning
if item.progress >= item.entity.build_steps
unless item.completed
item.completed = true
ent = @parent.director.spawn_entity(player_id: @parent.player.id, name: item.entity.name, position: spawn_point)
ent.target = @parent.component(:waypoint).waypoint if @parent.component(:waypoint)
@parent.director.schedule_order(IMICRTS::Order::BUILD_UNIT_COMPLETE, @parent.player.id, @parent.id)
end
end
end

View File

@@ -7,15 +7,15 @@ class IMICRTS
end
def body_image=(image)
@body_image = Gosu::Image.new("#{IMICRTS::ASSETS_PATH}/#{image}", retro: true)
@body_image = get_image("#{IMICRTS::ASSETS_PATH}/#{image}", retro: true)
end
def shell_image=(image)
@shell_image = Gosu::Image.new("#{IMICRTS::ASSETS_PATH}/#{image}", retro: true)
@shell_image = get_image("#{IMICRTS::ASSETS_PATH}/#{image}", retro: true)
end
def overlay_image=(image)
@overlay_image = Gosu::Image.new("#{IMICRTS::ASSETS_PATH}/#{image}", retro: true)
@overlay_image = get_image("#{IMICRTS::ASSETS_PATH}/#{image}", retro: true)
end
def render
@@ -28,8 +28,11 @@ class IMICRTS
def draw
render unless @render
@angle += 0.1
@render.draw_rot(@parent.position.x, @parent.position.y, @parent.position.z, @angle, @center.x, @center.y)
end
def update
@angle = @parent.angle
end
end
end

View File

@@ -3,6 +3,7 @@ class IMICRTS
def setup
@waypoint = @parent.position.clone
@waypoint.y += @parent.director.map.tile_size
@waypoint_color = 0xffffff00
end
def set(vector)
@@ -17,11 +18,11 @@ class IMICRTS
return unless @parent.player.selected_entities.include?(@parent)
Gosu.draw_line(
@parent.position.x, @parent.position.y, @parent.player.color,
@waypoint.x, @waypoint.y, @parent.player.color, ZOrder::ENTITY_GIZMOS
@parent.position.x, @parent.position.y, @waypoint_color,
@waypoint.x, @waypoint.y, @waypoint_color, ZOrder::ENTITY_GIZMOS
)
Gosu.draw_circle(@waypoint.x, @waypoint.y, 4, 9, @parent.player.color, ZOrder::ENTITY_GIZMOS)
Gosu.draw_circle(@waypoint.x, @waypoint.y, 4, 9, @waypoint_color, ZOrder::ENTITY_GIZMOS)
end
end
end