Skip to content

Commit

Permalink
Geared bots for deathmatch
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo Rehermann (Gustavo6046) committed May 3, 2019
1 parent c7204ba commit 8d0f324
Show file tree
Hide file tree
Showing 11 changed files with 140 additions and 27 deletions.
3 changes: 3 additions & 0 deletions CVarInfo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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";
113 changes: 98 additions & 15 deletions ZScript.zsc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -362,13 +362,54 @@ class ZTBotController : Actor
AimAtAngle(-possessed.AngleTo(other), speed, threshold);
}

Class<ZetaBotPawn> 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 )
{
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 )
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -1256,14 +1313,19 @@ 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);
}

else {
MoveTowardPos(lastEnemyPos, 3);

if ( FRandom(0, 1) < 0.06 )
possessed.Jump();

AutoUseAtAngle(0);
}
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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());
Expand Down
6 changes: 4 additions & 2 deletions ZetaCode/Pathing.zsc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class ZTPathNode : Actor
NT_CROUCH,
NT_JUMP,
NT_AVOID,
NT_SHOOT
NT_SHOOT,
NT_RESPAWN
};

static const string ZTNavTypeNames[] = {
Expand All @@ -25,7 +26,8 @@ class ZTPathNode : Actor
"Crouch",
"Jump",
"Avoid",
"Shoot"
"Shoot",
"Respawn"
};

enum LogType
Expand Down
7 changes: 6 additions & 1 deletion ZetaCode/WeaponSupport/Doom/ZetaBFG.zsc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
7 changes: 6 additions & 1 deletion ZetaCode/WeaponSupport/Doom/ZetaPR.zsc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
7 changes: 6 additions & 1 deletion ZetaCode/WeaponSupport/Doom/ZetaRL.zsc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
8 changes: 4 additions & 4 deletions ZetaCode/WeaponSupport/ZetaBullet.zsc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Binary file modified acs/ZETAACS.o
Binary file not shown.
2 changes: 1 addition & 1 deletion acs/last_source.sha512
Original file line number Diff line number Diff line change
@@ -1 +1 @@
e1da3d0a93732a90fc8f2cec307df9a2e788fbe76567f31c4584df6d65cc2ac9d162046d9a95db2bb3814c31ff57f3461a2fc7ebca73be43cafd7e403d6e1ad3
bacf401d13ecdb143644257ed7a2fe4da4a0facb780c8357817acbf6a1b8de1d1461f3def56a505c68fcefec2b1b4241a5063efb217a8573854b759ea840c165
2 changes: 1 addition & 1 deletion config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
NAME=ZetaBot
VERSION=0.5.0
VERSION=0.5.1

ADDFOLDER ZetaCode
ADDFOLDER sprites
Expand Down
12 changes: 11 additions & 1 deletion source/ZETAACS.acs
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit 8d0f324

Please sign in to comment.