Skip to content

Commit 634a35a

Browse files
committed
Miscellaneous fixes + refactoring (new game required)
1 parent 9c00c99 commit 634a35a

File tree

63 files changed

+4053
-5586
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+4053
-5586
lines changed

Optional Features/#1. (Choose From This Folder First)/No Enemy Map Spots/gamedata/scripts/sim_squad_generic.script

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1442,7 +1442,8 @@ function sim_attack_point:is_finished()
14421442
if squad.squad_online then
14431443
local obj_pos = commander.position
14441444
local dest_def_restr = db.zone_by_name[dest_smart.def_restr]
1445-
if (dest_def_restr ~= nil and not dest_def_restr:inside(obj_pos) and dest_smart:name() ~= "mar_smart_terrain_5_12") or (dest_def_restr == nil and obj_pos:distance_to_sqr(dest_smart.position) > 900) then
1445+
if (dest_def_restr ~= nil and not dest_def_restr:inside(obj_pos))
1446+
or (dest_def_restr == nil and obj_pos:distance_to_sqr(dest_smart.position) > 900) then
14461447
return false
14471448
end
14481449
-- else
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
1-
local object_binder_update = object_binder.update
2-
31
function init(obj) -- called 1st
42

53
local ini = obj:spawn_ini()
6-
--[[
7-
if ini and ini:section_exist("animation") then
8-
abort("object '%s': animation section is deprecated, use logic + impulse combination", obj:name())
9-
return
10-
end
11-
]]
12-
if (ini and ini:section_exist("logic")) or obj:clsid() == clsid.inventory_box then -- drop-boxes all have a [logic] section in vanilla, so are included without an explicit test
13-
db.storage[obj:id()] = {}
4+
5+
-- Drop-boxes all have a [logic] section in vanilla, so are included without an explicit test:
6+
if (ini and ini:section_exist("logic")) or obj:clsid() == clsid.inventory_box then
147
obj:bind_object(generic_physics_binder(obj))
158
end
169
end
1710

18-
---------------------------------------------------------------------------------------------
11+
--------------------------------------------------------------------------------
1912

2013
class "generic_physics_binder" (object_binder)
2114

2215
function generic_physics_binder:__init(obj) super(obj) -- called 2nd
2316
self.initialized = false
2417
self.loaded = false
18+
self.particle = nil
19+
self.box_items = nil
20+
if obj:clsid() == clsid.inventory_box then
21+
self.is_inventory_box = true
22+
self.is_drop_box = false
23+
else
24+
local ini = obj:spawn_ini()
25+
self.is_inventory_box = false
26+
self.is_drop_box = ini ~= nil and ini:section_exist("drop_box")
27+
end
28+
self.st = {}
2529
end
2630

2731
function generic_physics_binder:reload(section) -- called 3rd
@@ -30,36 +34,25 @@ end
3034

3135
function generic_physics_binder:reinit() -- called 4th
3236
object_binder.reinit(self)
33-
local sobj = self.object
34-
self.st = db.storage[sobj:id()]
35-
local is_inventory_box = sobj:clsid() == clsid.inventory_box
36-
self.is_inventory_box = is_inventory_box
37-
if not is_inventory_box then
38-
local ini = sobj:spawn_ini()
39-
self.is_drop_box = ini and ini:section_exist("drop_box")
40-
end
37+
db.storage[self.object:id()] = self.st
4138
end
4239

43-
function generic_physics_binder:net_spawn(data) -- called 5th
40+
function generic_physics_binder:net_spawn(se_abstract) -- called 5th
4441

45-
if not object_binder.net_spawn(self, data) then
42+
if not object_binder.net_spawn(self, se_abstract) then
4643
return false
4744
end
4845

49-
local sobj = self.object
46+
local obj = self.object
5047

51-
-- if sobj:clsid() == clsid.projector then
52-
-- db.add_sl(sobj)
53-
-- end
48+
db.add_obj(obj)
5449

5550
if self.is_drop_box then
56-
self.box_items = xr_box.ph_item_box(sobj)
51+
self.box_items = xr_box.ph_item_box(obj)
5752
end
5853

