diff --git a/assets/svg/buildings/barracks.svg b/assets/svg/structures/barracks.svg similarity index 100% rename from assets/svg/buildings/barracks.svg rename to assets/svg/structures/barracks.svg diff --git a/assets/svg/buildings/construction_yard.svg b/assets/svg/structures/construction_yard.svg similarity index 100% rename from assets/svg/buildings/construction_yard.svg rename to assets/svg/structures/construction_yard.svg diff --git a/assets/svg/buildings/helipad.svg b/assets/svg/structures/helipad.svg similarity index 100% rename from assets/svg/buildings/helipad.svg rename to assets/svg/structures/helipad.svg diff --git a/assets/svg/buildings/power_plant.svg b/assets/svg/structures/power_plant.svg similarity index 100% rename from assets/svg/buildings/power_plant.svg rename to assets/svg/structures/power_plant.svg diff --git a/assets/svg/buildings/refinery.svg b/assets/svg/structures/refinery.svg similarity index 100% rename from assets/svg/buildings/refinery.svg rename to assets/svg/structures/refinery.svg diff --git a/assets/svg/buildings/war_factory.svg b/assets/svg/structures/war_factory.svg similarity index 100% rename from assets/svg/buildings/war_factory.svg rename to assets/svg/structures/war_factory.svg diff --git a/i-mic-rts.rb b/i-mic-rts.rb index d43bd12..21bf384 100755 --- a/i-mic-rts.rb +++ b/i-mic-rts.rb @@ -6,11 +6,11 @@ rescue LoadError require "cyberarm_engine" end -require "nokogiri" - require "json" require "socket" +require "nokogiri" + require_relative "lib/exts/string" require_relative "lib/version" diff --git a/lib/components/spawner.rb b/lib/components/spawner.rb index 9eb4ee0..3af4ff5 100644 --- a/lib/components/spawner.rb +++ b/lib/components/spawner.rb @@ -5,7 +5,7 @@ class IMICRTS return unless item - item.progress += 1 if @parent.component(:building).construction_complete? + item.progress += 1 if @parent.component(:structure).construction_complete? return unless item.progress >= item.entity.build_steps && !item.completed diff --git a/lib/components/building.rb b/lib/components/structure.rb similarity index 98% rename from lib/components/building.rb rename to lib/components/structure.rb index 26eea83..8301830 100644 --- a/lib/components/building.rb +++ b/lib/components/structure.rb @@ -1,5 +1,5 @@ class IMICRTS - class Building < Component + class Structure < Component def setup data.construction_progress ||= 0 data.construction_goal ||= Entity.get(@parent.name).build_steps @@ -18,7 +18,7 @@ class IMICRTS @text.x = @parent.position.x - @text.width / 2 @text.draw when :deconstruct - when :building + when :structure when :idle else raise "Unknown state!" diff --git a/lib/entities/buildings/barracks.rb b/lib/entities/structures/barracks.rb similarity index 77% rename from lib/entities/buildings/barracks.rb rename to lib/entities/structures/barracks.rb index 82e9adf..fb41dcc 100644 --- a/lib/entities/buildings/barracks.rb +++ b/lib/entities/structures/barracks.rb @@ -6,9 +6,9 @@ tiles = [ [false, :path, :path, :path, false], ] -IMICRTS::Entity.define_entity(:barracks, :building, 400, 40, "Builds and heals soldiers", tiles) do |entity| +IMICRTS::Entity.define_entity(:barracks, :structure, 400, 40, "Builds and heals soldiers", tiles) do |entity| unless entity.proto_entity - entity.has(:building) + entity.has(:structure) entity.has(:waypoint) entity.has(:spawner) entity.has(:build_queue) diff --git a/lib/entities/buildings/construction_yard.rb b/lib/entities/structures/construction_yard.rb similarity index 85% rename from lib/entities/buildings/construction_yard.rb rename to lib/entities/structures/construction_yard.rb index d52fa0e..91a2aaa 100644 --- a/lib/entities/buildings/construction_yard.rb +++ b/lib/entities/structures/construction_yard.rb @@ -6,9 +6,9 @@ tiles = [ [false, :path, :path, :path, false], ] -IMICRTS::Entity.define_entity(:construction_yard, :building, 2_000, 310, "Provides radar and builds construction workers", tiles) do |entity| +IMICRTS::Entity.define_entity(:construction_yard, :structure, 2_000, 310, "Provides radar and builds construction workers", tiles) do |entity| unless entity.proto_entity - entity.has(:building) + entity.has(:structure) entity.has(:waypoint) entity.has(:spawner) entity.has(:build_queue) @@ -48,7 +48,7 @@ IMICRTS::Entity.define_entity(:construction_yard, :building, 2_000, 310, "Provid entity.on_tick do - if entity.component(:building).construction_complete? + if entity.component(:structure).construction_complete? item = entity.component(:build_queue).queue.first entity.particle_emitters.each_with_index do |emitter, i| diff --git a/lib/entities/buildings/helipad.rb b/lib/entities/structures/helipad.rb similarity index 82% rename from lib/entities/buildings/helipad.rb rename to lib/entities/structures/helipad.rb index 2c24344..9f0b865 100644 --- a/lib/entities/buildings/helipad.rb +++ b/lib/entities/structures/helipad.rb @@ -6,9 +6,9 @@ tiles = [ [false, false, false, false, false], ] -IMICRTS::Entity.define_entity(:helipad, :building, 1_000, 100, "Builds and rearms aircraft", tiles) do |entity| +IMICRTS::Entity.define_entity(:helipad, :structure, 1_000, 100, "Builds and rearms aircraft", tiles) do |entity| unless entity.proto_entity - entity.has(:building) + entity.has(:structure) entity.has(:waypoint) entity.has(:spawner) entity.has(:build_queue) diff --git a/lib/entities/buildings/power_plant.rb b/lib/entities/structures/power_plant.rb similarity index 84% rename from lib/entities/buildings/power_plant.rb rename to lib/entities/structures/power_plant.rb index 0b22190..4752b5c 100644 --- a/lib/entities/buildings/power_plant.rb +++ b/lib/entities/structures/power_plant.rb @@ -6,9 +6,9 @@ tiles = [ [false, false, :path, false, false], ] -IMICRTS::Entity.define_entity(:power_plant, :building, 800, 45, "Generates power", tiles) do |entity| +IMICRTS::Entity.define_entity(:power_plant, :structure, 800, 45, "Generates power", tiles) do |entity| unless entity.proto_entity - entity.has(:building) + entity.has(:structure) end entity.radius = 24 @@ -37,7 +37,7 @@ IMICRTS::Entity.define_entity(:power_plant, :building, 800, 45, "Generates power entity.on_tick do # entity.produce_power - if entity.component(:building).construction_complete? + if entity.component(:structure).construction_complete? entity.particle_emitters.each do |emitter| emitter.emitting = true end diff --git a/lib/entities/buildings/refinery.rb b/lib/entities/structures/refinery.rb similarity index 81% rename from lib/entities/buildings/refinery.rb rename to lib/entities/structures/refinery.rb index 103daa9..efcabdf 100644 --- a/lib/entities/buildings/refinery.rb +++ b/lib/entities/structures/refinery.rb @@ -6,9 +6,9 @@ tiles = [ [false, false, :path, :path, false], ] -IMICRTS::Entity.define_entity(:refinery, :building, 1_400, 200, "Generates credits", tiles) do |entity| +IMICRTS::Entity.define_entity(:refinery, :structure, 1_400, 200, "Generates credits", tiles) do |entity| unless entity.proto_entity - entity.has(:building) + entity.has(:structure) end entity.radius = 44 @@ -28,7 +28,7 @@ IMICRTS::Entity.define_entity(:refinery, :building, 1_400, 200, "Generates credi entity.particle_emitters << IMICRTS::SmokeEmitter.new(position: p1, emitting: false) entity.on_tick do - if entity.component(:building).data.state == :idle + if entity.component(:structure).data.state == :idle entity.particle_emitters.each do |emitter| emitter.emitting = true diff --git a/lib/entities/buildings/war_factory.rb b/lib/entities/structures/war_factory.rb similarity index 86% rename from lib/entities/buildings/war_factory.rb rename to lib/entities/structures/war_factory.rb index b232ed8..862055b 100644 --- a/lib/entities/buildings/war_factory.rb +++ b/lib/entities/structures/war_factory.rb @@ -6,9 +6,9 @@ tiles = [ [false, :path, :path, :path, false], ] -IMICRTS::Entity.define_entity(:war_factory, :building, 2_000, 310, "Builds and repairs ground vehicles", tiles) do |entity| +IMICRTS::Entity.define_entity(:war_factory, :structure, 2_000, 310, "Builds and repairs ground vehicles", tiles) do |entity| unless entity.proto_entity - entity.has(:building) + entity.has(:structure) entity.has(:waypoint) entity.has(:spawner) entity.has(:build_queue) @@ -37,7 +37,7 @@ IMICRTS::Entity.define_entity(:war_factory, :building, 2_000, 310, "Builds and r entity.particle_emitters << IMICRTS::SmokeEmitter.new(position: p2, emitting: false) entity.on_tick do - if entity.component(:building).construction_complete? + if entity.component(:structure).construction_complete? item = entity.component(:build_queue).queue.first entity.particle_emitters.each do |pe| diff --git a/lib/entity.rb b/lib/entity.rb index c47bac3..5f67888 100644 --- a/lib/entity.rb +++ b/lib/entity.rb @@ -162,7 +162,7 @@ class IMICRTS data.assigned_construction_workers ||= 1 data.construction_speed ||= 1 - component(:building).construction_work(data.assigned_construction_workers * data.construction_speed) if component(:building) + component(:structure).construction_work(data.assigned_construction_workers * data.construction_speed) if component(:structure) end def on_tick(&block) diff --git a/lib/orders/construct.rb b/lib/orders/construct.rb index f757a13..20d46e7 100644 --- a/lib/orders/construct.rb +++ b/lib/orders/construct.rb @@ -1,13 +1,13 @@ -IMICRTS::Order.define_handler(IMICRTS::Order::CONSTRUCT, arguments: [:player_id, :vector, :building]) do |order, director| +IMICRTS::Order.define_handler(IMICRTS::Order::CONSTRUCT, arguments: [:player_id, :vector, :structure]) do |order, director| tile = director.map.tile_at(order.vector.x, order.vector.y) position = tile.position + director.map.tile_size / 2 ent = director.spawn_entity( - player_id: order.player_id, name: order.building, + player_id: order.player_id, name: order.structure, position: CyberarmEngine::Vector.new(position.x, position.y, IMICRTS::ZOrder::BUILDING) ) - director.each_tile(order.vector, order.building) do |tile, space_required| + director.each_tile(order.vector, order.structure) do |tile, space_required| if space_required == true tile.entity = ent else @@ -24,7 +24,7 @@ IMICRTS::Order.define_serializer(IMICRTS::Order::CONSTRUCT) do |order, director| # Order ID | Player ID | Vector X | Vector Y | Entity Name # char | char | integer | integer | string - [IMICRTS::Order::CONSTRUCT, order.player_id, order.vector.x, order.vector.y, order.building.to_s].pack("CCNNA*") + [IMICRTS::Order::CONSTRUCT, order.player_id, order.vector.x, order.vector.y, order.structure.to_s].pack("CCNNA*") end IMICRTS::Order.define_deserializer(IMICRTS::Order::CONSTRUCT) do |string, director| diff --git a/lib/orders/construction_complete.rb b/lib/orders/construction_complete.rb index 22f6e8f..da56e0b 100644 --- a/lib/orders/construction_complete.rb +++ b/lib/orders/construction_complete.rb @@ -1,7 +1,7 @@ IMICRTS::Order.define_handler(IMICRTS::Order::CONSTRUCTION_COMPLETE, arguments: [:player_id, :entity_id]) do |order, director| entity = director.player(order.player_id).entity(order.entity_id) - entity.component(:building).data.construction_complete = true + entity.component(:structure).data.construction_complete = true end IMICRTS::Order.define_serializer(IMICRTS::Order::CONSTRUCTION_COMPLETE) do |order, director| diff --git a/lib/states/game.rb b/lib/states/game.rb index 65bf32f..c0c0e2e 100644 --- a/lib/states/game.rb +++ b/lib/states/game.rb @@ -59,8 +59,8 @@ class IMICRTS player_id: player.id, name: :construction_yard, position: CyberarmEngine::Vector.new(player.spawnpoint.x, player.spawnpoint.y, ZOrder::BUILDING) ) - construction_yard.component(:building).data.construction_progress = Entity.get(construction_yard.name).build_steps - construction_yard.component(:building).data.construction_complete = true + construction_yard.component(:structure).data.construction_progress = Entity.get(construction_yard.name).build_steps + construction_yard.component(:structure).data.construction_complete = true @director.each_tile(@director.map.world_to_grid(construction_yard.position), construction_yard.name) do |tile, space_required| if space_required == true tile.entity = construction_yard