File: bot_botphys.c

package info (click to toggle)
ktx 1.45-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 7,940 kB
  • sloc: ansic: 76,453; asm: 107; sh: 99; makefile: 4
file content (124 lines) | stat: -rw-r--r-- 2,282 bytes parent folder | download
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
/*
 bot/botphys.qc

 Copyright (C) 1997-1999 Robert 'Frog' Field
 Copyright (C) 1998-2000 Matt 'asdf' McChesney
 Copyright (C) 2000-2007 ParboiL
 */

// Converted from .qc on 05/02/2016
#ifdef BOT_SUPPORT

#include "g_local.h"

static float unstick_time = 0;
static qbool no_bots_stuck = 0;

int NumberOfClients(void)
{
	int count = 0;
	gedict_t *plr = NULL;

	for (plr = world; (plr = find_plr(plr));)
	{
		if (plr->ct == ctPlayer)
		{
			++count;
		}
	}

	return count;
}

void FrogbotPrePhysics1(void)
{
	gedict_t *p;

	for (p = world; (p = find_plr(p));)
	{
		if (p->isBot && p->s.v.takedamage)
		{
			VectorCopy(p->s.v.velocity, p->fb.oldvelocity);
		}
	}
}

void BotDetectTrapped(gedict_t *self)
{
	// This tries to detect stuck bots, and fixes the situation by either jumping or committing suicide
	vec3_t point;
	int content1;

	VectorSet(point, self->s.v.origin[0], self->s.v.origin[1], self->s.v.origin[2] - 24);
	content1 = trap_pointcontents(PASSVEC3(point));

	if (content1 == CONTENT_EMPTY)
	{
		self->fb.oldwaterlevel = 0;
		self->fb.oldwatertype = CONTENT_EMPTY;
	}
	else if (content1 == CONTENT_SOLID)
	{
		unstick_time = unstick_time + g_globalvars.frametime;
		if (unstick_time <= NumberOfClients())
		{
			no_bots_stuck = false;
			SetJumpFlag(self, true, "Trapped1");
		}
		else
		{
			self->fb.botchose = true;
			self->fb.next_impulse = CLIENTKILL;
		}
	}
	else
	{
		int content2 = trap_pointcontents(self->s.v.origin[0], self->s.v.origin[1],
											self->s.v.origin[2] + 4);
		if (content2 == CONTENT_EMPTY)
		{
			self->fb.oldwaterlevel = 1;
			self->fb.oldwatertype = content1;
		}
		else
		{
			int content3 = trap_pointcontents(self->s.v.origin[0], self->s.v.origin[1],
												self->s.v.origin[2] + 22);
			if (content3 == CONTENT_EMPTY)
			{
				self->fb.oldwaterlevel = 2;
				self->fb.oldwatertype = content2;
			}
			else
			{
				self->fb.oldwaterlevel = 3;
				self->fb.oldwatertype = content3;
			}
		}
	}
}

void FrogbotPrePhysics2(void)
{
	no_bots_stuck = true;

	for (self = world; (self = find_plr(self));)
	{
		if (self->isBot)
		{
			BotDetectTrapped(self);

			if (self->s.v.takedamage)
			{
				VectorCopy(self->s.v.origin, self->s.v.oldorigin);
			}
		}
	}

	if (no_bots_stuck)
	{
		unstick_time = 0;
	}
}

#endif // BOT_SUPPORT