From b261d6aaefce5fad8a13145334b2ba92869ba549 Mon Sep 17 00:00:00 2001
From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54>
Date: Sat, 30 Jan 2010 00:21:17 +0000
Subject: [PATCH] swarms fix entity inheritance

git-svn-id: http://svn.net-core.org/repos/t-engine4@296 51575b47-30f0-44d4-a5cc-537603b46e54
---
 game/engine/Entity.lua                        | 28 ++++++---
 game/modules/tome/class/Actor.lua             |  4 +-
 game/modules/tome/class/interface/Combat.lua  |  2 +-
 .../tome/data/general/npcs/skeleton.lua       |  2 +
 game/modules/tome/data/general/npcs/swarm.lua | 58 +++++++++++++++++++
 game/modules/tome/data/talents/misc/npcs.lua  | 41 +++++++++++++
 .../talents/techniques/combat-training.lua    |  2 +-
 .../data/talents/techniques/dualweapon.lua    |  4 +-
 .../tome/data/zones/old-forest/npcs.lua       |  1 +
 .../tome/data/zones/tower-amon-sul/npcs.lua   |  8 +--
 10 files changed, 132 insertions(+), 18 deletions(-)
 create mode 100644 game/modules/tome/data/general/npcs/swarm.lua

diff --git a/game/engine/Entity.lua b/game/engine/Entity.lua
index 97d93b9e7c..3c22beda91 100644
--- a/game/engine/Entity.lua
+++ b/game/engine/Entity.lua
@@ -5,6 +5,7 @@
 module(..., package.seeall, class.make)
 
 local next_uid = 1
+local entities_load_functions = {}
 
 -- Setup the uids repository as a weak value table, when the entities are no more used anywhere else they disappear from there too
 setmetatable(__uids, {__mode="v"})
@@ -106,7 +107,7 @@ function _M:resolve(t)
 	for k, e in pairs(t) do
 		if type(e) == "table" and e.__resolver then
 			t[k] = resolvers.calc[e.__resolver](e, self)
-		elseif type(e) == "table" then
+		elseif type(e) == "table" and not e.__CLASSNAME then
 			self:resolve(e)
 		end
 	end
@@ -163,10 +164,19 @@ end
 -- @param no_default if true then no default values will be assigned
 -- @usage MyEntityClass:loadList("/data/my_entities_def.lua")
 function _M:loadList(file, no_default, res)
+	no_default = no_default and true or false
 	res = res or {}
 
