212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
...
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
...
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
...
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
|
local portal_destination_evaluate = function(circuit,pos)
-- evaluation of the local network occurs before this function
-- is ever even called, so we only need to worry about the
-- farcaster-related transmission costs
for i,c in pairs(circuit) do
if vector.equals(c.pos,pos) then
print('found destination in circuit table',i,dump(c))
-- the destination is listed in the circuit table
for j,r in pairs(c.route) do
local nc = sorcery.ley.netcaps(pos,1)
print('checking route for sufficient energy to power farcasters', j, nc.freepower)
if nc.freepower < constants.portal_jump_cost_per_farcaster then
return false -- only one route to any given portal node
-- will be listed in the circuit table, so bail early
-- maybe in the future farcasters should charge up,
-- and power should be deducted when they are used?
end
end
................................................................................
end
end
return false
end
local portal_pick_destination = function(dev,circuit,partner)
if partner then
print('paired: evaluating partner')
if portal_destination_evaluate(circuit,partner)
then return partner end
print('partner failed eval')
end
local scrambled = sorcery.lib.tbl.scramble(circuit)
for i=1,#scrambled do
print('evaluating destination',i,dump(scrambled[i]))
if portal_destination_evaluate(circuit,scrambled[i].pos)
then return scrambled[i].pos end
print('eval failed')
end
print('no viable destinations in net')
end
-- minetest.register_lbm {
-- name = 'sorcery:activate_portals';
-- label = 'activate portals';
-- run_at_every_load = true;
-- nodenames = { 'sorcery:portal_node' };
................................................................................
partner = tune.partner
break
end
end
end
if cap.self.minpower ~= cap.self.powerdraw then
print("not enough power")
return true
end
-- clean out user table
for name,user in pairs(portal_context.users) do
if user and vector.equals(user.portal, pos) then
local found = false
................................................................................
user.time = 0
user.portal = pos
end
local cap = sorcery.ley.netcaps(pos,delta)
local jc = (constants.portal_jump_cost_local*delta)
if not user.dest and cap.freepower >= jc then
user.dest = portal_pick_destination(dev,crc,partner)
end
if not user.dest then goto skippad else
minetest.load_area(user.dest)
end
local fac = (user.time / constants.portal_jump_time);
minetest.add_particlespawner {
time = 1, amount = 100 + (fac * 200);
minsize = 0.2 + fac*0.7, maxsize = 0.4 + fac*0.9;
minvel = {y = 0.2, x=0,z=0}, maxvel = {y = 0.5, x=0,z=0};
minacc = {y = 0.0, x=0,z=0}, maxacc = {y = 0.3, x=0,z=0};
minpos = vector.add(n.pad,{x = -0.5, y = 0.5, z = -0.5});
|
|
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
...
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
...
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
...
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
|
local portal_destination_evaluate = function(circuit,pos)
-- evaluation of the local network occurs before this function
-- is ever even called, so we only need to worry about the
-- farcaster-related transmission costs
for i,c in pairs(circuit) do
if vector.equals(c.pos,pos) then
-- the destination is listed in the circuit table
for j,r in pairs(c.route) do
local nc = sorcery.ley.netcaps(pos,1)
-- print('checking route for sufficient energy to power farcasters', j, nc.freepower)
if nc.freepower < constants.portal_jump_cost_per_farcaster then
return false -- only one route to any given portal node
-- will be listed in the circuit table, so bail early
-- maybe in the future farcasters should charge up,
-- and power should be deducted when they are used?
end
end
................................................................................
end
end
return false
end
local portal_pick_destination = function(dev,circuit,partner)
if partner then
if portal_destination_evaluate(circuit,partner)
then return partner end
end
local scrambled = sorcery.lib.tbl.scramble(circuit)
for i=1,#scrambled do
if portal_destination_evaluate(circuit,scrambled[i].pos)
then return scrambled[i].pos end
end
end
-- minetest.register_lbm {
-- name = 'sorcery:activate_portals';
-- label = 'activate portals';
-- run_at_every_load = true;
-- nodenames = { 'sorcery:portal_node' };
................................................................................
partner = tune.partner
break
end
end
end
if cap.self.minpower ~= cap.self.powerdraw then
-- print("not enough power")
return true
end
-- clean out user table
for name,user in pairs(portal_context.users) do
if user and vector.equals(user.portal, pos) then
local found = false
................................................................................
user.time = 0
user.portal = pos
end
local cap = sorcery.ley.netcaps(pos,delta)
local jc = (constants.portal_jump_cost_local*delta)
if not user.dest and cap.freepower >= jc then
user.dest = portal_pick_destination(dev,crc,partner)
sorcery.lib.node.preload(user.dest, u.object)
end
if not user.dest then goto skippad end
local fac = (user.time / constants.portal_jump_time);
minetest.add_particlespawner {
time = 1, amount = 100 + (fac * 200);
minsize = 0.2 + fac*0.7, maxsize = 0.4 + fac*0.9;
minvel = {y = 0.2, x=0,z=0}, maxvel = {y = 0.5, x=0,z=0};
minacc = {y = 0.0, x=0,z=0}, maxacc = {y = 0.3, x=0,z=0};
minpos = vector.add(n.pad,{x = -0.5, y = 0.5, z = -0.5});
|