59-
db.add_obj(sobj)
60-
6154
if self.is_inventory_box then
62-
local sname = sobj:name()
55+
local sname = obj:name()
6356
if sname ~= "gar_treasure_quest_reward_in_anomaly" and sname ~= "gar_treasure_quest_old_pda" then
6457
local actor_level = level.name()
6558
if (actor_level == "marsh" and has_alife_info("mar_stashes_filled"))
@@ -76,58 +69,21 @@ function generic_physics_binder:net_spawn(data) -- called 5th
7669
return true
7770
end
7871
treasure_manager.use_box(sname)
79-
-- dbglog("Used box with name "..sname.." and ID "..sobj:id()..".")
8072
end
8173
end
8274

8375
return true
8476
end
8577

86-
function generic_physics_binder:update(delta) -- called 6th
87-
88-
object_binder_update(self, delta)
89-
90-
local sobj = self.object
91-
local obj_st = self.st
92-
93-
if not self.initialized then
94-
self.initialized = true
95-
xr_logic.initialize_obj(sobj, obj_st, self.loaded, modules.stype_item)
96-
local particle = utils.cfg_get_string(obj_st.ini, obj_st.section_logic, "particle", sobj, false, "", nil)
97-
if particle ~= nil then
98-
self.particle = particles_object(particle)
99-
self.particle:play_at_pos(sobj:position())
100-
end
101-
if obj_st.active_section ~= nil or self.is_drop_box then
102-
sobj:set_callback(callback.hit, generic_physics_binder.hit_callback, self)
103-
sobj:set_callback(callback.death, generic_physics_binder.death_callback, self)
104-
sobj:set_callback(callback.use_object, generic_physics_binder.use_callback, self)
105-
else
106-
if self.is_inventory_box then
107-
sobj:set_callback(callback.use_object, generic_physics_binder.use_callback, self)
108-
end
109-
end
110-
end
111-
112-
if obj_st.active_section ~= nil then
113-
xr_logic.issue_event(nil, obj_st[obj_st.active_scheme], "update", delta)
114-
end
115-
116-
xr_sound.update(sobj:id())
117-
end
118-
11978
function generic_physics_binder:net_destroy()
12079

121-
local sobj = self.object
122-
local sid = sobj:id()
80+
self:clear_callbacks()
12381

124-
xr_sound.stop_sounds_by_id(sid)
82+
local obj = self.object
83+
local obj_st = self.st
12584

126-
sobj:set_callback(callback.hit, nil) -- SRP
127-
sobj:set_callback(callback.death, nil) -- SRP
128-
sobj:set_callback(callback.use_object, nil) -- SRP
85+
xr_sound.stop_sounds_by_id(obj:id())
12986

130-
local obj_st = self.st
13187
if obj_st.active_scheme then
13288
xr_logic.issue_event(nil, obj_st[obj_st.active_scheme], "net_destroy")
13389
end
@@ -136,47 +92,53 @@ function generic_physics_binder:net_destroy()
13692
self.particle:stop()
13793
end
13894

139-
-- db.del_obj(sobj) -- done below
140-
-- db.del_sl(sobj)
141-
142-
db.storage[sid] = nil
95+
db.del_obj(obj)
14396

14497
object_binder.net_destroy(self)
14598
end
14699

147-
function generic_physics_binder:net_save_relevant()
148-
return true
149-
end
100+
local object_binder_update = object_binder.update
150101

151-
function generic_physics_binder:save(packet)
152-
object_binder.save(self, packet)
153-
set_save_marker(packet, "save", false, "physics_binder")
154-
xr_logic.save_obj(self.object, packet)
155-
set_save_marker(packet, "save", true, "physics_binder")
156-
end
102+
function generic_physics_binder:update(delta) -- called 6th
157103

158-
function generic_physics_binder:load(reader)
159-
self.loaded = true
160-
object_binder.load(self, reader)
161-
set_save_marker(reader, "load", false, "physics_binder")
162-
xr_logic.load_obj(self.object, reader)
163-
set_save_marker(reader, "load", true, "physics_binder")
164-
end
104+
object_binder_update(self, delta)
165105

