1 /*
2 ===========================================================================
3 Copyright (C) 2000 - 2013, Raven Software, Inc.
4 Copyright (C) 2001 - 2013, Activision, Inc.
5 Copyright (C) 2013 - 2015, OpenJK contributors
6
7 This file is part of the OpenJK source code.
8
9 OpenJK is free software; you can redistribute it and/or modify it
10 under the terms of the GNU General Public License version 2 as
11 published by the Free Software Foundation.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, see <http://www.gnu.org/licenses/>.
20 ===========================================================================
21 */
22
23 #include "../cgame/cg_local.h"
24 #include "b_local.h"
25 #include "Q3_Interface.h"
26
27 extern qboolean NPC_CheckSurrender( void );
28 extern void NPC_BehaviorSet_Default( int bState );
29
NPC_BSCivilian_Default(int bState)30 void NPC_BSCivilian_Default( int bState )
31 {
32 if ( NPC->enemy
33 && NPC->s.weapon == WP_NONE
34 && NPC_CheckSurrender() )
35 {//surrendering, do nothing
36 }
37 else if ( NPC->enemy
38 && NPC->s.weapon == WP_NONE
39 && bState != BS_HUNT_AND_KILL
40 && !Q3_TaskIDPending( NPC, TID_MOVE_NAV ) )
41 {//if in battle and have no weapon, run away, fixme: when in BS_HUNT_AND_KILL, they just stand there
42 if ( !NPCInfo->goalEntity
43 || bState != BS_FLEE //not fleeing
44 || ( NPC_BSFlee()//have reached our flee goal
45 && NPC->enemy//still have enemy (NPC_BSFlee checks enemy and can clear it)
46 && DistanceSquared( NPC->currentOrigin, NPC->enemy->currentOrigin ) < 16384 )//enemy within 128
47 )
48 {//run away!
49 NPC_StartFlee( NPC->enemy, NPC->enemy->currentOrigin, AEL_DANGER_GREAT, 5000, 10000 );
50 }
51 }
52 else
53 {//not surrendering
54 //FIXME: if unarmed and a jawa/ugnuaght, constantly look for enemies/players to run away from?
55 //FIXME: if we have a weapon and an enemy, set out playerTeam to the opposite of our enemy..???
56 NPC_BehaviorSet_Default(bState);
57 }
58 if ( !VectorCompare( NPC->client->ps.moveDir, vec3_origin ) )
59 {//moving
60 if ( NPC->client->ps.legsAnim == BOTH_COWER1 )
61 {//stop cowering anim on legs
62 NPC->client->ps.legsAnimTimer = 0;
63 }
64 }
65 }