Commit 91bc65842090883c16f47aa9b1ef37d0458d9625
1 parent
b4e6fb3b
EGOS !
git-svn-id: http://svn.net-core.org/repos/t-engine4@139 51575b47-30f0-44d4-a5cc-537603b46e54
Showing
19 changed files
with
146 additions
and
91 deletions
... | ... | @@ -5,7 +5,7 @@ local Faction = require "engine.Faction" |
5 | 5 | |
6 | 6 | module(..., package.seeall, class.inherit(Entity)) |
7 | 7 | |
8 | -function _M:init(t) | |
8 | +function _M:init(t, no_default) | |
9 | 9 | t = t or {} |
10 | 10 | |
11 | 11 | self.name = t.name or "unknown actor" |
... | ... | @@ -16,7 +16,7 @@ function _M:init(t) |
16 | 16 | self.energy.mod = self.energy.mod or 0 |
17 | 17 | self.faction = t.faction or "enemies" |
18 | 18 | self.changed = true |
19 | - Entity.init(self, t) | |
19 | + Entity.init(self, t, no_default) | |
20 | 20 | |
21 | 21 | self.compute_vals = {} |
22 | 22 | end | ... | ... |
... | ... | @@ -11,14 +11,16 @@ setmetatable(__uids, {__mode="v"}) |
11 | 11 | |
12 | 12 | local function copy_recurs(dst, src, deep) |
13 | 13 | for k, e in pairs(src) do |
14 | - if not dst[k] then | |
14 | + if type(e) == "table" and e.__CLASSNAME then | |
15 | + dst[k] = e | |
16 | + elseif not dst[k] then | |
15 | 17 | if deep then |
16 | 18 | dst[k] = {} |
17 | 19 | copy_recurs(dst[k], e, deep) |
18 | 20 | else |
19 | 21 | dst[k] = e |
20 | 22 | end |
21 | - elseif type(dst[k]) == "table" and type(e) == "table" then | |
23 | + elseif type(dst[k]) == "table" and type(e) == "table" and not e.__CLASSNAME then | |
22 | 24 | copy_recurs(dst[k], e, deep) |
23 | 25 | end |
24 | 26 | end |
... | ... | @@ -28,7 +30,7 @@ end |
28 | 30 | -- Any subclass MUST call this constructor |
29 | 31 | -- @param t a table defining the basic properties of the entity |
30 | 32 | -- @usage Entity.new{display='#', color_r=255, color_g=255, color_b=255} |
31 | -function _M:init(t) | |
33 | +function _M:init(t, no_default) | |
32 | 34 | t = t or {} |
33 | 35 | self.uid = next_uid |
34 | 36 | __uids[self.uid] = self |
... | ... | @@ -39,23 +41,25 @@ function _M:init(t) |
39 | 41 | self[k] = ee |
40 | 42 | end |
41 | 43 | |
42 | - self.image = self.image or nil | |
43 | - self.display = self.display or '.' | |
44 | - if self.color then | |
45 | - self.color_r = self.color.r | |
46 | - self.color_g = self.color.g | |
47 | - self.color_b = self.color.b | |
48 | - self.color_br = self.color.br | |
49 | - self.color_bg = self.color.bg | |
50 | - self.color_bb = self.color.bb | |
51 | - self.color = nil | |
44 | + if not no_default then | |
45 | + self.image = self.image or nil | |
46 | + self.display = self.display or '.' | |
47 | + if self.color then | |
48 | + self.color_r = self.color.r | |
49 | + self.color_g = self.color.g | |
50 | + self.color_b = self.color.b | |
51 | + self.color_br = self.color.br | |
52 | + self.color_bg = self.color.bg | |
53 | + self.color_bb = self.color.bb | |
54 | + self.color = nil | |
55 | + end | |
56 | + self.color_r = self.color_r or 0 | |
57 | + self.color_g = self.color_g or 0 | |
58 | + self.color_b = self.color_b or 0 | |
59 | + self.color_br = self.color_br or -1 | |
60 | + self.color_bg = self.color_bg or -1 | |
61 | + self.color_bb = self.color_bb or -1 | |
52 | 62 | end |
53 | - self.color_r = self.color_r or 0 | |
54 | - self.color_g = self.color_g or 0 | |
55 | - self.color_b = self.color_b or 0 | |
56 | - self.color_br = self.color_br or -1 | |
57 | - self.color_bg = self.color_bg or -1 | |
58 | - self.color_bb = self.color_bb or -1 | |
59 | 63 | |
60 | 64 | next_uid = next_uid + 1 |
61 | 65 | |
... | ... | @@ -121,48 +125,46 @@ function _M:check(prop, ...) |
121 | 125 | end |
122 | 126 | |
123 | 127 | --- Loads a list of entities from a definition file |
124 | --- @param ... the files to load from | |
128 | +-- @param file the file to load from | |
129 | +-- @param no_default if true then no default values will be assigned | |
125 | 130 | -- @usage MyEntityClass:loadList("/data/my_entities_def.lua") |
126 | -function _M:loadList(...) | |
131 | +function _M:loadList(file, no_default) | |
127 | 132 | local res = {} |
128 | 133 | |
129 | - for i, file in ipairs{...} do | |
130 | - local f, err = loadfile(file) | |
131 | - if err then error(err) end | |
132 | - | |
133 | - setfenv(f, setmetatable({ | |
134 | - resolvers = resolvers, | |
135 | - DamageType = require "engine.DamageType", | |
136 | - newEntity = function(t) | |
137 | - -- Do we inherit things ? | |
138 | - if t.base then | |
139 | - for k, e in pairs(res[t.base]) do | |
140 | - if not t[k] then | |
141 | - t[k] = e | |
142 | - elseif type(t[k]) == "table" and type(e) == "table" then | |
143 | - copy_recurs(t[k], e) | |
144 | - end | |
134 | + print("Loading entities file", file) | |
135 | + local f, err = loadfile(file) | |
136 | + if err then error(err) end | |
137 | + | |
138 | + setfenv(f, setmetatable({ | |
139 | + resolvers = resolvers, | |
140 | + DamageType = require "engine.DamageType", | |
141 | + newEntity = function(t) | |
142 | + -- Do we inherit things ? | |
143 | + if t.base then | |
144 | + for k, e in pairs(res[t.base]) do | |
145 | + if not t[k] then | |
146 | + t[k] = e | |
147 | + elseif type(t[k]) == "table" and type(e) == "table" then | |
148 | + copy_recurs(t[k], e) | |
145 | 149 | end |
146 | - t.base = nil | |
147 | 150 | end |
151 | + t.base = nil | |
152 | + end | |
153 | + | |
154 | + local e = self.new(t, no_default) | |
155 | + print("loaded", e.name, no_default) | |
156 | + res[#res+1] = e | |
157 | + if t.define_as then res[t.define_as] = e end | |
158 | + end, | |
159 | + load = function(f) | |
160 | + local ret = self:loadList(f) | |
161 | + for i, e in ipairs(ret) do res[#res+1] = e end | |
162 | + end, | |
163 | + loadList = function(f) | |
164 | + return self:loadList(f) | |
165 | + end, | |
166 | + }, {__index=_G})) | |
167 | + f() | |
148 | 168 | |
149 | - local e = self.new(t) | |
150 | - res[#res+1] = e | |
151 | - if t.define_as then res[t.define_as] = e end | |
152 | --- print("new entity", t.name) | |
153 | - for k, ee in pairs(e) do | |
154 | --- print("prop:", k, ee) | |
155 | - end | |
156 | - end, | |
157 | - load = function(f) | |
158 | - local ret = self:loadList(f) | |
159 | - for i, e in ipairs(ret) do res[#res+1] = e end | |
160 | - end, | |
161 | - loadList = function(f) | |
162 | - return self:loadList(f) | |
163 | - end, | |
164 | - }, {__index=_G})) | |
165 | - f() | |
166 | - end | |
167 | 169 | return res |
168 | 170 | end | ... | ... |
... | ... | @@ -3,8 +3,8 @@ local Entity = require "engine.Entity" |
3 | 3 | |
4 | 4 | module(..., package.seeall, class.inherit(Entity)) |
5 | 5 | |
6 | -function _M:init(t) | |
6 | +function _M:init(t, no_default) | |
7 | 7 | t = t or {} |
8 | 8 | self.name = t.name |
9 | - Entity.init(self, t) | |
9 | + Entity.init(self, t, no_default) | |
10 | 10 | end | ... | ... |
... | ... | @@ -16,6 +16,8 @@ function _M:init(level, map) |
16 | 16 | self.e_distances = {} |
17 | 17 | |
18 | 18 | self.distancer_co = self:createDistancer() |
19 | + | |
20 | + self.entities_list = {} | |
19 | 21 | end |
20 | 22 | |
21 | 23 | --- Adds an entity to the level |
... | ... | @@ -115,3 +117,14 @@ end |
115 | 117 | function _M:idleProcessActor(act) |
116 | 118 | table.insert(self.e_toprocess, 1, act) |
117 | 119 | end |
120 | + | |
121 | +--- Setup an entity list for the level, this allwos the Zone to pick objects/actors/... | |
122 | +function _M:setEntitiesList(type, list) | |
123 | + self.entities_list[type] = list | |
124 | + print("Stored entities list", type, list) | |
125 | +end | |
126 | + | |
127 | +--- Gets an entity list for the level, this allows the Zone to pick objects/actors/... | |
128 | +function _M:getEntitiesList(type) | |
129 | + return self.entities_list[type] | |
130 | +end | ... | ... |
... | ... | @@ -3,14 +3,9 @@ local Entity = require "engine.Entity" |
3 | 3 | |
4 | 4 | module(..., package.seeall, class.inherit(Entity)) |
5 | 5 | |
6 | -function _M:init(t) | |
6 | +function _M:init(t, no_default) | |
7 | 7 | t = t or {} |
8 | - Entity.init(self, t) | |
9 | -end | |
10 | - | |
11 | -function _M:resolve(t) | |
12 | - Entity.resolve(self, t) | |
13 | - self.egos = nil | |
8 | + Entity.init(self, t, no_default) | |
14 | 9 | end |
15 | 10 | |
16 | 11 | --- Gets the full name of the object | ... | ... |
... | ... | @@ -52,7 +52,7 @@ function _M:computeRarities(list, level, ood, filter) |
52 | 52 | elseif lev > e.level_range[2] then max = 100 / (lev - e.level_range[2]) |
53 | 53 | end |
54 | 54 | local genprob = max / e.rarity |
55 | - print("prob", e.name, math.floor(genprob), "max", math.floor(max), e.level_range[1], e.level_range[2], lev) | |
55 | + print("prob", e.name, math.floor(genprob), "max", math.floor(max), e.level_range[1], e.level_range[2], lev, "egoable", e.egos and #e.egos) | |
56 | 56 | |
57 | 57 | r.total = r.total + genprob |
58 | 58 | r[#r+1] = { e=e, genprob=r.total + genprob, level_diff = lev - level } |
... | ... | @@ -76,6 +76,47 @@ function _M:pickEntity(list) |
76 | 76 | return nil |
77 | 77 | end |
78 | 78 | |
79 | +function _M:getEgosList(level, type, group, class) | |
80 | + -- Already loaded ? use it | |
81 | + local list = level:getEntitiesList(type.."/"..group) | |
82 | + if list then return list end | |
83 | + | |
84 | + -- otehrwise loads it and store it | |
85 | + list = require(class):loadList(group, true) | |
86 | + level:setEntitiesList(type.."/"..group, list) | |
87 | + | |
88 | + return list | |
89 | +end | |
90 | + | |
91 | +function _M:makeEntity(level, type) | |
92 | + local list = level:getEntitiesList(type) | |
93 | + local e = self:pickEntity(list) | |
94 | + e = e:clone() | |
95 | + e:resolve() | |
96 | + | |
97 | + -- Add "ego" properties | |
98 | + if e.egos then | |
99 | + local egos = self:getEgosList(level, type, e.egos, e.__CLASSNAME) | |
100 | + local ego = egos[rng.range(1, #egos)] | |
101 | + if ego then | |
102 | + print("ego", ego.__CLASSNAME, ego.name, getmetatable(ego)) | |
103 | + ego = ego:clone() | |
104 | + ego:resolve() | |
105 | + local newname | |
106 | + if ego.prefix then | |
107 | + newname = ego.name .. e.name | |
108 | + else | |
109 | + newname = e.name .. ego.name | |
110 | + end | |
111 | + print("applying ego", ego.name, "to ", e.name, "::", newname) | |
112 | + table.merge(e, ego, true) | |
113 | + e.name = newname | |
114 | + end | |
115 | + end | |
116 | + | |
117 | + return e | |
118 | +end | |
119 | + | |
79 | 120 | function _M:load() |
80 | 121 | local f, err = loadfile("/data/zones/"..self.short_name.."/zone.lua") |
81 | 122 | if err then error(err) end | ... | ... |
... | ... | @@ -7,7 +7,10 @@ function _M:init(zone, map, level) |
7 | 7 | engine.Generator.init(self, zone, map) |
8 | 8 | self.level = level |
9 | 9 | local data = level.data.generator.actor |
10 | - self.npc_list = zone:computeRarities(zone.npc_list, level.level, data.ood, nil) | |
10 | + | |
11 | + -- Setup the entities list | |
12 | + level:setEntitiesList("actor", zone:computeRarities(zone.npc_list, level.level, data.ood, nil)) | |
13 | + | |
11 | 14 | if data.adjust_level_to_player and game:getPlayer() then |
12 | 15 | self.adjust_level_to_player = {base=game:getPlayer().level, min=data.adjust_level_to_player[1], max=data.adjust_level_to_player[2]} |
13 | 16 | end |
... | ... | @@ -17,10 +20,8 @@ end |
17 | 20 | |
18 | 21 | function _M:generate() |
19 | 22 | for i = 1, rng.range(self.nb_npc[1], self.nb_npc[2]) do |
20 | - local m = self.zone:pickEntity(self.npc_list) | |
23 | + local m = self.zone:makeEntity(self.level, "actor") | |
21 | 24 | if m then |
22 | - m = m:clone() | |
23 | - m:resolve() | |
24 | 25 | local x, y = rng.range(0, self.map.w), rng.range(0, self.map.h) |
25 | 26 | local tries = 0 |
26 | 27 | while not m:canMove(x, y) and tries < 100 do | ... | ... |
... | ... | @@ -6,8 +6,11 @@ module(..., package.seeall, class.inherit(engine.Generator)) |
6 | 6 | function _M:init(zone, map, level) |
7 | 7 | engine.Generator.init(self, zone, map) |
8 | 8 | self.level = level |
9 | - local data = level.data | |
10 | - self.object_list = zone:computeRarities(zone.object_list, level.level, data.generator and data.generator.actor and data.generator.actor.ood, nil) | |
9 | + local data = level.data.generator.object | |
10 | + | |
11 | + -- Setup the entities list | |
12 | + level:setEntitiesList("object", zone:computeRarities(zone.object_list, level.level, data.ood, nil)) | |
13 | + | |
11 | 14 | if data.adjust_level_to_player and game:getPlayer() then |
12 | 15 | self.adjust_level_to_player = {base=game:getPlayer().level, min=data.adjust_level_to_player[1], max=data.adjust_level_to_player[2]} |
13 | 16 | end |
... | ... | @@ -17,10 +20,8 @@ end |
17 | 20 | |
18 | 21 | function _M:generate() |
19 | 22 | for i = 1, rng.range(self.nb_object[1], self.nb_object[2]) do |
20 | - local o = self.zone:pickEntity(self.object_list) | |
23 | + local o = self.zone:makeEntity(self.level, "object") | |
21 | 24 | if o then |
22 | - o = o:clone() | |
23 | - o:resolve() | |
24 | 25 | local x, y = rng.range(0, self.map.w), rng.range(0, self.map.h) |
25 | 26 | local tries = 0 |
26 | 27 | while (self.map:checkEntity(x, y, Map.TERRAIN, "block_move") or self.map(x, y, Map.OBJECT)) and tries < 100 do | ... | ... |
... | ... | @@ -25,7 +25,7 @@ module(..., package.seeall, class.inherit( |
25 | 25 | mod.class.interface.Combat |
26 | 26 | )) |
27 | 27 | |
28 | -function _M:init(t) | |
28 | +function _M:init(t, no_default) | |
29 | 29 | -- Define some basic combat stats |
30 | 30 | self.combat_def = 0 |
31 | 31 | self.combat_armor = 0 |
... | ... | @@ -54,7 +54,7 @@ function _M:init(t) |
54 | 54 | -- Default melee barehanded damage |
55 | 55 | self.combat = { dam=1, atk=1, apr=0, dammod={str=1} } |
56 | 56 | |
57 | - engine.Actor.init(self, t) | |
57 | + engine.Actor.init(self, t, no_default) | |
58 | 58 | engine.interface.ActorInventory.init(self, t) |
59 | 59 | engine.interface.ActorTemporaryEffects.init(self, t) |
60 | 60 | engine.interface.ActorLife.init(self, t) | ... | ... |
... | ... | @@ -75,7 +75,7 @@ function _M:newGame() |
75 | 75 | self.player = Player.new{name=self.player_name} |
76 | 76 | |
77 | 77 | local birth = Birther.new(self.player, {"base", "race", "subrace", "sex", "class", "subclass" }, function() |
78 | - self.player.wild_x, self.player.wild_y = 38, 15 | |
78 | + self.player.wild_x, self.player.wild_y = 39, 17 | |
79 | 79 | self:changeLevel(1) |
80 | 80 | |
81 | 81 | local ds = LevelupStatsDialog.new(self.player) | ... | ... |
... | ... | @@ -3,8 +3,8 @@ require "engine.Grid" |
3 | 3 | |
4 | 4 | module(..., package.seeall, class.inherit(engine.Grid)) |
5 | 5 | |
6 | -function _M:init(t) | |
7 | - engine.Grid.init(self, t) | |
6 | +function _M:init(t, no_default) | |
7 | + engine.Grid.init(self, t, no_default) | |
8 | 8 | end |
9 | 9 | |
10 | 10 | function _M:block_move(x, y, e) | ... | ... |
... | ... | @@ -4,8 +4,8 @@ require "mod.class.Actor" |
4 | 4 | |
5 | 5 | module(..., package.seeall, class.inherit(mod.class.Actor, engine.interface.ActorAI)) |
6 | 6 | |
7 | -function _M:init(t) | |
8 | - mod.class.Actor.init(self, t) | |
7 | +function _M:init(t, no_default) | |
8 | + mod.class.Actor.init(self, t, no_default) | |
9 | 9 | ActorAI.init(self, t) |
10 | 10 | end |
11 | 11 | ... | ... |
... | ... | @@ -6,7 +6,7 @@ local ActorTalents = require "engine.interface.ActorTalents" |
6 | 6 | |
7 | 7 | module(..., package.seeall, class.inherit(mod.class.Actor)) |
8 | 8 | |
9 | -function _M:init(t) | |
9 | +function _M:init(t, no_default) | |
10 | 10 | t.body = { |
11 | 11 | INVEN = 1000, |
12 | 12 | MAINHAND = 1, |
... | ... | @@ -20,7 +20,7 @@ function _M:init(t) |
20 | 20 | FEET = 1, |
21 | 21 | TOOL = 1, |
22 | 22 | } |
23 | - mod.class.Actor.init(self, t) | |
23 | + mod.class.Actor.init(self, t, no_default) | |
24 | 24 | self.player = true |
25 | 25 | self.faction = "players" |
26 | 26 | ... | ... |
... | ... | @@ -19,13 +19,13 @@ return { |
19 | 19 | }, |
20 | 20 | actor = { |
21 | 21 | class = "engine.generator.actor.Random", |
22 | - nb_npc = {20, 30}, | |
22 | + nb_npc = {2, 3}, | |
23 | 23 | ood = {chance=5, range={1, 10}}, |
24 | 24 | adjust_level_to_player = {-1, 2}, |
25 | 25 | }, |
26 | 26 | object = { |
27 | 27 | class = "engine.generator.object.Random", |
28 | - nb_object = {3, 6}, | |
28 | + nb_object = {100, 100}, | |
29 | 29 | ood = {chance=5, range={1, 10}}, |
30 | 30 | }, |
31 | 31 | }, | ... | ... |
ideas/materials.ods
0 → 100644
No preview for this file type
-
Please register or login to post a comment