166-
function generic_physics_binder:use_callback(used_obj, user)
167-
if self.is_inventory_box then
168-
if used_obj:name() == "gar_smart_terrain_5_6_box" then
169-
local act = db.actor
170-
if act:has_info("gar_quest_redemption_started") then
171-
act:give_info_portion("gar_quest_redemption_done")
106+
local obj = self.object
107+
local obj_st = self.st
108+
109+
if not self.initialized then
110+
self.initialized = true
111+
xr_logic.initialize_obj(obj, obj_st, self.loaded, modules.stype_item)
112+
local particle = utils.cfg_get_string(obj_st.ini, obj_st.section_logic, "particle", nil, false, "", nil)
113+
if particle ~= nil then
114+
self.particle = particles_object(particle)
115+
self.particle:play_at_pos(obj:position())
116+
end
117+
if obj_st.active_scheme or self.is_drop_box then
118+
obj:set_callback(callback.hit, generic_physics_binder.hit_callback, self)
119+
obj:set_callback(callback.death, generic_physics_binder.death_callback, self)
120+
obj:set_callback(callback.use_object, generic_physics_binder.use_callback, self)
121+
else
122+
if self.is_inventory_box then
123+
obj:set_callback(callback.use_object, generic_physics_binder.use_callback, self)
172124
end
173125
end
174-
-- treasure_manager.use_box(used_obj, user)
175126
end
176-
local obj_st = self.st
177-
if obj_st.active_section then
178-
xr_logic.issue_event(nil, obj_st[obj_st.active_scheme], "use_callback", used_obj, user)
127+
128+
if obj_st.active_scheme then
129+
xr_logic.issue_event(nil, obj_st[obj_st.active_scheme], "update", delta)
179130
end
131+
132+
xr_sound.update(obj:id())
133+
end
134+
135+
--------------------------------------------------------------------------------
136+
137+
function generic_physics_binder:clear_callbacks()
138+
local obj = self.object
139+
obj:set_callback(callback.hit, nil)
140+
obj:set_callback(callback.death, nil)
141+
obj:set_callback(callback.use_object, nil)
180142
end
181143

182144
function generic_physics_binder:hit_callback(victim, amount, local_direction, hitter, bone_index)
@@ -187,32 +149,65 @@ function generic_physics_binder:hit_callback(victim, amount, local_direction, hi
187149
xr_logic.issue_event(nil, obj_st.ph_on_hit, "hit_callback", victim, amount, local_direction, hitter, bone_index)
188150
end
189151

190-
if obj_st.active_section then
152+
if obj_st.active_scheme then
191153
xr_logic.issue_event(nil, obj_st[obj_st.active_scheme], "hit_callback", victim, amount, local_direction, hitter, bone_index)
192154
end
193155
end
194156

195157
function generic_physics_binder:death_callback(victim, culprit)
196158

159+
self:clear_callbacks()
160+
197161
local obj_st = self.st
198162

199-
if obj_st.active_section then
163+
if obj_st.active_scheme then
200164
xr_logic.issue_event(nil, obj_st[obj_st.active_scheme], "death_callback", victim, culprit)
201165
end
202166

203-
victim:set_callback(callback.hit, nil) -- SRP
204-
victim:set_callback(callback.death, nil) -- SRP
205-
victim:set_callback(callback.use_object, nil) -- SRP
206-
207167
if self.particle ~= nil then
208168
self.particle:stop()
209169
end
210170

211-
if self.disable_graph_point ~= nil then
212-
game_graph():accessible(self.disable_graph_point, true)
213-
end
214-
215171
if self.is_drop_box then
216172
self.box_items:spawn_items()
217173
end
174+
end
175+
176+
function generic_physics_binder:use_callback(used_obj, user)
177+
178+
if self.is_inventory_box then
179+
if used_obj:name() == "gar_smart_terrain_5_6_box" then
180+
local actor = db.actor
181+
if actor:has_info("gar_quest_redemption_started") then
182+
actor:give_info_portion("gar_quest_redemption_done")
183+
end
184+
end
185+
end
186+
187+
local obj_st = self.st
188+
189+
if obj_st.active_scheme then
190+
xr_logic.issue_event(nil, obj_st[obj_st.active_scheme], "use_callback", used_obj, user)
191+
end
192+
end
193+
194+
--------------------------------------------------------------------------------
195+
196+
function generic_physics_binder:net_save_relevant()
197+
return true
198+
end
199+
200+
function generic_physics_binder:save(packet)
201+
set_save_marker(packet, "save", false, "physics_binder")
202+
object_binder.save(self, packet)
203+
xr_logic.save_obj(self.object, packet)
204+
set_save_marker(packet, "save", true, "physics_binder")
205+
end
206+
207+
function generic_physics_binder:load(reader) -- called 4.5th (only on load)
208+
set_save_marker(reader, "load", false, "physics_binder")
209+
object_binder.load(self, reader)
210+
xr_logic.load_obj(self.object, reader)
211+
set_save_marker(reader, "load", true, "physics_binder")
212+
self.loaded = true
218213
end

0 commit comments

Comments
 (0)