diff --git a/source/main.adb b/source/main.adb index dcab674..5a37788 100644 --- a/source/main.adb +++ b/source/main.adb @@ -365,8 +365,8 @@ begin world.configure; --~ai.configure; - world.make (biome.grass, 640, 480, 8); - world.add_chad (player); + world.make (biome.swamp, 640, 480, 480, 240, 60, 600, 600, 8); + world.insert_chad (player); core.dash; core.echo (core.success, "Successfully initialized game data, entering main gameplay loop."); diff --git a/source/world.adb b/source/world.adb index f530964..17962a0 100644 --- a/source/world.adb +++ b/source/world.adb @@ -10,12 +10,6 @@ package body world is lake_count : constant natural := 6; - landmark_limit : constant integer := 480; - location_limit : constant integer := 240; - construction_limit : constant natural := 120; - equipment_limit : constant natural := 300; - unit_limit : constant natural := 600; - target : core.vector := (-1, -1); dark : core.sprite; @@ -122,20 +116,78 @@ package body world is ------------------------------------------------------------------------------------------ - procedure make (index : in biome.enumeration; width, height, chad_limit : in natural) is + function random_landmark return landmark.information is + this : landmark.information; + begin + this.index := landmark.enumeration'val (core.random (0, landmark.count - 1)); + <> + this.x := core.random (6, map.width - 6); + this.y := core.random (6, map.height - 6); + -- + if map.clips (this.x, this.y) then + goto repeat_landmark_generation; + end if; + -- + return this; + end random_landmark; + + ------------------------------------------------------------------------------------------ + + procedure insert_landmark (data : in landmark.information) is + begin + core.echo_when (map.landmark_count.value = map.landmark_count.limit, core.failure, "Can't add new landmark, limit reached."); + core.increment (map.landmark_count.value); + -- + map.landmarks (map.landmark_count.value) := data; + -- + if landmark.description (map.landmarks (map.landmark_count.value).index).clip then + declare reach_x : constant natural := landmark.game (map.landmarks (map.landmark_count.value).index).width / core.base; + reach_y : constant natural := landmark.game (map.landmarks (map.landmark_count.value).index).height / core.base; + begin + for x in 0 .. reach_x - 1 loop + for y in 0 .. reach_y - 1 loop + map.clips (map.landmarks (map.landmark_count.value).x + x, map.landmarks (map.landmark_count.value).y + y) := true; + end loop; + end loop; + end; + end if; + end insert_landmark; + + ------------------------------------------------------------------------------------------ + + procedure insert_chad (data : in chad.information) is + begin + core.echo_when (map.chad_count.value = map.chad_count.limit, core.failure, "Can't add new chad, limit reached."); + core.increment (map.chad_count.value); + -- + map.chads (map.chad_count.value) := data; + end insert_chad; + + ------------------------------------------------------------------------------------------ + + procedure make (index : in biome.enumeration; width, height, landmark_limit, location_limit, construction_limit, equipment_limit, unit_limit, chad_limit : in natural) is begin core.echo (core.comment, "-- Procedurally generating new map..."); -- - core.echo (core.comment, "-- -- Map type : " & index'image); - core.echo (core.comment, "-- -- Map width :" & width'image); - core.echo (core.comment, "-- -- Map height :" & height'image); - core.echo (core.comment, "-- -- Landmark count :" & landmark_limit'image); + core.echo (core.comment, "-- -- Map type : " & index'image); + core.echo (core.comment, "-- -- Map width :" & width'image); + core.echo (core.comment, "-- -- Map height :" & height'image); + core.echo (core.comment, "-- -- Landmark count :" & landmark_limit'image); + core.echo (core.comment, "-- -- Location count :" & location_limit'image); + core.echo (core.comment, "-- -- Construction count :" & construction_limit'image); + core.echo (core.comment, "-- -- Equipment count :" & equipment_limit'image); + core.echo (core.comment, "-- -- Unit count :" & unit_limit'image); + core.echo (core.comment, "-- -- Chad count :" & chad_limit'image); -- - map.kind := index; - map.width := width; - map.height := height; - map.chad_limit := chad_limit; - map.chad_count := 0; + map.kind := index; + map.width := width; + map.height := height; + map.landmark_count := (0, landmark_limit); + map.location_count := (0, location_limit); + map.construction_count := (0, construction_limit); + map.equipment_count := (0, equipment_limit); + map.unit_count := (0, unit_limit); + map.chad_count := (0, chad_limit); -- map.tiles := new integer_matrix (0 .. map.width - 1, 0 .. map.height - 1); map.clips := new boolean_matrix (0 .. map.width - 1, 0 .. map.height - 1); @@ -145,7 +197,7 @@ package body world is map.constructions := new construction.informations (1 .. construction_limit); map.equipments := new equipment.informations (1 .. equipment_limit); map.units := new unit.informations (1 .. unit_limit); - map.chads := new chad.informations (1 .. map.chad_limit); + map.chads := new chad.informations (1 .. chad_limit); -- for x in 0 .. width - 1 loop for y in 0 .. height - 1 loop @@ -172,26 +224,7 @@ package body world is end loop; -- for index in 1 .. landmark_limit loop - map.landmarks (index).index := landmark.enumeration'val (core.random (0, landmark.count - 1)); - <> - map.landmarks (index).x := core.random (6, map.width - 6); - map.landmarks (index).y := core.random (6, map.height - 6); - -- - if map.clips (map.landmarks (index).x, map.landmarks (index).y) then - goto repeat_landmark_generation; - end if; - -- - if landmark.description (map.landmarks (index).index).clip then - declare reach_x : constant natural := landmark.game (map.landmarks (index).index).width / core.base; - reach_y : constant natural := landmark.game (map.landmarks (index).index).height / core.base; - begin - for x in 0 .. reach_x - 1 loop - for y in 0 .. reach_y - 1 loop - map.clips (map.landmarks (index).x + x, map.landmarks (index).y + y) := true; - end loop; - end loop; - end; - end if; + insert_landmark (random_landmark); end loop; -- for index in 1 .. location_limit loop @@ -278,8 +311,13 @@ package body world is core.io.write (file, biome.enumeration'pos (map.kind)); core.io.write (file, map.width); core.io.write (file, map.height); - core.io.write (file, map.chad_count); - core.io.write (file, map.chad_limit); + -- + core.save_point (file, map.landmark_count); + core.save_point (file, map.location_count); + core.save_point (file, map.construction_count); + core.save_point (file, map.equipment_count); + core.save_point (file, map.unit_count); + core.save_point (file, map.chad_count); -- for x in 0 .. map.width - 1 loop for y in 0 .. map.height - 1 loop @@ -289,26 +327,26 @@ package body world is end loop; end loop; -- - for index in 1 .. landmark_limit loop core.io.write (file, landmark.enumeration'pos (map.landmarks (index).index)); end loop; - for index in 1 .. location_limit loop core.io.write (file, location.enumeration'pos (map.locations (index).index)); end loop; - for index in 1 .. construction_limit loop core.io.write (file, construction.enumeration'pos (map.constructions (index).index)); end loop; - for index in 1 .. equipment_limit loop core.io.write (file, equipment.enumeration'pos (map.equipments (index).index)); end loop; - for index in 1 .. unit_limit loop core.io.write (file, unit.enumeration'pos (map.units (index).index)); end loop; + for index in 1 .. map.landmark_count.limit loop core.io.write (file, landmark.enumeration'pos (map.landmarks (index).index)); end loop; + for index in 1 .. map.location_count.limit loop core.io.write (file, location.enumeration'pos (map.locations (index).index)); end loop; + for index in 1 .. map.construction_count.limit loop core.io.write (file, construction.enumeration'pos (map.constructions (index).index)); end loop; + for index in 1 .. map.equipment_count.limit loop core.io.write (file, equipment.enumeration'pos (map.equipments (index).index)); end loop; + for index in 1 .. map.unit_count.limit loop core.io.write (file, unit.enumeration'pos (map.units (index).index)); end loop; -- - for index in 1 .. location_limit loop core.io.write (file, boolean'pos (map.locations (index).used)); end loop; - for index in 1 .. unit_limit loop core.io.write (file, map.units (index).count); end loop; - for index in 1 .. unit_limit loop core.io.write (file, boolean'pos (map.units (index).enemy)); end loop; + for index in 1 .. map.location_count.limit loop core.io.write (file, boolean'pos (map.locations (index).used)); end loop; + for index in 1 .. map.unit_count.limit loop core.io.write (file, map.units (index).count); end loop; + for index in 1 .. map.unit_count.limit loop core.io.write (file, boolean'pos (map.units (index).enemy)); end loop; -- - for index in 1 .. landmark_limit loop core.io.write (file, map.landmarks (index).x); end loop; - for index in 1 .. landmark_limit loop core.io.write (file, map.landmarks (index).y); end loop; - for index in 1 .. location_limit loop core.io.write (file, map.locations (index).x); end loop; - for index in 1 .. location_limit loop core.io.write (file, map.locations (index).y); end loop; - for index in 1 .. construction_limit loop core.io.write (file, map.constructions (index).x); end loop; - for index in 1 .. construction_limit loop core.io.write (file, map.constructions (index).y); end loop; - for index in 1 .. equipment_limit loop core.io.write (file, map.equipments (index).x); end loop; - for index in 1 .. equipment_limit loop core.io.write (file, map.equipments (index).y); end loop; - for index in 1 .. unit_limit loop core.io.write (file, map.units (index).x); end loop; - for index in 1 .. unit_limit loop core.io.write (file, map.units (index).y); end loop; + for index in 1 .. map.landmark_count.limit loop core.io.write (file, map.landmarks (index).x); end loop; + for index in 1 .. map.landmark_count.limit loop core.io.write (file, map.landmarks (index).y); end loop; + for index in 1 .. map.location_count.limit loop core.io.write (file, map.locations (index).x); end loop; + for index in 1 .. map.location_count.limit loop core.io.write (file, map.locations (index).y); end loop; + for index in 1 .. map.construction_count.limit loop core.io.write (file, map.constructions (index).x); end loop; + for index in 1 .. map.construction_count.limit loop core.io.write (file, map.constructions (index).y); end loop; + for index in 1 .. map.equipment_count.limit loop core.io.write (file, map.equipments (index).x); end loop; + for index in 1 .. map.equipment_count.limit loop core.io.write (file, map.equipments (index).y); end loop; + for index in 1 .. map.unit_count.limit loop core.io.write (file, map.units (index).x); end loop; + for index in 1 .. map.unit_count.limit loop core.io.write (file, map.units (index).y); end loop; -- core.io.write (file, chad.enumeration'pos (map.chads (1).index)); core.io.write (file, core.animation'pos (map.chads (1).state)); @@ -361,8 +399,13 @@ package body world is core.io.read (file, this); map.kind := biome.enumeration'val (this); core.io.read (file, map.width); core.io.read (file, map.height); - core.io.read (file, map.chad_count); - core.io.read (file, map.chad_limit); + -- + core.load_point (file, map.landmark_count); + core.load_point (file, map.location_count); + core.load_point (file, map.construction_count); + core.load_point (file, map.equipment_count); + core.load_point (file, map.unit_count); + core.load_point (file, map.chad_count); -- for x in 0 .. map.width - 1 loop for y in 0 .. map.height - 1 loop @@ -372,26 +415,26 @@ package body world is end loop; end loop; -- - for index in 1 .. landmark_limit loop core.io.read (file, this); map.landmarks (index).index := landmark.enumeration'val (this); end loop; - for index in 1 .. location_limit loop core.io.read (file, this); map.locations (index).index := location.enumeration'val (this); end loop; - for index in 1 .. construction_limit loop core.io.read (file, this); map.constructions (index).index := construction.enumeration'val (this); end loop; - for index in 1 .. equipment_limit loop core.io.read (file, this); map.equipments (index).index := equipment.enumeration'val (this); end loop; - for index in 1 .. unit_limit loop core.io.read (file, this); map.units (index).index := unit.enumeration'val (this); end loop; + for index in 1 .. map.landmark_count.limit loop core.io.read (file, this); map.landmarks (index).index := landmark.enumeration'val (this); end loop; + for index in 1 .. map.location_count.limit loop core.io.read (file, this); map.locations (index).index := location.enumeration'val (this); end loop; + for index in 1 .. map.construction_count.limit loop core.io.read (file, this); map.constructions (index).index := construction.enumeration'val (this); end loop; + for index in 1 .. map.equipment_count.limit loop core.io.read (file, this); map.equipments (index).index := equipment.enumeration'val (this); end loop; + for index in 1 .. map.unit_count.limit loop core.io.read (file, this); map.units (index).index := unit.enumeration'val (this); end loop; -- - for index in 1 .. location_limit loop core.io.read (file, this); map.locations (index).used := boolean'val (this); end loop; - for index in 1 .. unit_limit loop core.io.read (file, this); map.units (index).count := this; end loop; - for index in 1 .. unit_limit loop core.io.read (file, this); map.units (index).enemy := boolean'val (this); end loop; + for index in 1 .. map.location_count.limit loop core.io.read (file, this); map.locations (index).used := boolean'val (this); end loop; + for index in 1 .. map.unit_count.limit loop core.io.read (file, this); map.units (index).count := this; end loop; + for index in 1 .. map.unit_count.limit loop core.io.read (file, this); map.units (index).enemy := boolean'val (this); end loop; -- - for index in 1 .. landmark_limit loop core.io.read (file, map.landmarks (index).x); end loop; - for index in 1 .. landmark_limit loop core.io.read (file, map.landmarks (index).y); end loop; - for index in 1 .. location_limit loop core.io.read (file, map.locations (index).x); end loop; - for index in 1 .. location_limit loop core.io.read (file, map.locations (index).y); end loop; - for index in 1 .. construction_limit loop core.io.read (file, map.constructions (index).x); end loop; - for index in 1 .. construction_limit loop core.io.read (file, map.constructions (index).y); end loop; - for index in 1 .. equipment_limit loop core.io.read (file, map.equipments (index).x); end loop; - for index in 1 .. equipment_limit loop core.io.read (file, map.equipments (index).y); end loop; - for index in 1 .. unit_limit loop core.io.read (file, map.units (index).x); end loop; - for index in 1 .. unit_limit loop core.io.read (file, map.units (index).y); end loop; + for index in 1 .. map.landmark_count.limit loop core.io.read (file, map.landmarks (index).x); end loop; + for index in 1 .. map.landmark_count.limit loop core.io.read (file, map.landmarks (index).y); end loop; + for index in 1 .. map.location_count.limit loop core.io.read (file, map.locations (index).x); end loop; + for index in 1 .. map.location_count.limit loop core.io.read (file, map.locations (index).y); end loop; + for index in 1 .. map.construction_count.limit loop core.io.read (file, map.constructions (index).x); end loop; + for index in 1 .. map.construction_count.limit loop core.io.read (file, map.constructions (index).y); end loop; + for index in 1 .. map.equipment_count.limit loop core.io.read (file, map.equipments (index).x); end loop; + for index in 1 .. map.equipment_count.limit loop core.io.read (file, map.equipments (index).y); end loop; + for index in 1 .. map.unit_count.limit loop core.io.read (file, map.units (index).x); end loop; + for index in 1 .. map.unit_count.limit loop core.io.read (file, map.units (index).y); end loop; -- core.io.read (file, this); map.chads (1).index := chad.enumeration'val (this); core.io.read (file, this); map.chads (1).state := core.animation'val (this); @@ -524,7 +567,7 @@ package body world is end loop; end loop; -- - for index in 1 .. landmark_limit loop + for index in 1 .. map.landmark_count.limit loop core.render_image (data => landmark.game (map.landmarks (index).index), x => map.landmarks (index).x * core.base, y => map.landmarks (index).y * core.base, @@ -534,7 +577,7 @@ package body world is height => landmark.game (map.landmarks (index).index).height); end loop; -- - for index in 1 .. location_limit loop + for index in 1 .. map.location_count.limit loop core.render_image (data => location.game (map.locations (index).index), x => map.locations (index).x * core.base, y => map.locations (index).y * core.base, @@ -544,7 +587,7 @@ package body world is height => location.game (map.locations (index).index).height); end loop; -- - for index in 1 .. construction_limit loop + for index in 1 .. map.construction_count.limit loop core.render_image (data => construction.game (map.constructions (index).index), x => map.constructions (index).x * core.base, y => map.constructions (index).y * core.base, @@ -554,7 +597,7 @@ package body world is height => construction.game (map.constructions (index).index).height); end loop; -- - for index in 1 .. equipment_limit loop + for index in 1 .. map.equipment_count.limit loop core.render_image (data => equipment.game (map.equipments (index).index), x => map.equipments (index).x * core.base, y => map.equipments (index).y * core.base, @@ -588,16 +631,6 @@ package body world is ------------------------------------------------------------------------------------------ - procedure add_chad (data : in chad.information) is - begin - core.echo_when (map.chad_count = map.chad_limit, core.failure, "Can't add new chad, limit reached."); - core.increment (map.chad_count); - -- - map.chads (map.chad_count) := data; - end add_chad; - - ------------------------------------------------------------------------------------------ - procedure resource_cheat_1 is begin core.increment (map.chads (1).resources (resource.gold).value, 20); end resource_cheat_1; procedure resource_cheat_2 is begin core.increment (map.chads (1).resources (resource.wood).value, 10); end resource_cheat_2; procedure resource_cheat_3 is begin core.increment (map.chads (1).resources (resource.stone).value, 10); end resource_cheat_3; @@ -854,7 +887,7 @@ package body world is begin time := core.time; -- - for index in 1 .. landmark_limit loop + for index in 1 .. map.landmark_count.limit loop if map.views (map.landmarks (index).x, map.landmarks (index).y) and map.landmarks (index).x > view_from.x and map.landmarks (index).x < view_from.x + view_to.x and map.landmarks (index).y > view_from.y and map.landmarks (index).y < view_from.y + view_to.y then @@ -885,7 +918,7 @@ package body world is begin time := core.time; -- - for index in 1 .. location_limit loop + for index in 1 .. map.location_count.limit loop if map.views (map.locations (index).x, map.locations (index).y) and map.locations (index).x > view_from.x and map.locations (index).x < view_from.x + view_to.x and map.locations (index).y > view_from.y and map.locations (index).y < view_from.y + view_to.y then @@ -965,7 +998,7 @@ package body world is begin time := core.time; -- - for index in 1 .. construction_limit loop + for index in 1 .. map.construction_count.limit loop if map.views (map.constructions (index).x, map.constructions (index).y) and map.constructions (index).x > view_from.x and map.constructions (index).x < view_from.x + view_to.x and map.constructions (index).y > view_from.y and map.constructions (index).y < view_from.y + view_to.y then @@ -999,7 +1032,7 @@ package body world is begin time := core.time; -- - for index in 1 .. equipment_limit loop + for index in 1 .. map.equipment_count.limit loop if map.views (map.equipments (index).x, map.equipments (index).y) and map.equipments (index).x > view_from.x and map.equipments (index).x < view_from.x + view_to.x and map.equipments (index).y > view_from.y and map.equipments (index).y < view_from.y + view_to.y then @@ -1099,7 +1132,7 @@ package body world is begin time := core.time; -- - for index in 1 .. unit_limit loop + for index in 1 .. map.unit_count.limit loop if map.views (map.units (index).x, map.units (index).y) and map.units (index).x > view_from.x and map.units (index).x < view_from.x + view_to.x and map.units (index).y > view_from.y and map.units (index).y < view_from.y + view_to.y then @@ -1113,7 +1146,7 @@ package body world is end if; end loop; -- - for index in 1 .. map.chad_count loop + for index in 1 .. map.chad_count.value loop if map.views (map.chads (index).x, map.chads (index).y) then core.draw (data => chad.sprite (map.chads (index).index), x => offset.x + (map.chads (index).x - core.camera.x) * core.base * core.zoom, diff --git a/source/world.ads b/source/world.ads index b4589d6..317653a 100644 --- a/source/world.ads +++ b/source/world.ads @@ -16,20 +16,24 @@ package world is type boolean_matrix is array (natural range <>, natural range <>) of boolean; type definition is record - kind : biome.enumeration; - width : natural; - height : natural; - chad_count : natural; - chad_limit : natural; - tiles : access integer_matrix; - clips : access boolean_matrix; - views : access boolean_matrix; - landmarks : access landmark.informations; - locations : access location.informations; - constructions : access construction.informations; - equipments : access equipment.informations; - units : access unit.informations; - chads : access chad.informations; + kind : biome.enumeration; + width : natural; + height : natural; + tiles : access integer_matrix; + clips : access boolean_matrix; + views : access boolean_matrix; + landmark_count : core.point; + location_count : core.point; + construction_count : core.point; + equipment_count : core.point; + unit_count : core.point; + chad_count : core.point; + landmarks : access landmark.informations; + locations : access location.informations; + constructions : access construction.informations; + equipments : access equipment.informations; + units : access unit.informations; + chads : access chad.informations; end record; ------------------------------------------------------------------------------------------ @@ -44,7 +48,12 @@ package world is function equipment_valid (data : in equipment.enumeration) return boolean; - procedure make (index : in biome.enumeration; width, height, chad_limit : in natural); + function random_landmark return landmark.information; + + procedure insert_landmark (data : in landmark.information); + procedure insert_chad (data : in chad.information); + + procedure make (index : in biome.enumeration; width, height, landmark_limit, location_limit, construction_limit, equipment_limit, unit_limit, chad_limit : in natural); procedure save (file_name : in string); procedure load (file_name : in string); @@ -57,8 +66,6 @@ package world is function map_is_revealed return boolean; - procedure add_chad (data : in chad.information); - procedure draw_unit (data : in unit.enumeration; state : in core.animation; x, y, factor : in integer); procedure show_unit;