1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
..
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
..
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
...
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
...
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
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
262
263
264
265
266
...
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
...
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
...
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
...
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
...
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
|
-- [ʞ] starlit/init.lua
-- ~ lexi hale <lexi@hale.su>
-- ? basic setup, game rules, terrain
-- © EUPL v1.2
local T = minetest.get_translator 'starlit'
-- TODO enforce latest engine version
local mod = {
-- subordinate mods register here
lib = vtlib;
-- vtlib should be accessed as starlit.mod.lib by starlit modules for the sake of proper encapsulation. vtlib should simply be a provider, not a hardcoded dependency
}
local lib = mod.lib
starlit = {
ident = minetest.get_current_modname();
mod = mod;
translator = T;
constant = {
light = { --minetest units
dim = 3;
lamp = 7;
bright = 10;
brightest = 14; -- only sun and growlights
};
heat = { -- celsius
freezing = 0;
................................................................................
thermalConductivity = 0.05; -- κ
};
rad = {
};
phys = {
--- HACK HACK HAAAAAAAAAAACK
engineGravity = minetest.settings:get('movement_gravity') or 9.81
};
};
activeUsers = {
-- map of username -> user object
};
activeUI = {
................................................................................
-- standardized effects
fx = {};
type = {};
world = {
defaultScenario = 'starlit_scenario:imperialExpat';
seedbank = lib.math.seedbank(minetest.get_mapgen_setting 'seed');
mineral = lib.registry.mk 'starlit:mineral';
material = { -- raw materials
element = lib.registry.mk 'starlit:element';
-- elements are automatically sorted into the following categories
-- if they match. however, it's possible to have a metal/gas/liquid
-- that *isn't* a pure element, so these need separate registries
-- for alloys and mixtures like steel and water
................................................................................
};
jobs = {};
}
-- TODO deal with core.DEFAULT_PHYSICS once it hits master
starlit.cfgDir = minetest.get_worldpath() .. '/' .. starlit.ident
local logger = function(module)
local function argjoin(arg, nxt, ...)
if arg and not nxt then return tostring(arg) end
if not arg then return "(nil)" end
return tostring(arg) .. ' ' .. argjoin(nxt, ...)
end
local lg = {}
local setup = function(fn, lvl)
lvl = lvl or fn
local function emit(...)
local call = (fn == 'fatal') and error
or function(str) minetest.log(lvl, str) end
if module
then call(string.format('[%s :: %s] %s',starlit.ident,module,argjoin(...)))
else call(string.format('[%s] %s',starlit.ident,argjoin(...)))
end
end
lg[fn ] = function(...) emit(...) end
lg[fn .. 'f'] = function(...) emit(string.format(...)) end -- convenience fn
................................................................................
end
starlit.logger = logger
local log = logger()
function starlit.evaluate(name, ...)
local path = minetest.get_modpath(minetest.get_current_modname())
local filename = string.format('%s/%s', path, name)
log.info('loading', filename)
local chunk, err = loadfile(filename, filename)
if not chunk then error(err) end
return chunk(...)
end
function starlit.include(name, ...) -- semantic variant used for loading modules
return starlit.evaluate(name..'.lua', ...)
end
function starlit.region.radiator.scan(pos,node)
local R = starlit.region
local phash = minetest.hash_node_position(pos)
if R.radiator.sources[phash] then return end -- already loaded
node = node or minetest.get_node(pos)
local def = minetest.registered_nodes[node.name]
local cl = def._starlit and def._starlit.radiator
if not cl then return nil end
local min,max = cl.maxEffectArea and cl.maxEffectArea(pos) or nil
if not min then
assert(cl.radius, 'no radius callback for radiator')
local r = cl.radius(pos)
local vr = vector.new(r,r,r)
min,max = pos-vr, pos+vr
end
local id = R.radiator.store:insert_area(min,max, minetest.pos_to_string(pos))
R.radiator.sources[phash] = id
end
function starlit.region.radiator.unload(pos)
local R = starlit.region
local phash = minetest.hash_node_position(pos)
local id = R.radiator.sources[phash]
R.radiator.store:remove_area(id)
R.radiator.sources[phash] = nil
end
minetest.register_lbm {
label = 'build radiator index';
name = 'starlit:loadradiatorboxes';
nodenames = {'group:radiator'};
run_at_every_load = true;
action = function(pos, node, dt)
starlit.region.radiator.scan(pos, node)
end;
................................................................................
-- NOTE: temp emitter nodes are responsible for decaching themselves in their on_destruct cb
}
function starlit.startJob(id, interval, job)
local lastRun
local function start()
starlit.jobs[id] = minetest.after(interval, function()
local t = minetest.get_gametime()
local d = lastRun and t - lastRun or nil
lastRun = t
local continue = job(d, interval)
if continue == true or continue == nil then
start()
elseif continue ~= false then
interval = continue
................................................................................
starlit.include 'element'
starlit.include 'terrain'
starlit.include 'interfaces'
starlit.include 'compile'
starlit.include 'suit'
-- minetest.settings:set('movement_gravity', starlit.world.planet.gravity) -- ??? seriously???
-- THIS OVERRIDES THE GLOBAL SETTING *AND PERSISTS IT* WHAT IN THE SATANIC FUCK
---------------
-- callbacks --
---------------
-- here we connect our types up to the minetest API
local function userCB(fn)
return function(luser, ...)
local name = luser:get_player_name()
local user = starlit.activeUsers[name]
return fn(user, ...)
end
end
minetest.register_on_joinplayer(function(luser, lastLogin)
-- TODO check that necessary CSMs are installed
local user = starlit.type.user(luser)
if lastLogin == nil then
user:onSignup()
end
user:onJoin()
starlit.activeUsers[user.name] = user
end)
minetest.register_on_leaveplayer(function(luser)
starlit.activeUsers[luser:get_player_name()]:onPart()
end)
minetest.register_on_player_receive_fields(function(luser, formid, fields)
local name = luser:get_player_name()
local user = starlit.activeUsers[name]
if not user then return false end
if formid == '' then -- main menu
return starlit.ui.userMenuDispatch(user,fields)
end
local ui = starlit.interface.db[formid]
................................................................................
user:onRespond(ui, state, fields)
if fields.quit then
starlit.activeUI[name] = nil
end
return true
end)
minetest.register_on_respawnplayer(userCB(function(user)
return user:onRespawn()
end))
minetest.register_on_dieplayer(userCB(function(user, reason)
return user:onDie(reason)
end))
minetest.register_on_punchnode(function(pos,node,puncher,point)
local user = starlit.activeUsers[puncher:get_player_name()]
local oldTgt = user.action.tgt
user.action.tgt = point
if bit.band(user.action.bits, 0x80)==0 then
user.action.bits = bit.bor(user.action.bits, 0x80)
--user:trigger('primary', {state = 'init'})
else
................................................................................
user:trigger('retarget', {oldTgt = oldTgt})
end
end
-- sigh
--[[
core.noneitemdef_default.on_place = function(...)
if not triggerPower(...) then
minetest.item_place(...)
end
end
core.noneitemdef_default.on_use = function(...) triggerPower(...) end
core.noneitemdef_default.on_secondary_use = function(...) triggerPower(...) end
]]
minetest.register_item(":", {
type = "none",
wield_image = "wieldhand.png",
wield_scale = {x=1,y=1,z=2.5},
on_secondary_use = function(...) triggerPower(...) end;
-- on_use = function(...) print'base' end;
after_use = function(i,u,n,p)
if (u:is_player()) then triggerPower(i,u,p) end
end;
})
minetest.register_item("starlit:_hand_dig", {
type = "none",
wield_image = "wieldhand.png",
wield_scale = {x=1,y=1,z=2.5},
tool_capabilities = {
groupcaps = {
object = {maxlevel=1, times = {.10,.20,.40}};
plant = {maxlevel=1, times = {.50}};
................................................................................
-- sand, dirt, gravel
looseClump = {maxlevel=1, times = {1.5, 2.5}};
};
}
})
minetest.register_on_player_inventory_action(function(luser, act, inv, p)
local name = luser:get_player_name()
local user = starlit.activeUsers[name]
-- allow UIs to update on UI changes
local state = starlit.activeUI[name]
if state then
local ui = starlit.interface.db[state.form]
ui:cb('onMoveItem', user, act, inv, p)
end
end)
minetest.register_on_player_hpchange(function(luser, delta, cause)
local user = starlit.activeUsers[luser:get_player_name()]
if cause.type == 'fall' then
delta = user:damageModifier('bluntForceTrauma', (delta * 50))
-- justification: a short fall can do around
-- five points of damage, which is nearly 50%
-- of the default hp_max. since we crank up
-- hp by a factor of 50~40, damage should be
-- cranked by similarly
end
return delta
end, true)
function minetest.handle_node_drops(pos, drops, digger)
local function jitter(pos)
local function r(x) return x+math.random(-0.01, 0.01) end
return vector.new(
r(pos.x),
r(pos.y),
r(pos.z)
)
end
for i, it in ipairs(drops) do
if type(it) == 'string' then it = ItemStack(it) end
if not it:is_empty() then
local ent = minetest.add_item(jitter(pos), it)
if ent ~= nil then -- avoid crash when dropping unknown item
local dp = vector.new(0,0,0)
if digger then dp = digger:get_pos() end
local delta = dp - ent:get_pos()
ent:add_velocity(vector.new(delta.x,0,delta.z));
end
end
end
end
-- TODO timer iterates live UI
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
..
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
..
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
...
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
...
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
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
262
263
264
265
266
...
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
...
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
...
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
...
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
...
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
|
-- [ʞ] starlit/init.lua
-- ~ lexi hale <lexi@hale.su>
-- ? basic setup, game rules, terrain
-- © EUPL v1.2
local T = core.get_translator 'starlit'
-- TODO enforce latest engine version
local mod = {
-- subordinate mods register here
lib = vtlib;
-- vtlib should be accessed as starlit.mod.lib by starlit modules for the sake of proper encapsulation. vtlib should simply be a provider, not a hardcoded dependency
}
local lib = mod.lib
starlit = {
ident = core.get_current_modname();
mod = mod;
translator = T;
constant = {
light = { --luanti units
dim = 3;
lamp = 7;
bright = 10;
brightest = 14; -- only sun and growlights
};
heat = { -- celsius
freezing = 0;
................................................................................
thermalConductivity = 0.05; -- κ
};
rad = {
};
phys = {
--- HACK HACK HAAAAAAAAAAACK
engineGravity = core.settings:get('movement_gravity') or 9.81
};
};
activeUsers = {
-- map of username -> user object
};
activeUI = {
................................................................................
-- standardized effects
fx = {};
type = {};
world = {
defaultScenario = 'starlit_scenario:imperialExpat';
seedbank = lib.math.seedbank(core.get_mapgen_setting 'seed');
mineral = lib.registry.mk 'starlit:mineral';
material = { -- raw materials
element = lib.registry.mk 'starlit:element';
-- elements are automatically sorted into the following categories
-- if they match. however, it's possible to have a metal/gas/liquid
-- that *isn't* a pure element, so these need separate registries
-- for alloys and mixtures like steel and water
................................................................................
};
jobs = {};
}
-- TODO deal with core.DEFAULT_PHYSICS once it hits master
starlit.cfgDir = core.get_worldpath() .. '/' .. starlit.ident
local logger = function(module)
local function argjoin(arg, nxt, ...)
if arg and not nxt then return tostring(arg) end
if not arg then return "(nil)" end
return tostring(arg) .. ' ' .. argjoin(nxt, ...)
end
local lg = {}
local setup = function(fn, lvl)
lvl = lvl or fn
local function emit(...)
local call = (fn == 'fatal') and error
or function(str) core.log(lvl, str) end
if module
then call(string.format('[%s :: %s] %s',starlit.ident,module,argjoin(...)))
else call(string.format('[%s] %s',starlit.ident,argjoin(...)))
end
end
lg[fn ] = function(...) emit(...) end
lg[fn .. 'f'] = function(...) emit(string.format(...)) end -- convenience fn
................................................................................
end
starlit.logger = logger
local log = logger()
function starlit.evaluate(name, ...)
local path = core.get_modpath(core.get_current_modname())
local filename = string.format('%s/%s', path, name)
log.info('loading', filename)
local chunk, err = loadfile(filename, filename)
if not chunk then error(err) end
return chunk(...)
end
function starlit.include(name, ...) -- semantic variant used for loading modules
return starlit.evaluate(name..'.lua', ...)
end
function starlit.region.radiator.scan(pos,node)
local R = starlit.region
local phash = core.hash_node_position(pos)
if R.radiator.sources[phash] then return end -- already loaded
node = node or core.get_node(pos)
local def = core.registered_nodes[node.name]
local cl = def._starlit and def._starlit.radiator
if not cl then return nil end
local min,max = cl.maxEffectArea and cl.maxEffectArea(pos) or nil
if not min then
assert(cl.radius, 'no radius callback for radiator')
local r = cl.radius(pos)
local vr = vector.new(r,r,r)
min,max = pos-vr, pos+vr
end
local id = R.radiator.store:insert_area(min,max, core.pos_to_string(pos))
R.radiator.sources[phash] = id
end
function starlit.region.radiator.unload(pos)
local R = starlit.region
local phash = core.hash_node_position(pos)
local id = R.radiator.sources[phash]
R.radiator.store:remove_area(id)
R.radiator.sources[phash] = nil
end
core.register_lbm {
label = 'build radiator index';
name = 'starlit:loadradiatorboxes';
nodenames = {'group:radiator'};
run_at_every_load = true;
action = function(pos, node, dt)
starlit.region.radiator.scan(pos, node)
end;
................................................................................
-- NOTE: temp emitter nodes are responsible for decaching themselves in their on_destruct cb
}
function starlit.startJob(id, interval, job)
local lastRun
local function start()
starlit.jobs[id] = core.after(interval, function()
local t = core.get_gametime()
local d = lastRun and t - lastRun or nil
lastRun = t
local continue = job(d, interval)
if continue == true or continue == nil then
start()
elseif continue ~= false then
interval = continue
................................................................................
starlit.include 'element'
starlit.include 'terrain'
starlit.include 'interfaces'
starlit.include 'compile'
starlit.include 'suit'
-- core.settings:set('movement_gravity', starlit.world.planet.gravity) -- ??? seriously???
-- THIS OVERRIDES THE GLOBAL SETTING *AND PERSISTS IT* WHAT IN THE SATANIC FUCK
---------------
-- callbacks --
---------------
-- here we connect our types up to the luanti API
local function userCB(fn)
return function(luser, ...)
local name = luser:get_player_name()
local user = starlit.activeUsers[name]
return fn(user, ...)
end
end
core.register_on_joinplayer(function(luser, lastLogin)
-- TODO check that necessary CSMs are installed
local user = starlit.type.user(luser)
if lastLogin == nil then
user:onSignup()
end
user:onJoin()
starlit.activeUsers[user.name] = user
end)
core.register_on_leaveplayer(function(luser)
starlit.activeUsers[luser:get_player_name()]:onPart()
end)
core.register_on_player_receive_fields(function(luser, formid, fields)
local name = luser:get_player_name()
local user = starlit.activeUsers[name]
if not user then return false end
if formid == '' then -- main menu
return starlit.ui.userMenuDispatch(user,fields)
end
local ui = starlit.interface.db[formid]
................................................................................
user:onRespond(ui, state, fields)
if fields.quit then
starlit.activeUI[name] = nil
end
return true
end)
core.register_on_respawnplayer(userCB(function(user)
return user:onRespawn()
end))
core.register_on_dieplayer(userCB(function(user, reason)
return user:onDie(reason)
end))
core.register_on_punchnode(function(pos,node,puncher,point)
local user = starlit.activeUsers[puncher:get_player_name()]
local oldTgt = user.action.tgt
user.action.tgt = point
if bit.band(user.action.bits, 0x80)==0 then
user.action.bits = bit.bor(user.action.bits, 0x80)
--user:trigger('primary', {state = 'init'})
else
................................................................................
user:trigger('retarget', {oldTgt = oldTgt})
end
end
-- sigh
--[[
core.noneitemdef_default.on_place = function(...)
if not triggerPower(...) then
core.item_place(...)
end
end
core.noneitemdef_default.on_use = function(...) triggerPower(...) end
core.noneitemdef_default.on_secondary_use = function(...) triggerPower(...) end
]]
core.register_item(":", {
type = "none",
wield_image = "wieldhand.png",
wield_scale = {x=1,y=1,z=2.5},
on_secondary_use = function(...) triggerPower(...) end;
-- on_use = function(...) print'base' end;
after_use = function(i,u,n,p)
if (u:is_player()) then triggerPower(i,u,p) end
end;
})
core.register_item("starlit:_hand_dig", {
type = "none",
wield_image = "wieldhand.png",
wield_scale = {x=1,y=1,z=2.5},
tool_capabilities = {
groupcaps = {
object = {maxlevel=1, times = {.10,.20,.40}};
plant = {maxlevel=1, times = {.50}};
................................................................................
-- sand, dirt, gravel
looseClump = {maxlevel=1, times = {1.5, 2.5}};
};
}
})
core.register_on_player_inventory_action(function(luser, act, inv, p)
local name = luser:get_player_name()
local user = starlit.activeUsers[name]
-- allow UIs to update on UI changes
local state = starlit.activeUI[name]
if state then
local ui = starlit.interface.db[state.form]
ui:cb('onMoveItem', user, act, inv, p)
end
end)
core.register_on_player_hpchange(function(luser, delta, cause)
local user = starlit.activeUsers[luser:get_player_name()]
if cause.type == 'fall' then
delta = user:damageModifier('bluntForceTrauma', (delta * 50))
-- justification: a short fall can do around
-- five points of damage, which is nearly 50%
-- of the default hp_max. since we crank up
-- hp by a factor of 50~40, damage should be
-- cranked by similarly
end
return delta
end, true)
function core.handle_node_drops(pos, drops, digger)
local function jitter(pos)
local function r(x) return x+math.random(-0.01, 0.01) end
return vector.new(
r(pos.x),
r(pos.y),
r(pos.z)
)
end
for i, it in ipairs(drops) do
if type(it) == 'string' then it = ItemStack(it) end
if not it:is_empty() then
local ent = core.add_item(jitter(pos), it)
if ent ~= nil then -- avoid crash when dropping unknown item
local dp = vector.new(0,0,0)
if digger then dp = digger:get_pos() end
local delta = dp - ent:get_pos()
ent:add_velocity(vector.new(delta.x,0,delta.z));
end
end
end
end
-- TODO timer iterates live UI
|