-	print("Loading entities file", file)
-	local f, err = loadfile(file)
+	local f, err = nil, nil
+	if entities_load_functions[file] and entities_load_functions[file][no_default] then
+		print("Loading entities file from memory", file)
+		f = entities_load_functions[file][no_default]
+	else
+		f, err = loadfile(file)
+		print("Loading entities file from file", file)
+		entities_load_functions[file] = entities_load_functions[file] or {}
+		entities_load_functions[file][no_default] = f
+	end
 	if err then error(err) end
 
 	setfenv(f, setmetatable({
@@ -176,17 +186,19 @@ function _M:loadList(file, no_default, res)
 			-- Do we inherit things ?
 			if t.base then
 				for k, e in pairs(res[t.base]) do
-					if not t[k] then
-						t[k] = e
-					elseif type(t[k]) == "table" and type(e) == "table" then
-						copy_recurs(t[k], e)
+					if k ~= "define_as" then
+						if not t[k] then
+							t[k] = e
+						elseif type(t[k]) == "table" and type(e) == "table" then
+							copy_recurs(t[k], e)
+						end
 					end
 				end
 				t.base = nil
 			end
 
 			local e = self.new(t, no_default)
-			print("loaded", e.name, no_default)
+
 			res[#res+1] = e
 			if t.define_as then res[t.define_as] = e end
 		end,
diff --git a/game/modules/tome/class/Actor.lua b/game/modules/tome/class/Actor.lua
index ddaffd6e65..5bfad5d12c 100644
--- a/game/modules/tome/class/Actor.lua
+++ b/game/modules/tome/class/Actor.lua
@@ -55,9 +55,9 @@ function _M:init(t, no_default)
 	t.mana_rating = t.mana_rating or 10
 	t.stamina_rating = t.stamina_rating or 10
 
-	t.esp = {range=10}
+	t.esp = t.esp or {range=10}
 
-	t.on_melee_hit = {}
+	t.on_melee_hit = t.on_melee_hit or {}
 
 	-- Resistances
 	t.resists = t.resists or {}
diff --git a/game/modules/tome/class/interface/Combat.lua b/game/modules/tome/class/interface/Combat.lua
index d937547fce..bd692b2868 100644
--- a/game/modules/tome/class/interface/Combat.lua
+++ b/game/modules/tome/class/interface/Combat.lua
@@ -76,7 +76,7 @@ function _M:attackTarget(target, damtype, mult, noenergy)
 	end
 
 	-- Barehanded ?
-	if not speed then
+	if not speed and self.combat then
 		local s, h = self:attackTargetWith(target, self.combat, damtype, mult)
 		speed = math.max(speed or 0, s)
 		hit = hit or h
diff --git a/game/modules/tome/data/general/npcs/skeleton.lua b/game/modules/tome/data/general/npcs/skeleton.lua
index a66837ce2b..9ec13fe67a 100644
--- a/game/modules/tome/data/general/npcs/skeleton.lua
+++ b/game/modules/tome/data/general/npcs/skeleton.lua
@@ -29,6 +29,7 @@ newEntity{ base = "BASE_NPC_SKELETON",
 	rarity = 4,
 	max_life = resolvers.rngavg(40,50),
 	combat_armor = 5, combat_def = 1,
+	talents = resolvers.talents{ [Talents.T_SUMMON]=1 },
 }
 
 newEntity{ base = "BASE_NPC_SKELETON",
@@ -38,6 +39,7 @@ newEntity{ base = "BASE_NPC_SKELETON",
 	max_life = resolvers.rngavg(90,100),
 	combat_armor = 5, combat_def = 1,
 	talents = resolvers.talents{ [Talents.T_STAMINA_POOL]=1, [Talents.T_STUNNING_BLOW]=1, [Talents.T_DEATH_BLOW]=1 },
+	ai_state = { talent_in=1, },
 }
 
 newEntity{ base = "BASE_NPC_SKELETON",
diff --git a/game/modules/tome/data/general/npcs/swarm.lua b/game/modules/tome/data/general/npcs/swarm.lua
new file mode 100644
index 0000000000..ea722f05f9
--- /dev/null
+++ b/game/modules/tome/data/general/npcs/swarm.lua
@@ -0,0 +1,58 @@
+local Talents = require("engine.interface.ActorTalents")
+
+newEntity{
+	define_as = "BASE_NPC_INSECT",
+	type = "insect", subtype = "swarms",
+	display = "I", color=colors.WHITE,
+	can_multiply = 2,
+	desc = "Buzzzzzzzzzzzzzzzzzzzzzzzzzzz.",
+	body = { INVEN = 1 },
+	autolevel = "warrior",
+	ai = "dumb_talented_simple", ai_state = { talent_in=1, },
+	stats = { str=1, dex=20, mag=3, con=1 },
+	energy = { mod=2 },
+	combat_armor = 1, combat_def = 10,
+}
+
+newEntity{ base = "BASE_NPC_INSECT",
+	name = "midge swarm", color=colors.UMBER,
+	desc = "A swarm of midges, they want blood.",
+	level_range = {1, 25}, exp_worth = 1,
+	rarity = 4,
+	max_life = resolvers.rngavg(1,2),
+	combat = { dam=1, atk=15, apr=20 },
+}
+
+newEntity{ base = "BASE_NPC_INSECT",
+	name = "bee swarm", color=colors.GOLD,
+	desc = "They buzz at you threateningly, as you have gotten too close to their hive.",
+	level_range = {2, 25}, exp_worth = 1,
+	rarity = 4,
+	max_life = resolvers.rngavg(1,3),
+	combat = { dam=2, atk=15, apr=20 },
+
+	talents = resolvers.talents{ [Talents.T_SPORE_POISON]=1 },
+}
+
+newEntity{ base = "BASE_NPC_INSECT",
+	name = "hornet swarm", color=colors.YELLOW,
+	desc = "You have intruded on their grounds, they will defend it at all costs.",
+	level_range = {3, 25}, exp_worth = 1,
+	rarity = 7,
+	max_life = resolvers.rngavg(3,5),
+	combat = { dam=5, atk=15, apr=20 },
+
+	talents = resolvers.talents{ [Talents.T_SPORE_POISON]=2 },
+}
+
+newEntity{ base = "BASE_NPC_INSECT",
+	name = "hummerhorn", color=colors.YELLOW,
+	desc = "A giant buzzing wasp, its stinger drips venom. ",
+	level_range = {16, 50}, exp_worth = 1,
+	rarity = 7,
+	max_life = resolvers.rngavg(5,7),
+	combat = { dam=10, atk=15, apr=20 },
+	can_multiply = 4,
+
+	talents = resolvers.talents{ [Talents.T_SPORE_POISON]=3 },
+}
diff --git a/game/modules/tome/data/talents/misc/npcs.lua b/game/modules/tome/data/talents/misc/npcs.lua
index d56f88b8d8..cf451fb402 100644
--- a/game/modules/tome/data/talents/misc/npcs.lua
+++ b/game/modules/tome/data/talents/misc/npcs.lua
@@ -205,3 +205,44 @@ newTalent{
 		return ([[Bites the target, infecting ti with poison.]])
 	end,
 }
+
+newTalent{
+	name = "Summon",
+	type = {"other/other", 1},
+	cooldown = 4,
+	range = 20,
+	action = function(self, t)
+		local filters = self.summon or {{type=self.type, subtype=self.subtype, number=1, hasxp=true, lastfor=20}}
+		if #filters == 0 then return end
+		local filter = rng.table(filters)
+
+		for i = 1, filter.number do
+			-- Find space
+			local x, y = util.findFreeGrid(self.x, self.y, 10, true, {[Map.ACTOR]=true})
+			if not x then
+				game.logPlayer(self, "Not enough space to summon!")
+				break
+			end
+
+			-- Find an actor with that filter
+			local m = game.zone:makeEntity(game.level, "actor", filter)
+			if m then
+				if not filter.hasxp then m.exp_worth = 0 end
+				m:resolve()
+
+				m.summoner = self
+				m.summon_time = filter.lastfor
+
+				m:move(x, y, true)
+				game.level:addEntity(m)
+				m:added()
+
+				game.logSeen(self, "%s summons %s!", self.name:capitalize(), m.name)
+			end
+		end
+		return true
+	end,
+	info = function(self)
+		return ([[Summon allies.]])
+	end,
+}
diff --git a/game/modules/tome/data/talents/techniques/combat-training.lua b/game/modules/tome/data/talents/techniques/combat-training.lua
index 51bfdd3979..07b745df7f 100644
--- a/game/modules/tome/data/talents/techniques/combat-training.lua
+++ b/game/modules/tome/data/talents/techniques/combat-training.lua
@@ -89,6 +89,6 @@ newTalent{
 	require = { stat = { dex=function(level) return 10 + level * 3 end }, },
 	mode = "passive",
 	info = function(self, t)
-		return [[Increases damage with knifes.]]
+		return [[Increases damage with knives.]]
 	end,
 }
diff --git a/game/modules/tome/data/talents/techniques/dualweapon.lua b/game/modules/tome/data/talents/techniques/dualweapon.lua
index c1eba16c1a..dafeda4d7c 100644
--- a/game/modules/tome/data/talents/techniques/dualweapon.lua
+++ b/game/modules/tome/data/talents/techniques/dualweapon.lua
@@ -118,7 +118,7 @@ newTalent{
 		return true
 	end,
 	info = function(self, t)
-		return ([[Lashes out a flurry of blows, hiting your target three times with each weapons for %d%% damage.]]):format(100 * (1.8 + self:getTalentLevel(t) / 10))
+		return ([[Lashes out a flurry of blows, hitting your target three times with each weapons for %d%% damage.]]):format(100 * (1.8 + self:getTalentLevel(t) / 10))
 	end,
 }
 
@@ -147,7 +147,7 @@ newTalent{
 		return true
 	end,
 	info = function(self, t)
-		return ([[Lashes out a flurry of blows, hiting your target three times with each weapons for %d%% damage.]]):format(100 * (1.8 + self:getTalentLevel(t) / 10))
+		return ([[Lashes out a flurry of blows, hitting your target three times with each weapons for %d%% damage.]]):format(100 * (1.8 + self:getTalentLevel(t) / 10))
 	end,
 }
 
diff --git a/game/modules/tome/data/zones/old-forest/npcs.lua b/game/modules/tome/data/zones/old-forest/npcs.lua
index 02f0aa1ca6..c648365934 100644
--- a/game/modules/tome/data/zones/old-forest/npcs.lua
+++ b/game/modules/tome/data/zones/old-forest/npcs.lua
@@ -2,6 +2,7 @@ load("/data/general/npcs/bear.lua")
 load("/data/general/npcs/vermin.lua")
 load("/data/general/npcs/wolf.lua")
 load("/data/general/npcs/snake.lua")
+load("/data/general/npcs/swarm.lua")
 
 local Talents = require("engine.interface.ActorTalents")
 
diff --git a/game/modules/tome/data/zones/tower-amon-sul/npcs.lua b/game/modules/tome/data/zones/tower-amon-sul/npcs.lua
index 54e3da8472..0d54782231 100644
--- a/game/modules/tome/data/zones/tower-amon-sul/npcs.lua
+++ b/game/modules/tome/data/zones/tower-amon-sul/npcs.lua
@@ -1,8 +1,8 @@
-load("/data/general/npcs/rodent.lua")
-load("/data/general/npcs/vermin.lua")
-load("/data/general/npcs/molds.lua")
+--load("/data/general/npcs/rodent.lua")
+--load("/data/general/npcs/vermin.lua")
+--load("/data/general/npcs/molds.lua")
 load("/data/general/npcs/skeleton.lua")
-load("/data/general/npcs/snake.lua")
+--load("/data/general/npcs/snake.lua")
 
 local Talents = require("engine.interface.ActorTalents")
 
-- 
GitLab