From 8d0f324fbc38a303f88b5fc103a69b2e73cff75b Mon Sep 17 00:00:00 2001 From: "Gustavo Rehermann (Gustavo6046)" Date: Fri, 3 May 2019 22:07:03 +0000 Subject: [PATCH] Geared bots for deathmatch --- CVarInfo.txt | 3 + ZScript.zsc | 113 ++++++++++++++++++++---- ZetaCode/Pathing.zsc | 6 +- ZetaCode/WeaponSupport/Doom/ZetaBFG.zsc | 7 +- ZetaCode/WeaponSupport/Doom/ZetaPR.zsc | 7 +- ZetaCode/WeaponSupport/Doom/ZetaRL.zsc | 7 +- ZetaCode/WeaponSupport/ZetaBullet.zsc | 8 +- acs/ZETAACS.o | Bin 80 -> 104 bytes acs/last_source.sha512 | 2 +- config | 2 +- source/ZETAACS.acs | 12 ++- 11 files changed, 140 insertions(+), 27 deletions(-) diff --git a/CVarInfo.txt b/CVarInfo.txt index 2b93f12..d9b4059 100644 --- a/CVarInfo.txt +++ b/CVarInfo.txt @@ -7,5 +7,8 @@ server float zb_autouseinterval = 9; server bool zb_autouse = true; server bool zb_autonodes = true; server bool zb_talk = true; +server bool zb_cooprespawn = false; +server bool zb_respawn = true; +server bool zb_autonoderespawn = true; server string zb_names = "Jack,Persephone,Ăˆmille,Robert,Amanda,Maria,Mary,Josh,Wagner,John,Louis,Gabriel,Renato,Alejandro,Alexander,Heinrich,Caesar,Walter,Amy,Lawrence,Marylenne,Leonhart,Leonard,Jackson,Lee,Bert,Humberto,Mike,Pablo,Michael,Hitchcock,Hilton,Ronald,Robinson,Son,House,Romulus,Peter,Peterson,Zephyrus,Robin,Paul,Paula,Thorson,Robohead,Minchson,James,Jamilton,Greg,Gregor,Gregory,Victoria,Anita,Whindersson,Melody,Xonon,Xihil,Thought,Hope,Rebecca,Prince,Larry,Barry,Garry,Garmond,Barney"; \ No newline at end of file diff --git a/ZScript.zsc b/ZScript.zsc index 0d915ef..6507454 100644 --- a/ZScript.zsc +++ b/ZScript.zsc @@ -278,7 +278,7 @@ class ZTBotController : Actor GruntInterval = 0; - if ( CVar.GetCVar('deathmatch').GetInt() == 1 ) + if ( CVar.GetCVar('deathmatch').GetInt() > 0 ) bFRIENDLY = false; debugCount = 0; @@ -362,6 +362,45 @@ class ZTBotController : Actor AimAtAngle(-possessed.AngleTo(other), speed, threshold); } + Class possessedType; + + void A_ZetaRespawn() { + if (possessedType == null) return; + + ZTPathNode pn, chosen = null; + double chanceDenom = 1; + uint found = 0; + + let iter = ThinkerIterator.Create("ZTPathNode", STAT_DEFAULT); + + while ((pn = ZTPathNode(iter.Next())) != null) { + if (pn.nodeType == ZTPathNode.NT_RESPAWN) { + double prob = FRandom(0, chanceDenom); + + if (prob <= 1.0) + chosen = pn; + + // DebugLog(LT_VERBOSE, String.format("Node %i at x=%f,y=%f has luck value %f/%f.", ++found, pn.pos.x, pn.pos.y, 0 - prob, chanceDenom)); + + chanceDenom++; + } + } + + if (chosen == null) { + if (possessed == null) Destroy(); + return; + } + + Vector3 spawnPos = chosen.pos; + spawnPos.x += FRandom(-16, 16); + spawnPos.y += FRandom(-16, 16); + + SetPossessed(ZetaBotPawn(Spawn(possessedType, spawnPos))); + Spawn("TeleportFog", spawnPos); + + DebugLog(LT_VERBOSE, String.format("%s respawned!", myName)); + } + void SetPossessed(ZetaBotPawn other) { if ( other != null ) @@ -369,6 +408,8 @@ class ZTBotController : Actor DebugLog(LT_INFO, myName.." has possessed a "..other.GetClassName().."!"); possessed = other; + ZetaCape.MakeFor(other); + possessedType = possessed.GetClass(); possessed.cont = self; if ( CVar.GetCVar("deathmatch").GetInt() == 1 ) @@ -473,10 +514,15 @@ class ZTBotController : Actor { ActorList res = new("ActorList"); ThinkerIterator iter = ThinkerIterator.Create("Actor", STAT_DEFAULT); + ThinkerIterator iter2 = ThinkerIterator.Create("Actor", STAT_PLAYER); Actor cur = null; - while ( cur = Actor(iter.Next()) ) + while ( true ) { + if ( !(cur = Actor(iter.Next())) ) + if ( !(cur = Actor(iter2.Next())) ) + break; + Vector2 off = possessed.Vec2To(cur); double pdot = 1; @@ -491,8 +537,9 @@ class ZTBotController : Actor double pdot = off.x * avec.x + off.y * avec.y; } - if ( cur != null && cur != from && ( cur.bISMONSTER || cur.CheckClass("PlayerPawn", AAPTR_DEFAULT, true) ) && LineOfSight(cur, from) && isEnemy(from, cur) && cur.Health > 0 && pdot > 0.3 ) + if ( cur != null && cur != from && ( cur.bISMONSTER || cur.CheckClass("PlayerPawn", match_superclass: true) ) && LineOfSight(cur, from) && isEnemy(from, cur) && cur.Health > 0 && pdot > 0.3 ) { res.Push(cur); + } } return res; @@ -654,7 +701,7 @@ class ZTBotController : Actor bool isEnemy(Actor from, Actor other) { - return from.bFRIENDLY != other.bFRIENDLY || ( !from.bFRIENDLY && other.CheckClass("PlayerPawn", AAPTR_DEFAULT, true) ) || CVar.GetCVar("deathmatch").GetInt() == 1; + return from.bFRIENDLY != other.bFRIENDLY || ( !from.bFRIENDLY && other.CheckClass("PlayerPawn", AAPTR_DEFAULT, true) ) || CVar.GetCVar('deathmatch').GetInt() > 0; } ZTPathNode ClosestNode(Actor other) @@ -920,7 +967,7 @@ class ZTBotController : Actor void BotChat(String kind, double importance) { - if ( !CVar.FindCVar("zb_talk").GetBool() || importance < FRandom(0, 1.8) ) + if ( !CVar.FindCVar("zb_talk").GetBool() || importance < FRandom(0, 3.25) ) return; A_PlaySound("zetabot/"..myVoice.."/"..kind, CHAN_VOICE, attenuation: 0.7); @@ -1068,7 +1115,7 @@ class ZTBotController : Actor AimAtAngle(currNode.Angle, 70, 20); } - if ( FRandom(0, 1) < 0.03 ) + if ( FRandom(0, 1) < 0.0175 ) possessed.Jump(); possessed.LineTrace(possessed.angle - 45, 200, possessed.pitch, data: leftfront); @@ -1096,10 +1143,18 @@ class ZTBotController : Actor void A_ZetaTick() { - if ( possessed == null ) - { - Destroy(); - return; + if ( possessed == null || possessed.Health <= 0 ) { + if ( CVar.FindCVar('zb_respawn').GetBool() && ( CVar.FindCVar('deathmatch').GetInt() > 0 || CVar.FindCVar('zb_cooprespawn').GetBool() ) ) { + DebugLog(LT_VERBOSE, String.format("Setting Respawn mode for %s.", myName)); + SetStateLabel("Respawn"); + + return; + } + + else { + Destroy(); + return; + } } if ( currNode != null && currNode.nodeType == ZTPathNode.NT_AVOID ) @@ -1212,7 +1267,7 @@ class ZTBotController : Actor BotChat("TARG", 0.8); - if ( !LineOfSight(enemy) && possessed.Distance2D(enemy) > 768 ) + if ( !possessed.CheckSight(enemy) ) { lastEnemyPos = enemy.pos; SetBotState(BS_HUNTING); @@ -1247,6 +1302,8 @@ class ZTBotController : Actor if ( bstate == BS_HUNTING ) { + double lastPosDist = (possessed.pos.x - lastEnemyPos.x) * (possessed.pos.x - lastEnemyPos.x) + (possessed.pos.y - lastEnemyPos.y) * (possessed.pos.y - lastEnemyPos.y); + if ( enemy == null || enemy.Health <= 0 ) { enemy = null; @@ -1256,7 +1313,7 @@ class ZTBotController : Actor else if ( possessed.CheckSight(enemy) || possessed.Distance3D(enemy) < 96 ) SetBotState(BS_ATTACKING); - else if ( (possessed.pos.x - lastEnemyPos.x) * (possessed.pos.x - lastEnemyPos.x) + (possessed.pos.y - lastEnemyPos.y) * (possessed.pos.y - lastEnemyPos.y) < 128 * 128 ) + else if ( lastPosDist < 16384 || lastPosDist > 4194304 ) { enemy = null; SetBotState(BS_WANDERING); @@ -1264,6 +1321,11 @@ class ZTBotController : Actor else { MoveTowardPos(lastEnemyPos, 3); + + if ( FRandom(0, 1) < 0.06 ) + possessed.Jump(); + + AutoUseAtAngle(0); } } @@ -1454,7 +1516,7 @@ class ZTBotController : Actor else { - if ( FRandom(0, 1) < 0.3 ) + if ( FRandom(0, 1) < 0.06 ) possessed.Jump(); BotChat("ACTV", 0.2); @@ -1536,6 +1598,12 @@ class ZTBotController : Actor Spawn: TNT1 A 1; Goto TickLoop; + + Respawn: + TNT1 A 12; + TNT1 A 0 A_Jump(180, "Respawn"); + TNT1 A 1 A_ZetaRespawn; + Goto TickLoop; TickLoop: TNT1 A 1 A_ZetaTick; @@ -1601,8 +1669,24 @@ class ZetaBot : Actor if ( cont == null ) return; - ZetaCape.MakeFor(cont.possessed); cont.possessed.angle = angle; + + if ( zb_autonoderespawn ) { + let iter = ThinkerIterator.Create("ZTPathNode", STAT_DEFAULT); + bool can = true; + ZTPathNode pn; + + while (pn = ZTPathNode(iter.Next())) + if (pn.nodeType == ZTPathNode.NT_RESPAWN && pn.Distance2D(cont.possessed) < 64) { + can = false; + break; + } + + if (can) { + DebugLog(LT_INFO, String.format("Added respawn node at location x=%f,y=%f,z=%f", pos.x, pos.y, pos.z)); + ZTPathNode.plopNode(cont.possessed.pos, ZTPathNode.NT_RESPAWN, angle); + } + } DebugLog(LT_INFO, "ZetaBot spawned with success! Class: "..cont.possessed.GetClassName()); Destroy(); @@ -1667,7 +1751,6 @@ class ZetaSpirit : Actor if ( cont == null ) return; - ZetaCape.MakeFor(cont.possessed); cont.possessed.angle = angle; DebugLog(LT_INFO, "ZetaBot spawned with success! Class: "..cont.possessed.GetClassName()); diff --git a/ZetaCode/Pathing.zsc b/ZetaCode/Pathing.zsc index 0c2cb41..30ae6d7 100644 --- a/ZetaCode/Pathing.zsc +++ b/ZetaCode/Pathing.zsc @@ -15,7 +15,8 @@ class ZTPathNode : Actor NT_CROUCH, NT_JUMP, NT_AVOID, - NT_SHOOT + NT_SHOOT, + NT_RESPAWN }; static const string ZTNavTypeNames[] = { @@ -25,7 +26,8 @@ class ZTPathNode : Actor "Crouch", "Jump", "Avoid", - "Shoot" + "Shoot", + "Respawn" }; enum LogType diff --git a/ZetaCode/WeaponSupport/Doom/ZetaBFG.zsc b/ZetaCode/WeaponSupport/Doom/ZetaBFG.zsc index e048644..e70fb77 100644 --- a/ZetaCode/WeaponSupport/Doom/ZetaBFG.zsc +++ b/ZetaCode/WeaponSupport/Doom/ZetaBFG.zsc @@ -24,6 +24,11 @@ class ZetaBFG : ZetaWeapon override void Fire(Actor shooter, Actor target) { - shooter.SpawnMissileAngle("BFGBall", shooter.angle, target == null ? 0 : ((target.pos.z - shooter.pos.z) * 25 / target.Distance2D(shooter))); + double pitch = 0; + + if (target != null && target.Distance2D(shooter) > 0) + pitch = ((target.pos.z - shooter.pos.z) * 25 / target.Distance2D(shooter)); + + shooter.SpawnMissileAngle("BFGBall", shooter.angle, pitch); } } \ No newline at end of file diff --git a/ZetaCode/WeaponSupport/Doom/ZetaPR.zsc b/ZetaCode/WeaponSupport/Doom/ZetaPR.zsc index a096f4c..1b04fed 100644 --- a/ZetaCode/WeaponSupport/Doom/ZetaPR.zsc +++ b/ZetaCode/WeaponSupport/Doom/ZetaPR.zsc @@ -24,6 +24,11 @@ class ZetaPR : ZetaWeapon override void Fire(Actor shooter, Actor target) { - shooter.SpawnMissileAngle("PlasmaBall", shooter.angle, target == null ? 0 : ((target.pos.z - shooter.pos.z) * 25 / target.Distance2D(shooter))); + double pitch = 0; + + if (target != null && target.Distance2D(shooter) > 0) + pitch = ((target.pos.z - shooter.pos.z) * 25 / target.Distance2D(shooter)); + + shooter.SpawnMissileAngle("PlasmaBall", shooter.angle, pitch); } } \ No newline at end of file diff --git a/ZetaCode/WeaponSupport/Doom/ZetaRL.zsc b/ZetaCode/WeaponSupport/Doom/ZetaRL.zsc index 96c9346..981cb12 100644 --- a/ZetaCode/WeaponSupport/Doom/ZetaRL.zsc +++ b/ZetaCode/WeaponSupport/Doom/ZetaRL.zsc @@ -27,6 +27,11 @@ class ZetaRL : ZetaWeapon override void Fire(Actor shooter, Actor target) { - shooter.SpawnMissileAngle("Rocket", shooter.angle, target == null ? 0 : ((target.pos.z - shooter.pos.z) * 20 / target.Distance2D(shooter))); + double pitch = 0; + + if (target != null && target.Distance2D(shooter) > 0) + pitch = ((target.pos.z - shooter.pos.z) * 25 / target.Distance2D(shooter)); + + shooter.SpawnMissileAngle("Rocket", shooter.angle, pitch); } } \ No newline at end of file diff --git a/ZetaCode/WeaponSupport/ZetaBullet.zsc b/ZetaCode/WeaponSupport/ZetaBullet.zsc index 2e95328..cbbad0e 100644 --- a/ZetaCode/WeaponSupport/ZetaBullet.zsc +++ b/ZetaCode/WeaponSupport/ZetaBullet.zsc @@ -38,10 +38,10 @@ class ZetaBullet : Actor bullet.currDmg = Floor(damage + 0.5); bullet.angle += FRandom(-spreadX, spreadX); - if (target != null) { - bullet.pitch = (target.pos.z - shooter.pos.z) / target.Distance2D(shooter); - bullet.pitch += FRandom(-spreadY, spreadY); - } + if (target != null && target.Distance2D(shooter) > 0) + bullet.pitch = (target.pos.z - shooter.pos.z); + + bullet.pitch += FRandom(-spreadY, spreadY); bullet.shooter = shooter; bullet.damageType = damageType; diff --git a/acs/ZETAACS.o b/acs/ZETAACS.o index 585d66ec7b103ad8c7f6c97fae6bfd6849807a4f..2e61a86b99d87e0a11439f0c40b812b738629e62 100644 GIT binary patch delta 76 zcmWH@Fm-eeW=LRQVA#OG*w2U{7=i;rf+T?AC)imSIDqs?c76t4AbpCRi9u+htg-+| L5~w*9NPz(WFj5RE delta 52 xcmc}@kactpX7FHOVA#OG*v|;0g9Ac>IDqsib`}PXiKfZ|0zeK>Q7VuE0|4;U2dMx6 diff --git a/acs/last_source.sha512 b/acs/last_source.sha512 index d30b616..085b7d6 100644 --- a/acs/last_source.sha512 +++ b/acs/last_source.sha512 @@ -1 +1 @@ -e1da3d0a93732a90fc8f2cec307df9a2e788fbe76567f31c4584df6d65cc2ac9d162046d9a95db2bb3814c31ff57f3461a2fc7ebca73be43cafd7e403d6e1ad3 \ No newline at end of file +bacf401d13ecdb143644257ed7a2fe4da4a0facb780c8357817acbf6a1b8de1d1461f3def56a505c68fcefec2b1b4241a5063efb217a8573854b759ea840c165 \ No newline at end of file diff --git a/config b/config index 81726b7..d14e6c7 100644 --- a/config +++ b/config @@ -1,6 +1,6 @@ #!/bin/bash NAME=ZetaBot -VERSION=0.5.0 +VERSION=0.5.1 ADDFOLDER ZetaCode ADDFOLDER sprites diff --git a/source/ZETAACS.acs b/source/ZETAACS.acs index 7b09ba6..141f18d 100644 --- a/source/ZETAACS.acs +++ b/source/ZETAACS.acs @@ -1,6 +1,16 @@ #include "zcommon.acs" -script 1994 ENTER +script 1992 ENTER { GiveInventory("BotName", 1); } + +script 1993 RETURN +{ + GiveInventory("BotName", 1); +} + +script 1994 RESPAWN +{ + GiveInventory("BotName", 1); +} \ No newline at end of file