botlib: add USER linkflag. When a bot passes that link, he'll USE the
closest func_button nearby.
This commit is contained in:
parent
cec4872994
commit
2c7f540787
5 changed files with 91 additions and 4 deletions
|
@ -57,6 +57,7 @@ class bot:player
|
|||
virtual void(void) CheckRoute;
|
||||
virtual void(void) PreFrame;
|
||||
virtual void(void) PostFrame;
|
||||
virtual void(void) UseButton;
|
||||
};
|
||||
|
||||
entity Bot_AddQuick(void);
|
||||
|
|
|
@ -78,6 +78,57 @@ bot::BrainThink(int enemyvisible, int enemydistant)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
bot::UseButton(void)
|
||||
{
|
||||
#if 1
|
||||
float best;
|
||||
func_button best_button = __NULL__;
|
||||
|
||||
best = COST_INFINITE;
|
||||
for (entity e = world; (e = find(e, ::classname, "func_button"));) {
|
||||
float dist;
|
||||
vector pos;
|
||||
pos[0] = e.absmin[0] + (0.5 * (e.absmax[0] - e.absmin[0]));
|
||||
pos[1] = e.absmin[1] + (0.5 * (e.absmax[1] - e.absmin[1]));
|
||||
pos[2] = e.absmin[2] + (0.5 * (e.absmax[2] - e.absmin[2]));
|
||||
dist = vlen(origin - pos);
|
||||
|
||||
if (dist < best) {
|
||||
best = dist;
|
||||
best_button = (func_button)e;
|
||||
}
|
||||
}
|
||||
|
||||
if (best_button == __NULL__)
|
||||
return;
|
||||
|
||||
best_button.Trigger(this, TRIG_TOGGLE);
|
||||
sound(this, CHAN_ITEM, "common/wpn_select.wav", 0.25, ATTN_IDLE);
|
||||
#else
|
||||
float best;
|
||||
vector foo;
|
||||
|
||||
best = COST_INFINITE;
|
||||
for (entity e = world; (e = find(e, ::classname, "func_button"));) {
|
||||
float dist;
|
||||
vector pos;
|
||||
pos[0] = e.absmin[0] + (0.5 * (e.absmax[0] - e.absmin[0]));
|
||||
pos[1] = e.absmin[1] + (0.5 * (e.absmax[1] - e.absmin[1]));
|
||||
pos[2] = e.absmin[2] + (0.5 * (e.absmax[2] - e.absmin[2]));
|
||||
dist = vlen(origin - pos);
|
||||
|
||||
if (dist < best) {
|
||||
best = dist;
|
||||
foo = pos;
|
||||
}
|
||||
}
|
||||
|
||||
v_angle = vectoangles(origin - foo);
|
||||
Player_UseDown();
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
bot::SeeThink(void)
|
||||
{
|
||||
|
@ -157,6 +208,10 @@ bot::CheckRoute(void)
|
|||
/* if a node is flagged as jumpy, jump! */
|
||||
if (m_pRoute[m_iCurNode].m_iFlags & LF_JUMP)
|
||||
input_buttons |= INPUT_BUTTON2;
|
||||
|
||||
/* find the nearest usable item (func_button) and use them */
|
||||
if (m_pRoute[m_iCurNode].m_iFlags & LF_USER)
|
||||
UseButton();
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
|
|
@ -22,5 +22,5 @@
|
|||
#define LF_TELEPORT 0x00000008i
|
||||
#define LF_WALK 0x00000010i
|
||||
#define LF_AIM 0x00000020i
|
||||
#define LF_USER 0x7fffff00i
|
||||
#define LF_USER 0x00000040i
|
||||
#define LF_DESTINATION 0x80000000i
|
||||
|
|
|
@ -288,6 +288,31 @@ Way_FlagAim(void)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
Way_FlagUse(void)
|
||||
{
|
||||
if (g_waylink_status == 0) {
|
||||
g_way1 = Way_FindClosestNode(self.origin);
|
||||
g_waylink_status = 1;
|
||||
env_message_single(self, "^2Selected first waypoint!\n");
|
||||
} else if (g_waylink_status == 1) {
|
||||
g_way2 = Way_FindClosestNode(self.origin);
|
||||
g_waylink_status = 0;
|
||||
|
||||
if (g_way1 != g_way2) {
|
||||
for (int b = 0i; b < g_pWaypoints[g_way1].m_numNeighbours; b++) {
|
||||
if (g_pWaypoints[g_way1].m_pNeighbour[b].m_iNode == g_way2) {
|
||||
g_pWaypoints[g_way1].m_pNeighbour[b].m_iFlags |= LF_USER;
|
||||
env_message_single(self, "^2Walk-linked the two points!\n");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
env_message_single(self, "^1Failed to link, the two points are the same!\n");
|
||||
}
|
||||
g_way1 = g_way2 = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Way_HelperSpawns()
|
||||
{
|
||||
|
@ -338,7 +363,7 @@ Way_SaveFile(string filename)
|
|||
fputs(file, sprintf("%v %f %i\n", g_pWaypoints[i].m_vecOrigin, g_pWaypoints[i].m_flRadius, g_pWaypoints[i].m_numNeighbours));
|
||||
|
||||
for(int j = 0i; j < g_pWaypoints[i].m_numNeighbours; j++) {
|
||||
fputs(file, sprintf(" %i %f %x\n", g_pWaypoints[i].m_pNeighbour[j].m_iNode, g_pWaypoints[i].m_pNeighbour[j].m_flCost, (float)g_pWaypoints[i].m_pNeighbour[j].m_iFlags));
|
||||
fputs(file, sprintf(" %i %f %i\n", g_pWaypoints[i].m_pNeighbour[j].m_iNode, g_pWaypoints[i].m_pNeighbour[j].m_flCost, g_pWaypoints[i].m_pNeighbour[j].m_iFlags));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -373,7 +398,7 @@ Way_ReadFile(string strFile)
|
|||
tokenize(fgets(file));
|
||||
g_pWaypoints[i].m_pNeighbour[j].m_iNode = stoi(argv(0));
|
||||
g_pWaypoints[i].m_pNeighbour[j].m_flCost = stof(argv(1));
|
||||
g_pWaypoints[i].m_pNeighbour[j].m_iFlags = stoh(argv(2));
|
||||
g_pWaypoints[i].m_pNeighbour[j].m_iFlags = stoi(argv(2));
|
||||
}
|
||||
}
|
||||
fclose(file);
|
||||
|
@ -601,6 +626,9 @@ Way_Cmd(void)
|
|||
case "linkaim":
|
||||
Way_FlagAim();
|
||||
break;
|
||||
case "linkuse":
|
||||
Way_FlagUse();
|
||||
break;
|
||||
case "move":
|
||||
vector p;
|
||||
int n = Way_FindClosestNode(self.origin);
|
||||
|
|
|
@ -110,7 +110,7 @@ Way_Init(void)
|
|||
"2.\tFlag ^2CROUCH^7 (2 steps)\n" \
|
||||
"3.\tFlag ^1WALK^7 (2 steps)\n" \
|
||||
"4.\tFlag ^4AIM^7 (2 steps)\n" \
|
||||
"\n" \
|
||||
"5.\tFlag ^4USE^7 (2 steps)\n" \
|
||||
"\n" \
|
||||
"\n" \
|
||||
"\n" \
|
||||
|
@ -282,6 +282,9 @@ WAY_FLAGS(int n)
|
|||
case 4:
|
||||
localcmd("sv way linkaim\n");
|
||||
break;
|
||||
case 5:
|
||||
localcmd("sv way linkuse\n");
|
||||
break;
|
||||
case 9:
|
||||
Textmenu_Call("WAY_MENU");
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue