This repository has been archived by the owner on Nov 21, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
165 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
|
||
local BuildWorm = {stages = {}} | ||
local Log = function(str, base, ...) BiterBase.Logger.log(string.format("[BuildWorm] - (" .. base.name .. "): " .. str, ...)) end | ||
|
||
BuildWorm.stages.clear_trees = function(base, data) | ||
local surface = base.queen.surface | ||
local pos = base.queen.position | ||
table.each(surface.find_entities_filtered({area = Position.expand_to_area(pos, data.search_distance), type = 'tree'}), function(entity) | ||
entity.destroy() | ||
end) | ||
return 'build_worm' | ||
end | ||
|
||
BuildWorm.stages.build_worm = function(base, data) | ||
local surface = base.queen.surface | ||
local pos = base.queen.position | ||
local entity_pos = surface.find_non_colliding_position(data.worm_type, pos, data.search_distance, 0.5) | ||
if entity_pos and Position.distance(pos, entity_pos) <= data.search_distance then | ||
local worm = surface.create_entity({name = data.worm_type, position = entity_pos, force = base.queen.force}) | ||
table.insert(base.worms, worm) | ||
Log("Successfully spawned a new worm at %s", base, serpent.line(worm.position)) | ||
return 'success' | ||
end | ||
|
||
data.search_distance = data.search_distance + 1 | ||
return 'clear_trees' | ||
end | ||
|
||
function BuildWorm.tick(base, data) | ||
if not data.stage then | ||
data.stage = 'clear_trees' | ||
end | ||
local prev_stage = data.stage | ||
data.stage = BuildWorm.stages[data.stage](base, data) | ||
if prev_stage ~= data.stage then | ||
Log("Updating stage from %s to %s", base, prev_stage, data.stage) | ||
end | ||
return true | ||
end | ||
|
||
function BuildWorm.is_expired(base, data) | ||
return data.search_distance > 7 or data.stage == 'success' | ||
end | ||
|
||
function BuildWorm.initialize(base, data) | ||
data.search_distance = 2 | ||
if game.evolution_factor > 0.66 and math.random(100) > 66 then | ||
data.worm_type = 'big-worm-turret' | ||
elseif game.evolution_factor > 0.4 and math.random(100) > 40 then | ||
data.worm_type = 'medium-worm-turret' | ||
else | ||
data.worm_type = 'small-worm-turret' | ||
end | ||
end | ||
|
||
return BuildWorm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
|
||
local GrowHive = {stages = {}} | ||
local Log = function(str, base, ...) BiterBase.Logger.log(string.format("[GrowHive] - (" .. base.name .. "): " .. str, ...)) end | ||
|
||
GrowHive.stages.clear_trees = function(base, data) | ||
local surface = base.queen.surface | ||
local pos = base.queen.position | ||
table.each(surface.find_entities_filtered({area = Position.expand_to_area(pos, data.search_distance), type = 'tree'}), function(entity) | ||
entity.destroy() | ||
end) | ||
return 'build_hive' | ||
end | ||
|
||
GrowHive.stages.build_hive = function(base, data) | ||
local surface = base.queen.surface | ||
local pos = base.queen.position | ||
local entity_pos = surface.find_non_colliding_position(data.hive_type, pos, data.search_distance, 0.5) | ||
if entity_pos and Position.distance(pos, entity_pos) <= data.search_distance then | ||
local hive = surface.create_entity({name = data.hive_type, position = entity_pos, force = base.queen.force}) | ||
table.insert(base.hives, hive) | ||
Log("Successfully spawned a new hive at %s", base, serpent.line(hive.position)) | ||
return 'success' | ||
end | ||
|
||
data.search_distance = data.search_distance + 1 | ||
return 'clear_trees' | ||
end | ||
|
||
function GrowHive.tick(base, data) | ||
if not data.stage then | ||
data.stage = 'clear_trees' | ||
end | ||
local prev_stage = data.stage | ||
data.stage = GrowHive.stages[data.stage](base, data) | ||
if prev_stage ~= data.stage then | ||
Log("Updating stage from %s to %s", base, prev_stage, data.stage) | ||
end | ||
return true | ||
end | ||
|
||
function GrowHive.is_expired(base, data) | ||
return data.search_distance > 10 or data.stage == 'success' | ||
end | ||
|
||
function GrowHive.initialize(base, data) | ||
data.search_distance = 3 | ||
if math.random(100) > 33 then | ||
data.hive_type = 'biter-spawner' | ||
else | ||
data.hive_type = 'spitter-spawner' | ||
end | ||
end | ||
|
||
return GrowHive |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters