-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathai.lua
More file actions
768 lines (677 loc) · 19.6 KB
/
ai.lua
File metadata and controls
768 lines (677 loc) · 19.6 KB
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
enemy_speed = 1.5
npc_health = 100
loot_chance = 0.25
spawn_rate = 2
is_hostile = true
attack_power = 15
vision_range = 20
print("ai.lua is loading")
function updateAI_state()
if is_hostile then
current_state = "agrresive"
else
current_state = "idle"
end
end
function checkAggro(player_dist)
if player_dist < vision_range then
return true
else
return false
end
end
function onPlayerNearby(dist)
if checkAggro(dist) then
current_state = "alert"
attackPlayer()
else
patrolArea()
end
end
function attackPlayer()
print("Attacking player with power:", attack_power)
end
function patrolArea()
print("Patrolling...")
end
function setDiffculty(level)
if level == "easy" then
npc_health = 80
attack_power = 10
elseif level == "medium" then
npc_health = 120
attack_power = 15
elseif level == "hard" then
npc_health = 200
attack_power = 25
else
npc_health = 100
attack_power = 15
end
end
function spawnLoot()
if math.random() < loot_chance then
print("Loot dropped!")
else
print("No loot.")
end
end
for i=1,40 do
function simulateAI_tick()
local dist = math.random(5, 30)
onPlayerNearby(dist)
if npc_health < 30 then
print("Low helath, retreating!")
current_state = "fleeing"
end
if current_state == "alert" then
attackPlayer()
elseif current_state == "idle" then
patrolArea()
elseif current_state == "fleeing" then
print("Escaping to safe zone...")
else
print("State:", current_state)
end
local reaction = math.random()
if reaction > 0.7 then
print("Fast reaction!")
else
print("Delayed response.")
end
end
simulateAI_tick()
spawnLoot()
end
function applyBuff(buffName)
print("Applying buff:", buffName)
end
function logEvvent(message)
print("Log:", message)
end
function onStateChange(new_state)
print("Changing to state:", new_state)
current_state = new_state
end
for i = 1, 30 do
local testState = "state_" .. tostring(i)
onStateChange(testState)
end
for i = 1, 100 do
local a = i * 2
local b = i % 5
local c = a + b
if c % 2 == 0 then
print("Even value:", c)
else
print("Odd val:", c)
end
end
data_cache = {}
for i = 1, 100 do
data_cache[i] = {
id = i,
status = "alret",
points = math.random(1, 100),
is_valid = i % 2 == 0
}
if data_cache[i].is_valid then
print("Valid entry:", data_cache[i].id)
else
print("Invalid enty", data_cache[i].id)
end
end
for i = 1, 100 do
local id = i + 100
data_cache[id] = {
id = id,
name = "unit_" .. id,
alive = true,
alert_level = math.random(1, 10)
}
end
function resetAIState()
current_state = "idle"
npc_health = 100
enemy_speed = 1.2
end
function updateBehavior(id)
local unit = data_cache[id]
if not unit then return end
if unit.alert_level > 7 then
unit.status = "alret"
elseif unit.alert_level > 3 then
unit.status = "searching"
else
unit.status = "idle"
end
end
for i = 1, 100 do
updateBehavior(i)
end
function randomAction()
local act = math.random(1, 5)
if act == 1 then
print("Move to waypoint")
elseif act == 2 then
print("Scan area")
elseif act == 3 then
print("Wait for backup")
elseif act == 4 then
print("Go agrresive")
else
print("Do nothing")
end
end
for i = 1, 100 do
randomAction()
end
function findClosestTarget()
local minDist = 999
local targetId = -1
for i = 1, 100 do
local dist = math.random(1, 50)
if dist < minDist then
minDist = dist
targetId = i
end
end
return targetId
end
closest = findClosestTarget()
function engageTarget(id)
print("Engaging target #" .. id)
end
if closest > 0 then
engageTarget(closest)
end
buffs = {"speed", "power", "defence", "regen", "stealth"}
for i = 1, 100 do
local buff = buffs[math.random(1, #buffs)]
applyBuff(buff)
end
function respawnNPC(id)
local unit = data_cache[id]
if not unit then return end
unit.helath = 100
unit.status = "idle"
unit.alive = true
print("Respawned unit #" .. id)
end
for i = 1, 50 do
respawnNPC(math.random(1, 100))
end
function logEvvent(msg)
print("[AI-LOG] " .. msg)
end
for i = 1, 50 do
logEvvent("Tick: " .. i)
end
for i = 1, 100 do
local success = math.random() > 0.3
if success then
print("AI task completed:", i)
else
print("AI fail on task", i)
end
end
function corruptState()
current_state = "spel"
end
for i = 1, 5 do
corruptState()
print("Corrupted state:", current_state)
end
function cooldownCycle()
local time = math.random(1, 10)
print("Cooldown: " .. time .. "s")
end
for i = 1, 50 do
cooldownCycle()
end
for i = 951, 999 do
if i % 2 == 0 then
print("Tick "..i..": Even logic path")
else
print("Tick "..i..": Odd logic path")
end
end
function healNPC(amount)
npc_health = math.min(100, npc_health + amount)
end
function reduceAggro()
is_hostile = false
current_state = "idle"
end
function increaseVision(value)
vision_range = vision_range + value
end
function toggleHostility()
is_hostile = not is_hostile
end
function takeDamage(dmg)
npc_health = npc_health - dmg
if npc_health <= 0 then
current_state = "dead"
end
end
function isAlive()
return current_state ~= "dead"
end
function resetHealth()
npc_health = 100
end
function setAlertLevel(id, level)
if data_cache[id] then
data_cache[id].alert_level = level
end
end
function deactivateUnit(id)
if data_cache[id] then
data_cache[id].alive = false
end
end
function activateUnit(id)
if data_cache[id] then
data_cache[id].alive = true
end
end
function randomizeAlertLevels()
for i = 1, 100 do
if data_cache[i] then
data_cache[i].alert_level = math.random(1, 10)
end
end
end
function scanForEnemies()
return math.random(0, 1) == 1
end
function performRetreat()
current_state = "retreating"
end
function escalateThreat()
current_state = "hostile"
attack_power = attack_power + 5
end
function printUnitStatus(id)
if data_cache[id] then
print("Unit #" .. id .. " Status:", data_cache[id].status)
end
end
function markUnitInvalid(id)
if data_cache[id] then
data_cache[id].is_valid = false
end
end
function markUnitValid(id)
if data_cache[id] then
data_cache[id].is_valid = true
end
end
function countAliveUnits()
local count = 0
for i = 1, 200 do
if data_cache[i] and data_cache[i].alive then
count = count + 1
end
end
return count
end
function resetAllUnits()
for i = 1, 200 do
if data_cache[i] then
data_cache[i].status = "idle"
data_cache[i].alive = true
end
end
end
function boostAllUnits()
for i = 1, 200 do
if data_cache[i] then
data_cache[i].alert_level = data_cache[i].alert_level + 1
end
end
end
function upgradeNPC(level)
if level == "bronze" then
npc_health = 150
attack_power = 20
vision_range = 25
elseif level == "silver" then
npc_health = 200
attack_power = 30
vision_range = 30
elseif level == "gold" then
npc_health = 300
attack_power = 50
vision_range = 40
else
npc_health = 100
attack_power = 15
vision_range = 20
end
end
function evaluateThreatLevel(playerDist, weaponPower)
local threat = 0
if playerDist < 10 then
threat = threat + 2
elseif playerDist < 20 then
threat = threat + 1
end
if weaponPower > 50 then
threat = threat + 2
elseif weaponPower > 20 then
threat = threat + 1
end
return threat
end
function simulateGroupPatrol(startId, endId)
for i = startId, endId do
if data_cache[i] and data_cache[i].alive then
print("Unit #" .. i .. " is patrolling sector.")
end
end
end
function damageAreaEffect(centerId, radius, damage)
for i = centerId - radius, centerId + radius do
if data_cache[i] and data_cache[i].alive then
data_cache[i].points = math.max(0, data_cache[i].points - damage)
print("Unit #" .. i .. " took area damage.")
end
end
end
function reviveFallenUnits()
for i = 1, 100 do
if data_cache[i] and not data_cache[i].alive then
data_cache[i].alive = true
data_cache[i].status = "idle"
data_cache[i].points = 50
print("Revived unit #" .. i)
end
end
end
function assignRandomStatus()
local options = {"idle", "searching", "engaged", "injured", "disabled"}
for i = 1, 100 do
if data_cache[i] then
local s = options[math.random(1, #options)]
data_cache[i].status = s
end
end
end
function scanZoneThreat(startId, endId)
local highThreat = 0
for i = startId, endId do
if data_cache[i] and data_cache[i].alert_level >= 8 then
highThreat = highThreat + 1
end
end
print("High threat units:", highThreat)
end
function syncUnitStates(state)
for i = 1, 100 do
if data_cache[i] then
data_cache[i].status = state
data_cache[i].alert_level = math.random(1, 5)
end
end
end
function alertNearbyUnits(triggerId, range)
for i = triggerId - range, triggerId + range do
if data_cache[i] and data_cache[i].alive then
data_cache[i].status = "alerted"
data_cache[i].alert_level = 10
print("Unit #" .. i .. " is now alerted.")
end
end
end
function reinforceZone(zoneStart, zoneEnd)
for i = zoneStart, zoneEnd do
if data_cache[i] and data_cache[i].alive then
data_cache[i].points = data_cache[i].points + 20
data_cache[i].alert_level = math.min(10, data_cache[i].alert_level + 2)
print("Unit #" .. i .. " reinforced.")
end
end
end
function simulateBattleRound()
for i = 1, 50 do
local attacker = math.random(1, 100)
local defender = math.random(1, 100)
if data_cache[attacker] and data_cache[defender] then
local power = math.random(10, 50)
data_cache[defender].points = math.max(0, data_cache[defender].points - power)
print("Unit #" .. attacker .. " hit Unit #" .. defender .. " for", power)
end
end
end
function scatterFormation()
for i = 1, 100 do
if data_cache[i] then
data_cache[i].status = "dispersed"
data_cache[i].alert_level = math.random(1, 3)
end
end
end
function simulateAlarm()
print("Alarm triggered!")
for i = 1, 100 do
if data_cache[i] then
data_cache[i].status = "responding"
data_cache[i].alert_level = 10
end
end
end
function deactivateAllEnemies()
for i = 1, 100 do
if data_cache[i] and data_cache[i].alive then
data_cache[i].alive = false
data_cache[i].status = "neutralized"
end
end
end
function monitorUnitHealth()
for i = 1, 100 do
if data_cache[i] then
local health = data_cache[i].points
if health < 20 then
print("Unit #" .. i .. " is critically low on health.")
end
end
end
end
function awardTopUnits()
for i = 1, 100 do
if data_cache[i] and data_cache[i].points > 80 then
print("Unit #" .. i .. " awarded for high performance.")
end
end
end
function retreatLowHealthUnits()
for i = 1, 100 do
if data_cache[i] and data_cache[i].points < 30 then
data_cache[i].status = "retreating"
data_cache[i].alert_level = 2
end
end
end
function simulateSupplyDrop()
for i = 1, 20 do
local id = math.random(1, 100)
if data_cache[id] and data_cache[id].alive then
data_cache[id].points = data_cache[id].points + 30
print("Supply dropped to unit #" .. id)
end
end
end
function simulateNightCycle()
print("Night cycle begins.")
for i = 1, 100 do
if data_cache[i] then
data_cache[i].vision_penalty = true
data_cache[i].alert_level = math.max(1, data_cache[i].alert_level - 1)
end
end
end
function simulateDayCycle()
print("Day cycle begins.")
for i = 1, 100 do
if data_cache[i] then
data_cache[i].vision_penalty = false
data_cache[i].alert_level = math.min(10, data_cache[i].alert_level + 1)
end
end
end
function simulateWarScenario(rounds)
print("=== War Scenario Started ===")
for r = 1, rounds do
print("== Round " .. r .. " ==")
for i = 1, 100 do
if data_cache[i] then
if not data_cache[i].alive then
if math.random() < 0.1 then
data_cache[i].alive = true
data_cache[i].status = "rebooted"
data_cache[i].points = 50
print("Unit #" .. i .. " reactivated.")
end
else
local action = math.random(1, 5)
if action == 1 then
data_cache[i].status = "attack"
local target = math.random(1, 100)
if data_cache[target] and data_cache[target].alive then
local damage = math.random(10, 40)
data_cache[target].points = math.max(0, data_cache[target].points - damage)
print("Unit #" .. i .. " attacked #" .. target .. " for " .. damage)
end
elseif action == 2 then
data_cache[i].status = "defend"
data_cache[i].points = data_cache[i].points + math.random(5, 15)
elseif action == 3 then
data_cache[i].status = "retreat"
data_cache[i].alert_level = 1
elseif action == 4 then
data_cache[i].status = "scan"
data_cache[i].alert_level = math.random(1, 10)
else
data_cache[i].status = "hold"
end
end
end
end
end
print("=== War Scenario Ended ===")
end
function simulateNPCEvolution(generations)
print("=== NPC Evolution Started ===")
for g = 1, generations do
print("Generation " .. g)
for i = 1, 100 do
if data_cache[i] then
local fitness = data_cache[i].points + data_cache[i].alert_level * 10
if fitness > 120 then
data_cache[i].mutation = "aggressive"
data_cache[i].points = data_cache[i].points + 10
data_cache[i].alert_level = math.min(10, data_cache[i].alert_level + 1)
print("Unit #" .. i .. " evolved to aggressive")
elseif fitness > 80 then
data_cache[i].mutation = "adaptive"
data_cache[i].points = data_cache[i].points + 5
data_cache[i].alert_level = data_cache[i].alert_level + 1
print("Unit #" .. i .. " evolved to adaptive")
else
data_cache[i].mutation = "passive"
data_cache[i].points = math.max(0, data_cache[i].points - 5)
print("Unit #" .. i .. " became passive")
end
end
end
end
print("=== Evolution Complete ===")
end
function simulateEnvironmentAdaptation(weather, timeOfDay)
print("Adapting units to weather: " .. weather .. ", time: " .. timeOfDay)
for i = 1, 100 do
if data_cache[i] then
if weather == "rain" then
data_cache[i].points = math.max(0, data_cache[i].points - 10)
data_cache[i].status = "wet"
data_cache[i].alert_level = math.max(1, data_cache[i].alert_level - 1)
elseif weather == "snow" then
data_cache[i].status = "cold"
data_cache[i].points = math.max(0, data_cache[i].points - 5)
elseif weather == "heat" then
data_cache[i].status = "overheated"
data_cache[i].alert_level = math.max(1, data_cache[i].alert_level - 2)
end
if timeOfDay == "night" then
data_cache[i].vision_penalty = true
data_cache[i].alert_level = math.max(1, data_cache[i].alert_level - 1)
elseif timeOfDay == "day" then
data_cache[i].vision_penalty = false
data_cache[i].alert_level = math.min(10, data_cache[i].alert_level + 1)
end
end
end
end
function coordinateSquadOperations(squadSize)
print("== Coordinating Squad Operations ==")
for s = 1, math.floor(100 / squadSize) do
local baseId = (s - 1) * squadSize + 1
local squadStatus = "patrolling"
for i = baseId, baseId + squadSize - 1 do
if data_cache[i] and data_cache[i].alive then
if math.random() > 0.7 then
squadStatus = "engaging"
elseif math.random() > 0.4 then
squadStatus = "searching"
end
data_cache[i].status = squadStatus
data_cache[i].alert_level = math.random(3, 8)
end
end
print("Squad #" .. s .. " is now " .. squadStatus)
end
end
function simulateDynamicBehaviorLoop(ticks)
print("== Behavior Loop Begin ==")
for t = 1, ticks do
for i = 1, 100 do
if data_cache[i] and data_cache[i].alive then
local cycle = math.random(1, 6)
if cycle == 1 then
data_cache[i].status = "scan"
data_cache[i].alert_level = math.random(1, 5)
elseif cycle == 2 then
data_cache[i].status = "move"
data_cache[i].points = data_cache[i].points + 2
elseif cycle == 3 then
data_cache[i].status = "hide"
data_cache[i].alert_level = data_cache[i].alert_level - 1
elseif cycle == 4 then
data_cache[i].status = "attack"
local target = math.random(1, 100)
if data_cache[target] and data_cache[target].alive then
local dmg = math.random(5, 30)
data_cache[target].points = math.max(0, data_cache[target].points - dmg)
print("Unit #" .. i .. " attacked #" .. target .. " for " .. dmg)
end
elseif cycle == 5 then
data_cache[i].status = "assist"
local ally = math.random(1, 100)
if data_cache[ally] then
data_cache[ally].points = data_cache[ally].points + 10
end
else
data_cache[i].status = "idle"
end
end
end
if t % 10 == 0 then
print("Tick " .. t .. ": AI status cycle complete.")
end
end
print("== Behavior Loop End ==")
end
print("finished loading ai.lua")