-
Notifications
You must be signed in to change notification settings - Fork 4
/
_g.script
1310 lines (1183 loc) · 47.5 KB
/
_g.script
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
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
205
206
207
208
209
210
211
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
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
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--************************************************* Инициализация расширений движка ************************************************
log1("--LUA version: ["..(jit.version or _VERSION).."]")
log1("--MOD version: "..system_ini():r_string_wq("mod_ver", "mod_ver").." "..stdfs.path(getFS():update_path( "$fs_root$", "gamedata.db_base_configs" )).last_write_time_string_short)
--==============================================================================================
FFI = require('ffi') --Делать только здесь и только один раз!
--==============================================================================================
prefetch("ansi_functions")
--=======================================[Константы]============================================
NO_ACTIVE_SLOT = 255
BI_NONE = 65535
INVALID_STORY_ID = 4294967295
--==============================================================================================
math.randomseed(os.time())
--=================================[Функции из xrLuaFix]========================================
--Срезать пробелы слева
string.trim_l = function(s) return s:gsub("^%s+", '') end
--Срезать пробелы справа
string.trim_r = function(s) return s:gsub("%s*$", '') end
--Срезать все пробелы слева и справа
string.trim = function(s) return s:match( "^%s*(.*%S)" ) or "" end
--==============================================================================================
-- Взято из аддона Naxac'a
local to_ptrn = {
[' '] = '%s',
['.'] = '%.',
['%'] = '%%',
['*'] = '%*',
['-'] = '%-'
}
string.explode = function ( div, -- разделитель
str, -- строка
clear ) -- обрезать ли пробелы по краям строк (false/true)
local ret = {}
for s in str:gmatch("([^"..(to_ptrn[div] or div).."]+)") do
ret[#ret+1] = (clear and s:trim() or s)
end
return ret
end
--==============================================================================================
-- очистка строки от "лишних" символов (полезно при работе с FS)
string.clear = function(str) --KRodin: поправил функцию, теперь работает.
return str:gsub( '[/:<>|%*%?"\\]*', "" )
end
--==============================================================================================
-- Форматирование текста по ширине
-- http://www.amk-team.ru/forum/topic/13216-sborochnyy-ceh/?do=findComment&comment=959286
string.width = function(str, width, return_table, indent, paragrapf)
indent = indent or 0
paragrapf = paragrapf or 0
width = (width or 80) - indent
local i = string.rep(' ', indent)
local t = {}
local line = string.rep(' ', paragrapf)
for exp, word in str:gmatch('(%s-(%S+))') do
if line == '' and #t ~= 0 then
exp = word
end
local l_len = #line
local len = l_len + #exp
if len > width then
t[#t+1], line = line, word
else
line = line .. exp
if l_len == width then
t[#t+1], line = line, ''
end
end
end
t[#t+1] = line
if return_table then
return t
else
return i .. table.concat(t, '\n' .. i)
end
end
--==============================================================================================
-- поверхностное (простое) клонирование таблицы:
-- создаётся копия таблицы и копии всех элементов без их клонирования,
-- т.е. для ссылочных типов обе таблицы будут содержать ссылки на одни и те же данные
-- метатаблицы не копируются
function table.clone_simple(tbl)
local res = {}
for k,v in pairs(tbl) do
res[k] = v
end
return res
end
--==============================================================================================
function table.copy(tbl) --Возвращает копию таблицы.
local mt = getmetatable(tbl)
local res = {}
for k, v in pairs(tbl) do
if type(k) == "table" then
k = table.copy(k)
end
if type(v) == "table" then
v = table.copy(v)
end
res[k] = v
end
setmetatable(res, mt)
return res
end
--=================================[CUIScriptWnd Extension]=====================================
-- Вызов обычный, как и в AddCallback, но после последнего аргумента можно передавать множество дополнительных.
function CUIScriptWnd:Connect(name, event, func, ...)
local args = {...}
return self:AddCallback( name, event, function() func(unpack(args)) end )
end
--=======================================[LuaXML]===============================================
prefetch("_luaxml")
DYN_XML_SAVE_PATH = getFS():update_path('$game_config$', 'ui\\ui_dynamic.xml') --Путь к динамическому XML файлу
--==============================================================================================
local _advance_game_time = level.advance_game_time
level.advance_game_time = function(game_ms) --KRodin: универсальная функция для перевода часов. Вынесена из менеджера сна.
_advance_game_time(game_ms) --Прокручивает игровое время вперед на заданное кол-во ИГРОВЫХ миллисекунд.
--
db.actor:update_condition() --Обновляем движковые эффекты здоровья
get_actor_obj():UpdateArtefactsOnBelt() --И эффекты артефактов
--
ogse_signals.get_mgr():call("after_time_change") --KRodin: Добавил специальный сигнал для обновления погодного менеджера, таймеров и прочих систем, зависящих от игрового времени.
--
ogse_signals.get_mgr():call("on_update", 0) --Учитываем все возможные скриптовые эффекты
--
--Malandrinus: Эта функция идёт как затычка к механизму прокрутки времени, который в ОГСЕ используется для сна.
--Я обнаружил, что после прокрутки времени происходят косяки с пересчётом состояний актора.
--Подробностей уже не помню, но лечилось это разовым игнорированием соответствующего обновления сразу после приращения времени.
--Для установки этого разового игнора и предназначена эта функция.
--Вполне допускаю, хотя уже и не помню точно, что вместе с актором пропускается обновление чего-то ещё.
-- http://www.amk-team.ru/forum/topic/10538-x-ray-extensions/page-50#entry975972
level.set_ignore_game_state_update()
end
--==============================================================================================
function get_ammo_size(obj) --Возвращает колличество патрон в пачке
return obj:get_current_ammo()
end
function set_ammo_size(obj, size) --Задать кол-во патронов в пачке
obj:set_ammo_box_curr(size)
end
function get_inv_item_slot( obj )
return obj:get_inventory_item().slot
end
function set_inv_item_slot( obj, slot )
obj:get_inventory_item().slot = slot
end
--==============================================================================================
--Для экспериментов.
--game_object.make_object_visible_somewhen = function() end
--==============================================================================================
--******************************************** Инициализация расширений движка закончена ********************************************
-- FIX Nazgool ------------------------------------------------------------------
-- Возможно подобные функции уже где-то и есть, но я пока не нашёл.
-- Проверки
function isTable (obj) return type(obj) == 'table' end
function isBoolean (obj) return type(obj) == 'boolean' end
function isNumber (obj) return type(obj) == 'number' end
function isFunction(obj) return type(obj) == 'function' end
function isString (obj) return type(obj) == 'string' end
function isUserdata(obj) return type(obj) == 'userdata' end
function isThread (obj) return type(obj) == 'thread' end
function isNil (obj) return obj == nil end -- не false, а именно nil
-- Проверка - пуста ли таблица или строка
-- Если параметр 'space' не nil/false, то строка, состоящая только из пробельных символов и(или) неразрывного пробела будет считаться пустой.
function isEmpty(obj, space)
if isString(obj) then
if space then return not obj:match('[^%s\160]+') end
return #obj == 0
end
if isTable(obj) then return next(obj) == nil end
return false
end
-- является ли таблица массивом
function isArray(tbl)
local n=0
for _ in pairs(tbl) do n=n+1 end
return n <= #tbl
end
-- Приведение значения переменной 'val' к булевому значению
function toBoolean(val)
return not not val
end
-- END FIX Nazgool -------------------------------------------------------------
----------------------------------------------------------------------
schemes = {} -- соответствие схем модулям
stypes = {} -- типы схем
--/ Загружает схему из файла на диске и активирует в мотиваторе.
--/ Здесь:
--/ filename - имя файла, в котором реализована схема, без расширения
--/ scheme - имя схемы
function load_scheme(filename, scheme, stype)
schemes[scheme] = filename
stypes[scheme] = stype
end
----------------------------------------------------------------------
function validate_enemy_object( enemy )
if not ( enemy and enemy.clsid ) then return false, nil end
if enemy.health == nil or enemy.health <= 0 then
return false, nil
end
if enemy.m_story_id ~= nil then -- это грязный хак чтобы выяснить не попался ли нам серверный объект
if not ( IsStalker( enemy ) or IsMonster( enemy) ) then
return false, nil
end
local id = enemy.id
local enemy_gameobj = level.object_by_id( id )
if not enemy_gameobj then
return false, nil
else
return true, enemy_gameobj
end
else
if not ( enemy:is_stalker() or enemy:is_actor() or enemy:is_monster() ) then
return false, nil
end
return true, enemy
end
end
----------------------------------------------------------------------
function action(obj, ...) --Пример использования можно увидеть в ogse_hitfx. Ещё используется в mob_walker.script и mob_camp.script, может ещё где-то.
local args = {...}
local act = entity_action()
for i=1, #args do
if args[i] ~= nil then
act:set_action(args[i])
--else
-- break
end
end
if obj ~= nil then
obj:command(act, false)
end
return entity_action(act)
end
----------------------------------------------------------------------
function distance_between(obj1, obj2)
return obj1:position():distance_to(obj2:position())
end
--/ Если один объект nil, например нет актера, то считаем, что он далеко
function distance_between_safe(obj1, obj2)
if(obj1 == nil or obj2 == nil) then return 100000 end
return obj1:position():distance_to(obj2:position())
end
--/ Проверка на инфопоршны, даже если игрока не существует
function has_alife_info(info_id)
return alife():has_info(0, info_id)
end
function if_then_else(cond, if_true, if_false)
return cond and if_true or if_false
end
-------------------------------------------------------------------------------------------------------
--Отличается от split_comma_separated_list тем, что кроме запятых обрабатывает ещё и пробелы.
function parse_names( s )
return string.explode(",", s, true)
end
--Конвертирует строку вида "actor, 0, actor_dolg, 1, actor_freedom, 2, ..."
--В таблицу вида { ["actor"] = "0", ["actor_dolg"] = "1", ["actor_freedom"] = "2", ... }
function parse_key_value( s )
if s == nil then return nil end --бывает и такое
local t = {}
local t0 = parse_names( s )
for i=1, #t0, 2 do
local key, nam = t0[i], t0[i+1]
ASSERT(nam, "parse_key_value [%s]: stopped at %s: [%s] - [%s]", s, i, key or "nil", nam or "nil")
t[key] = nam
end
return t
end
--Парсит строку вида "n1, n2, n3..." в таблицу { n1, n2, n3, ... } где n1, n2, n3... - числа
function parse_nums( s )
local t = {}
for i,entry in ipairs(parse_names( s )) do
local v = tonumber( entry )
ASSERT(v, "parse_nums: [%s], stopped at [%s]: [%s]", s, i, entry)
table.insert(t, v)
end
return t
end
-------------------------------------------------------------------------------------------------------
function get_clsid(npc)
--Надо бы изучить, в каких случаях сюда попадают несуществующие объекты,
--Исправить это, и тогда можно будет убрать эти нагромождения отсюда.
if not npc then return nil end
if npc and npc.id then
if type(npc.id) == "function" then
local id = npc:id()
local sobj = alife():object(id)
if sobj then
return npc:clsid()
else
--log1(debug.traceback())
--log3("!!DEBUG_GETCLSID NO_SRVOBJ [%s, %s]", id, npc:name() )
return nil
end
elseif type(npc.id) == "number" then
return npc:clsid()
else
log1(debug.traceback())
log1("!!DEBUG_GETCLSID GET_SOMETHING_STRANGE")
return nil
end
else
log1(debug.traceback())
log1("!!DEBUG_GETCLSID DEAD_ON_ARRIVAL")
return nil
end
--
--if npc then return npc:clsid() end
--return nil
end
--/ Вычисляет yaw в радианах
function yaw(v1, v2)
return math.abs(v2:getH() - v1:getH())
end
function yaw_degree(...)
return yaw(...) * 57.295779513
end
function yaw_degree3d(v1, v2)
return math.acos(v1:dotproduct(v2)) * 57.295779513
end
function vector_cross(...)
return vector():crossproduct(...)
end
--/ Вращает вектор вокруг оси y против часовой стрелки
function vector_rotate_y(v, angle)
angle = angle * 0.017453292519943295769236907684886
local c = math.cos (angle)
local s = math.sin (angle)
return vector ():set (v.x * c - v.z * s, v.y, v.x * s + v.z * c)
end
function stop_play_sound(obj)
if obj:alive() == true then
obj:set_sound_mask(-1)
obj:set_sound_mask(0)
end
end
-------------------------------------------------------------------------------------------
function switch_online(id)
alife():set_switch_online (id, true)
alife():set_switch_offline(id, false)
end
-------------------------------------------------------------------------------------------
function switch_offline(id)
alife():set_switch_online (id, false)
alife():set_switch_offline(id, true)
end
-------------------------------------------------------------------------------------------
local monster_classes = {}
-------------------------------------------------------------------------------------------
local anomaly_classes = {}
-------------------------------------------------------------------------------------------
local stalker_classes = {}
-------------------------------------------------------------------------------------------
local weapon_classes = {}
-------------------------------------------------------------------------------------------
local outfit_classes = {}
-------------------------------------------------------------------------------------------
function IsMonster(object, class_id)
local id = class_id or get_clsid(object)
return id and monster_classes[id]
end
-------------------------------------------------------------------------------------------
function IsActor(object, class_id)
local id = class_id or get_clsid(object)
return id == clsid.actor
end
-------------------------------------------------------------------------------------------
function IsStalker(object, class_id)
local id = class_id or get_clsid(object)
return id and stalker_classes[id]
end
-------------------------------------------------------------------------------------------
function IsAnomaly(object, class_id)
local id = class_id or get_clsid(object)
return id and anomaly_classes[id]
end
-------------------------------------------------------------------------------------------
function isWeapon(object, class_id)
local id = class_id or get_clsid(object)
return id and weapon_classes[id]
end
-------------------------------------------------------------------------------------------
function isOutfit(object, class_id)
local id = class_id or get_clsid(object)
return id and outfit_classes[id]
end
-------------------------------------------------------------------------------------------
function isLc(object, class_id)
local id = class_id or get_clsid(object)
return id == clsid.level_changer
end
-------------------------------------------------------------------------------------------
function isKnife(object, class_id)
local id = class_id or get_clsid(object)
return id == clsid.wpn_knife or id == clsid.wpn_knife_s
end
-------------------------------------------------------------------------------------------
function IsInventoryBox( object, class_id )
local id = class_id or get_clsid( object )
return id == clsid.inventory_box or id == clsid.inventory_container
end
-------------------------------------------------------------------------------------------
function isIndoor(level_name) --KRodin: всем подземным уровням прописывается НЕ default погода. По этому признаку и будем проверять.
return get_string(level_name, "weathers", nil, game_ini()) ~= "default"
end
-------------------------------------------------------------------------------------------
function id_by_sid( sid )
local sim = alife()
if sim then
local se_obj = sim:story_object( sid )
if se_obj then
return se_obj.id
end
end
return nil
end
function level_object_by_sid( sid )
local id = id_by_sid( sid )
if id then
return level.object_by_id(id)
end
return nil
end
-- Крешнуть игру (после вывода сообщения об ошибке в лог)
function abort(fmt, ...)
log1("!!****************************[ABORT]*********************************")
log1(debug.traceback())
log3(fmt, ...)
log1("!!********************************************************************")
error(tostring(fmt))
end
--/ проверяет целую часть числа на нечётность
function odd( x )
return math.floor( x * 0.5 ) * 2 == math.floor( x )
end
--/ Усталость
function on_actor_critical_power()
if not has_alife_info("encyclopedy_tutorial_weakness") then
game.start_tutorial("part_11_weakness")
db.actor:give_info_portion("encyclopedy_tutorial_weakness")
end
end
function on_actor_critical_max_power()
end
--/ Кровотечение
function on_actor_bleeding()
if not has_alife_info("encyclopedy_tutorial_wound") then
game.start_tutorial("part_8_wound")
db.actor:give_info_portion("encyclopedy_tutorial_wound")
end
end
--/ Жажда
function on_actor_thirst()
end
--/ Голод
function on_actor_satiety()
if not ogse_sleep_mgr.is_sleep_active() then
if not has_alife_info("encyclopedy_tutorial_satiety") then
game.start_tutorial("part_13_satiety")
db.actor:give_info_portion("encyclopedy_tutorial_satiety")
end
end
end
--/ Радиация
function on_actor_radiation()
if not has_alife_info("encyclopedy_tutorial_radiation") then
game.start_tutorial("part_6_radiation")
db.actor:give_info_portion("encyclopedy_tutorial_radiation")
end
end
--/ Заклинило оружие
function on_actor_weapon_jammed()
if not has_alife_info("encyclopedy_tutorial_weapon") then
game.start_tutorial("part_9_weapon")
db.actor:give_info_portion("encyclopedy_tutorial_weapon")
end
end
--/ не может ходить изза веса
function on_actor_cant_walk_weight()
if not has_alife_info("encyclopedy_tutorial_overload") then
game.start_tutorial("part_14_overload")
db.actor:give_info_portion("encyclopedy_tutorial_overload")
end
end
--/ пси воздействие
function on_actor_psy()
if not has_alife_info("encyclopedy_tutorial_psy") then
game.start_tutorial("part_7_psy")
db.actor:give_info_portion("encyclopedy_tutorial_psy")
end
end
function set_actor_rank(rank)
if rank == "novice" then
db.actor:set_character_rank(0)
elseif rank == "stalker" then
db.actor:set_character_rank(300)
elseif rank == "veteran" then
db.actor:set_character_rank(600)
elseif rank == "master" then
db.actor:set_character_rank(900)
end
end
function get_texture_info(id_name, id_default)
if id_default == nil then id_default = id_name end
local task_info = GetTextureInfo(id_name, id_default)
local r = task_info:get_rect()
r.x2 = r.x2 - r.x1
r.y2 = r.y2 - r.y1
return task_info:get_file_name(), r
end
function start_game_callback()
monster_classes = {
[clsid.bloodsucker] = true,
[clsid.boar] = true,
[clsid.dog_red] = true,
[clsid.dog_black] = true,
[clsid.flesh] = true,
[clsid.burer] = true,
[clsid.cat] = true,
[clsid.chimera] = true,
[clsid.controller] = true,
[clsid.fracture] = true,
[clsid.poltergeist] = true,
[clsid.zombie] = true,
[clsid.snork] = true,
[clsid.tushkano] = true,
[clsid.psy_dog] = true,
[clsid.psy_dog_phantom] = true,
[clsid.pseudo_gigant] = true,
[clsid.bloodsucker_s] = true,
[clsid.boar_s] = true,
[clsid.dog_s] = true,
[clsid.flesh_s] = true,
[clsid.pseudodog_s] = true,
[clsid.burer_s] = true,
[clsid.cat_s] = true,
[clsid.chimera_s] = true,
[clsid.controller_s] = true,
[clsid.fracture_s] = true,
[clsid.poltergeist_s] = true,
[clsid.gigant_s] = true,
[clsid.zombie_s] = true,
[clsid.snork_s] = true,
[clsid.tushkano_s] = true,
[clsid.psy_dog_s] = true,
[clsid.psy_dog_phantom_s] = true
}
anomaly_classes = {
[clsid.zone_acid_fog] = true,
[clsid.zone_bfuzz] = true,
[clsid.zone_bfuzz_s] = true,
[clsid.zone_dead] = true,
[clsid.zone_galant_s] = true,
[clsid.zone_galantine] = true,
[clsid.zone_mbald_s] = true,
[clsid.zone_mincer] = true,
[clsid.zone_mincer_s] = true,
[clsid.zone_mosquito_bald] = true,
[clsid.ameba_zone] = true,
[clsid.zone_rusty_hair] = true,
[clsid.torrid_zone] = true,
[clsid.zone_radioactive] = true
}
stalker_classes = {
[clsid.actor] = true,
[clsid.script_stalker] = true
}
weapon_classes = {
[clsid.wpn_ak74] = true,
[clsid.wpn_ak74_s] = true,
[clsid.wpn_binocular] = true,
[clsid.wpn_binocular_s] = true,
[clsid.wpn_bm16] = true,
[clsid.wpn_bm16_s] = true,
[clsid.wpn_fn2000] = true,
[clsid.wpn_fort] = true,
[clsid.wpn_grenade_f1] = true,
[clsid.wpn_grenade_fake] = true,
[clsid.wpn_grenade_launcher] = true,
[clsid.wpn_grenade_rgd5] = true,
[clsid.wpn_grenade_rpg7] = true,
[clsid.wpn_groza] = true,
[clsid.wpn_groza_s] = true,
[clsid.wpn_hpsa] = true,
[clsid.wpn_hpsa_s] = true,
[clsid.wpn_knife] = true,
[clsid.wpn_knife_s] = true,
[clsid.wpn_lr300] = true,
[clsid.wpn_lr300_s] = true,
[clsid.wpn_mounted] = true,
[clsid.wpn_pm] = true,
[clsid.wpn_pm_s] = true,
[clsid.wpn_rg6] = true,
[clsid.wpn_rg6_s] = true,
[clsid.wpn_rpg7] = true,
[clsid.wpn_rpg7_s] = true,
[clsid.wpn_shotgun] = true,
[clsid.wpn_shotgun_s] = true,
[clsid.wpn_stat_mgun] = true,
[clsid.wpn_svd] = true,
[clsid.wpn_svd_s] = true,
[clsid.wpn_svu] = true,
[clsid.wpn_svu_s] = true,
[clsid.wpn_usp45] = true,
[clsid.wpn_usp45_s] = true,
[clsid.wpn_val] = true,
[clsid.wpn_val_s] = true,
[clsid.wpn_vintorez] = true,
[clsid.wpn_vintorez_s] = true
}
outfit_classes = {
[clsid.equ_exo] = true,
[clsid.equ_military] = true,
[clsid.equ_scientific] = true,
[clsid.equ_stalker] = true,
[clsid.equ_stalker_s] = true
}
m_netpk.attach()
dialog_manager.fill_phrase_table()
--
stdfs.recursive_directory_iterator( getFS():update_path( "$game_config$", "" ), function( file ) log3("~~[%s]", file.full_filename) end )
stdfs.recursive_directory_iterator( getFS():update_path( "$game_scripts$", "" ), function( file ) log3("~~[%s]", file.full_filename) end )
stdfs.recursive_directory_iterator( getFS():update_path( "$game_shaders$", "" ), function( file ) log3("~~[%s]", file.full_filename) end )
end
-------------------------------------------------------------------------------
-- Добавлено в OGSE --
-------------------------------------------------------------------------------
function ASSERT(cond, ...)
if not cond then
abort(...)
end
end
sys_ini = system_ini() --Из скриптов вызывать только sys_ini!!!!
-- служебные функции для чтения параметров из секций объектов
function get_string(section, param, def_val, ini_file)
local ini = ini_file or sys_ini
ASSERT(ini:section_exist(section), "get_string: section '"..section.."' doesn't exist")
if ini:line_exist(section, param) then
return ini:r_string(section, param)
else
return def_val
end
end
function get_string_wq(section, param, def_val, ini_file)
local ini = ini_file or sys_ini
ASSERT(ini:section_exist(section), "get_string: section '"..section.."' doesn't exist")
if ini:line_exist(section, param) then
return ini:r_string_wq(section, param)
else
return def_val
end
end
function get_u32(section, param, def_val, ini_file)
local ini = ini_file or sys_ini
ASSERT(ini:section_exist(section), "get_u32: section '"..section.."' doesn't exist")
if ini:line_exist(section, param) then
return ini:r_u32(section, param)
else
return def_val
end
end
function get_bool(section, param, def_val, ini_file)
local ini = ini_file or sys_ini
ASSERT(ini:section_exist(section), "get_bool: section '"..section.."' doesn't exist")
if ini:line_exist(section, param) then
return ini:r_bool(section, param)
else
return not (not def_val)
end
end
function get_float(section, param, def_val, ini_file)
local ini = ini_file or sys_ini
ASSERT(ini:section_exist(section), "get_float: section '"..section.."' doesn't exist")
if ini:line_exist(section, param) then
return ini:r_float(section, param)
else
return def_val
end
end
-- получить класс из секции, полезно в том случае, если нет объекта (и недоступен метод clsid), а есть только имя секции
function get_class(section)
ASSERT(sys_ini:section_exist(section), "get_class: section '"..section.."' doesn't exist")
ASSERT(sys_ini:line_exist(section, "class"), "get_class: there is no 'class' parameter in the section '"..section.."'")
return sys_ini:r_clsid(section, "class")
end
-- делит строку в виде "aaa,bbb,ccc" на строки "aaa", "bbb", "ccc" и возвращает их в виде массива
function split_comma_separated_list(s)
return string.explode(",", s)
end
-- читает время, сохранённое в виде строки со значениями, разделёнными запятой, и конвертирует в значение класса CTime
function unpack_time_from_string(str_time)
local time_values = {}
for i,s in ipairs(split_comma_separated_list(str_time)) do
local value = tonumber(s)
ASSERT(value, "unpack_time_from_string: problem with unpacking saved time '%s', value #%d (%s)", str_time, i, s)
table.insert(time_values, value)
end
ASSERT(#time_values == 7, "unpack_time_from_string: packed time '%s' has wrong number of components. Must be equal to seven.")
local res = game.CTime()
res:set(unpack(time_values))
return res
end
-- упаковать время в виде объекта CTime в строку значений, разделённых запятой
function pack_time_to_string(t)
ASSERT(t, "pack_time_to_string: t is a nil reference")
return table.concat({t:get()}, ',')
end
-- читает строку вида "s1,s2,s3" и парсит на строковые значения, разделённые запятой, в таблицу вида {s1, s2, s3}
function get_names(section, param, ini_file)
local ini = ini_file or sys_ini
ASSERT(ini:section_exist(section), "get_names: section '"..section.."' doesn't exist")
local s = ini:r_string(section, param)
return split_comma_separated_list(s)
end
-- читает строку вида "s1,s2,s3" и парсит на численные значения, разделённые запятой, в таблицу вида {n1, n2, n3}
function get_numbers(section, param, ini_file)
local t = {}
for i,sv in ipairs(get_names(section, param, ini_file)) do
local v = tonumber(sv)
ASSERT(v, "get_numbers: can not convert to number item ["..i.."]: "..sv)
table.insert(t, v)
end
return t
end
function get_section_keys(section, ini_file)
local ini = ini_file or sys_ini
ASSERT(ini:section_exist(section), "get_section_keys: section '"..section.."' doesn't exist")
local t = {}
for i=0,ini:line_count(section)-1 do
local _, key, v = ini:r_line(section, i)
t[i+1] = key
end
return t
end
function get_section_keys_and_values( section, ini_file )
local ini = ini_file or sys_ini
ASSERT( ini:section_exist( section ), "get_section_keys: section '" .. section .. "' doesn't exist" )
local t = {}
for i = 0, ini:line_count( section ) - 1 do
local _, key, v = ini:r_line( section, i )
t[ key ] = v
end
return t
end
function get_vector(section, param, def_val, ini_file)
local ini = ini_file or sys_ini
ASSERT(ini:section_exist(section), "get_vector: section '"..section.."' doesn't exist")
if ini:line_exist(section, param) then
local pos = get_names(section, param, ini)
return vector():set(tonumber(pos[1]), tonumber(pos[2]), tonumber(pos[3]))
else
if def_val then
return def_val
else
return vector():set(0,0,0)
end
end
end
-- значение по умолчанию должно задаваться таблицей {num1, num2}
function get_vector2(section, param, def_val, ini_file)
local ini = ini_file or sys_ini
ASSERT(ini:section_exist(section), "get_vector2: section '"..section.."' doesn't exist")
if ini:line_exist(section, param) then
local pos = get_names(section, param, ini)
return vector2():set(tonumber(pos[1]), tonumber(pos[2]))
else
if def_val then
return def_val
else
return vector2():set(0,0)
end
end
end
-- Берём параметры иконки из конфигов
function get_inventory_icon_rect(sect)
return 50*sys_ini:r_u32(sect, "inv_grid_x"), 50*sys_ini:r_u32(sect, "inv_grid_y"), 50*sys_ini:r_u32(sect, "inv_grid_width"), 50*sys_ini:r_u32(sect, "inv_grid_height")
end
-- получить номер локации по номеру глобального вертекса
function location_id_by_gvid(gvid)
if gvid and game_graph():valid_vertex_id( gvid ) then
return game_graph():vertex( gvid ):level_id()
end
end
-- получить номер локации для клиентского объекта
function object_location_id(obj)
local gvid = obj.game_vertex_id and obj:game_vertex_id() or obj.m_game_vertex_id
return location_id_by_gvid(gvid)
--return obj.level_id --Тут может вылетать, если у объекта невалидный gvid, походу.
end
function object_level_name(obj)
local lid = object_location_id( obj )
if lid then
return level_system_name_by_lid( lid )
end
--return obj.level_name --Тут может вылетать, если у объекта невалидный gvid, походу.
end
function level_system_name_by_lid(lid)
if lid then
return alife():level_name( lid )
end
end
function level_name_by_level_system_name(lname)
return game.translate_string(lname)
end
--системное имя уровня
function level_system_name_by_gvid(gvid)
return level_system_name_by_lid(location_id_by_gvid(gvid))
end
--Внятное имя уровня (не системное, а то, которое изображается на карте):
function level_name_by_gvid(gvid)
return level_name_by_level_system_name(level_system_name_by_gvid(gvid))
end
--***********************************[Функции для вывода в лог]****************************************
-----------------------------------------------------------------------------------------
local tostring_all_tbl = {
["table"] = function(table, ind) --Распечатка таблиц
local res = "{" --Начало
local end_res = ind and "\n"..ind.."}" or "\n}" --Конец
local def_ind = " " --Отступ от начала строки
ind = ind and ind..def_ind or def_ind --Для каждой "таблицы внутри таблицы" отступ увеличивается в 2 раза
for k, v in pairs(table) do
res = res.."\n"..ind.."["..tostring_all(k, ind).."] = "..tostring_all(v, ind)..","
end
return res..end_res
end,
["string"] = function(v) return "'"..v.."'" end, --Строки берём в кавычки. Это нужно, чтобы можно было отличить строку "123" от числа 123, "nil" от nil и тд...
["number"] = function(v) return tostring(v) end,
["boolean"] = function(v) return tostring(v) end,
["nil"] = function(v) return tostring(v) end,
["function"] = function() return "[[FUNCTION]]" end, --Function, Userdata и Thread распечатать нельзя, просто заменим на строки
["userdata"] = function(v) return tostring(v) or "[[USERDATA]]" end,
["thread"] = function() return "[[THREAD]]" end,
}
--Конвертирование чего угодно в строку. Использовать только для вывода в лог!
function tostring_all(obj, ind) --ind - служебный аргумент для распечатки "таблиц в таблицах".
return tostring_all_tbl[type(obj)](obj, ind)
end
--Функциональная обёртка для log1.
--Делает дополнительную работу по конвертации параметров, которые не воспринимаются родной функцией string.format.
--Параметры можно передавать ЛЮБОГО ТИПА! В строке формата они должны стоять как %s (потому, что будут сконвертированы в строки).
function log3(fmt, ...)
local args = {...}
for i=1, #args do
args[i] = tostring_all(args[i])
end
local res, msg = pcall(string.format, fmt, unpack(args))
--
--if res then msg = msg.."\nlog3 called from: "..debug.traceback() end
--
if not res then --Если произошла ошибка
msg = "!!log3 failed: "..msg.."\n"..debug.traceback()
end
log1(msg)
end
-----------------------------------------------------------------------------------------
local logs_cach = {}
--Функция создаёт новый лог-файл и выводит текст в него.
--fname - название лог-файла, например "Anomaly_Evader". Он будет создан в папке logs, к названию добавится дата и время создания.
--fmt, ... - строка формата с параметрами как и в функции log3
function log4(fname, fmt, ...)
local f = logs_cach[fname]
if not f then
local dt = os.date("*t")
local fpath = getFS():update_path("$logs$", string.format("%s_%02d.%02d.%02d_%02d.%02d.%02d.log",fname,dt.day,dt.month,dt.year,dt.hour,dt.min,dt.sec))
f = io.open(fpath, "w")
logs_cach[fname] = f
end
local args = {...}
for i=1, #args do
args[i] = tostring_all(args[i])
end
local res, msg = pcall(string.format, fmt, unpack(args))
if not res then
msg = "!!log4 failed: "..msg.."\n"..debug.traceback()
end
f:write(msg..'\n')
f:flush()
end
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
function log2(fmt, ...) --Простая обёртка для log1.
log1(fmt:format(...))
end
-----------------------------------------------------------------------------------------
function clear_log() --Очистить лог
cmd("clear_log")
end
-----------------------------------------------------------------------------------------
--*****************************************************************************************************
function print_vector(name, v)
log2("%s: %9.3f, %9.3f, %9.3f", name, v.x, v.y, v.z)
end
function print_matrix(name, m)
log1(name..":")
log2("[%9.3f, %9.3f, %9.3f, %9.3f]", m.i.x, m.i.y, m.i.z, m._14_)
log2("[%9.3f, %9.3f, %9.3f, %9.3f]", m.j.x, m.j.y, m.j.z, m._24_)
log2("[%9.3f, %9.3f, %9.3f, %9.3f]", m.k.x, m.k.y, m.k.z, m._34_)
log2("[%9.3f, %9.3f, %9.3f, %9.3f]", m.c.x, m.c.y, m.c.z, m._44_)
end
function time2string(time, fmt, order)
ASSERT(time, "[_g.time2string] 'time' is a nil reference")
if not fmt then
return time:timeToString(game.CTime.TimeToMilisecs).." "..time:dateToString(game.CTime.DateToDay)
else
local y,m,d,h,min,s,ms = time:get()
local args = {y=y,m=m,d=d,h=h,min=min,s=s,ms=ms}
if order then
args = {args[order[1]], args[order[2]], args[order[3]], args[order[4]], args[order[5]], args[order[6]], args[order[7]]}
end
return fmt:format(unpack(args))
end
end
function print_time(title, time)
log1(title..": "..time2string(time))
end
function hit_object(obj, dir, imp, dr, pow, t)
local h = hit()
h.direction = dir
h.impulse = imp
h.draftsman = dr
h.power = pow
h.type = t