Refactored world generation and randomization...

This commit is contained in:
Ognjen Milan Robovic 2024-06-10 07:06:25 -04:00
parent d89fb6f944
commit bbd68657c5
2 changed files with 153 additions and 82 deletions

View File

@ -133,20 +133,92 @@ package body world is
------------------------------------------------------------------------------------------
function random_location return location.information is
this : location.information;
begin
this.index := location.enumeration'val (core.random (0, location.count - 1));
this.used := false;
<<repeat_location_generation>>
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_location_generation;
end if;
--
return this;
end random_location;
------------------------------------------------------------------------------------------
function random_construction return construction.information is
this : construction.information;
begin
this.index := construction.enumeration'val (core.random (0, construction.count - 1));
<<repeat_construction_generation>>
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_construction_generation;
end if;
--
return this;
end random_construction;
------------------------------------------------------------------------------------------
function random_equipment return equipment.information is
this : equipment.information;
begin
this.index := equipment.enumeration'val (core.random (0, equipment.count - 1));
<<repeat_equipment_generation>>
this.x := core.random (0, map.width - 1);
this.y := core.random (0, map.height - 1);
--
if map.clips (this.x, this.y) then
goto repeat_equipment_generation;
end if;
--
return this;
end random_equipment;
------------------------------------------------------------------------------------------
function random_unit return unit.information is
this : unit.information;
begin
this.index := unit.enumeration'val (core.random (1, unit.count - 1)); -- none
this.count := core.random (1, 10);
this.enemy := true;
<<repeat_unit_generation>>
this.x := core.random (0, map.width - 1);
this.y := core.random (0, map.height - 1);
--
if map.clips (this.x, this.y) then
goto repeat_unit_generation;
end if;
--
return this;
end random_unit;
------------------------------------------------------------------------------------------
procedure insert_landmark (data : in landmark.information) is
this : constant natural := map.landmark_count.value + 1;
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;
map.landmarks (this) := 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;
if landmark.description (map.landmarks (this).index).clip then
declare reach_x : constant natural := landmark.game (map.landmarks (this).index).width / core.base;
reach_y : constant natural := landmark.game (map.landmarks (this).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;
map.clips (map.landmarks (this).x + x, map.landmarks (this).y + y) := true;
end loop;
end loop;
end;
@ -155,6 +227,66 @@ package body world is
------------------------------------------------------------------------------------------
procedure insert_location (data : in location.information) is
this : constant natural := map.location_count.value + 1;
begin
core.echo_when (map.location_count.value = map.location_count.limit, core.failure, "Can't add new location, limit reached.");
core.increment (map.location_count.value);
--
map.locations (this) := data;
--
if location.description (map.locations (this).index).clip then
for x in 0 .. location.game (map.locations (this).index).width / core.base - 1 loop
for y in 0 .. location.game (map.locations (this).index).height / core.base - 1 loop
map.clips (map.locations (this).x + x, map.locations (this).y + y) := true;
end loop;
end loop;
end if;
end insert_location;
------------------------------------------------------------------------------------------
procedure insert_construction (data : in construction.information) is
this : constant natural := map.construction_count.value + 1;
begin
core.echo_when (map.construction_count.value = map.construction_count.limit, core.failure, "Can't add new construction, limit reached.");
core.increment (map.construction_count.value);
--
map.constructions (map.construction_count.value) := data;
--
declare reach_x : constant natural := construction.game (map.constructions (this).index).width / core.base;
reach_y : constant natural := construction.game (map.constructions (this).index).height / core.base;
begin
for x in 0 .. reach_x - 1 loop
for y in 0 .. reach_y - 1 loop
map.clips (map.constructions (this).x + x, map.constructions (this).y + y) := true;
end loop;
end loop;
end;
end insert_construction;
------------------------------------------------------------------------------------------
procedure insert_equipment (data : in equipment.information) is
begin
core.echo_when (map.equipment_count.value = map.equipment_count.limit, core.failure, "Can't add new equipment, limit reached.");
core.increment (map.equipment_count.value);
--
map.equipments (map.equipment_count.value) := data;
end insert_equipment;
------------------------------------------------------------------------------------------
procedure insert_unit (data : in unit.information) is
begin
core.echo_when (map.unit_count.value = map.unit_count.limit, core.failure, "Can't add new unit, limit reached.");
core.increment (map.unit_count.value);
--
map.units (map.unit_count.value) := data;
end insert_unit;
------------------------------------------------------------------------------------------
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.");
@ -223,80 +355,11 @@ package body world is
end loop;
end loop;
--
for index in 1 .. landmark_limit loop
insert_landmark (random_landmark);
end loop;
--
for index in 1 .. location_limit loop
map.locations (index).index := location.enumeration'val (core.random (0, location.count - 1));
map.locations (index).used := false;
<<repeat_location_generation>>
map.locations (index).x := core.random (6, map.width - 6);
map.locations (index).y := core.random (6, map.height - 6);
--
if map.clips (map.locations (index).x, map.locations (index).y) then
goto repeat_location_generation;
end if;
--
if location.description (map.locations (index).index).clip then
declare reach_x : constant natural := location.game (map.locations (index).index).width / core.base;
reach_y : constant natural := location.game (map.locations (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.locations (index).x + x, map.locations (index).y + y) := true;
end loop;
end loop;
end;
end if;
end loop;
--
for index in 1 .. construction_limit loop
map.constructions (index).index := construction.enumeration'val (core.random (0, construction.count - 1));
<<repeat_construction_generation>>
map.constructions (index).x := core.random (6, map.width - 6);
map.constructions (index).y := core.random (6, map.height - 6);
--
if map.clips (map.constructions (index).x, map.constructions (index).y) then
goto repeat_construction_generation;
end if;
--
declare reach_x : constant natural := construction.game (map.constructions (index).index).width / core.base;
reach_y : constant natural := construction.game (map.constructions (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.constructions (index).x + x, map.constructions (index).y + y) := true;
end loop;
end loop;
end;
end loop;
--
for index in 1 .. equipment_limit loop
map.equipments (index).index := equipment.enumeration'val (core.random (0, equipment.count - 1));
<<repeat_equipment_generation>>
map.equipments (index).x := core.random (0, map.width - 1);
map.equipments (index).y := core.random (0, map.height - 1);
--
if map.clips (map.equipments (index).x, map.equipments (index).y) then
goto repeat_equipment_generation;
end if;
end loop;
--
for index in 1 .. unit_limit loop
map.units (index).index := unit.enumeration'val (core.random (1, unit.count - 1)); -- none
map.units (index).count := core.random (1, 10);
map.units (index).enemy := true;
<<repeat_unit_generation>>
map.units (index).x := core.random (0, map.width - 1);
map.units (index).y := core.random (0, map.height - 1);
--
if map.clips (map.units (index).x, map.units (index).y) then
goto repeat_unit_generation;
end if;
--
map.clips (map.units (index).x, map.units (index).y) := true;
end loop;
for index in 1 .. landmark_limit loop insert_landmark (random_landmark); end loop;
for index in 1 .. location_limit loop insert_location (random_location); end loop;
for index in 1 .. construction_limit loop insert_construction (random_construction); end loop;
for index in 1 .. equipment_limit loop insert_equipment (random_equipment); end loop;
for index in 1 .. unit_limit loop insert_unit (random_unit); end loop;
--
core.echo (core.success, "Finished procedurally generating new map.");
end make;

View File

@ -49,8 +49,16 @@ package world is
function equipment_valid (data : in equipment.enumeration) return boolean;
function random_landmark return landmark.information;
function random_location return location.information;
function random_construction return construction.information;
function random_equipment return equipment.information;
function random_unit return unit.information;
procedure insert_landmark (data : in landmark.information);
procedure insert_location (data : in location.information);
procedure insert_construction (data : in construction.information);
procedure insert_equipment (data : in equipment.information);
procedure insert_unit (data : in unit.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);