JNR
aiMobState_Territorial.cpp
1 /*
2 
3 Jump'n'Run Engine
4 http://www.atanaslaskov.com/jnr/
5 
6 BSD LICENSE
7 Copyright (c) 2007-2013, Atanas Laskov
8 All rights reserved.
9 
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
12 1. Redistributions of source code must retain the above copyright notice,
13 this list of conditions and the following disclaimer.
14 2. Redistributions in binary form must reproduce the above copyright notice,
15 this list of conditions and the following disclaimer in the documentation
16 and/or other materials provided with the distribution.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL ATANAS LASKOV BE LIABLE FOR ANY
21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 */
29 
30 //
31 // FILE: aiMobState_Territorial.cpp
32 //
33 // Basic monster AI
34 //
35 // Copyright (C) 2007-2013 Atanas Laskov, <latanas@gmail.com>
36 //
37 #include "stdafx.h"
38 #include "ai.h"
39 
40 void aiMobState_Territorial::load(laFileParser *fp)
41 {
42  aiMobState_Ramble::load(fp);
43 
44  //Load global params
45  //...
46 }
47 
48 aiMobState_Territorial::~aiMobState_Territorial(void)
49 {
50 }
51 
52 void aiMobState_Territorial::perceive_active( std::string strID_Old )
53 {
54  laMonster* pMonster = (laMonster*) self();
55  laPlayer* pPlayer = (laPlayer*) player();
56 
57  aiMobState_Ramble::perceive_active(strID_Old);
58 
59  pMonster->agressive(M_TRUE);
60 }
61 
62 // The player is in attack range
63 //
64 void aiMobState_Territorial::perceive_InRange(unsigned state)
65 {
66  laMonster* pMonster = (laMonster*) self();
67  laPlayer* pPlayer = (laPlayer*) player();
68 
69  switch(state)
70  {
71  case PERCEPT_SET:
72  // Show battle GUI
73  pMonster->enableBattleGUI();
74 
75  //Initate attack
76  pMonster->attackSelect(M_MATTACK_MAIN + rand()%2);
77  pMonster->attackInitiate();
78  break;
79 
80  case PERCEPT_RESET:
81  // Hide GUI
82  pMonster->enableBattleGUI(M_FALSE);
83  pMonster->attackStop();
84  break;
85 
86  case PERCEPT_HOLD:
87  if( pMonster->attackIsCharged() )
88  {
89  pMonster->attack(pPlayer);
90  }
91  else
92  {
93  pMonster->attackSelect(M_MATTACK_MAIN + rand()%2);
94  pMonster->attackInitiate(); // attack anew
95  }
96 
97  // Face the player
98  //
99  pMonster->move(0);
100  _select_creature();
101 
102  if( pPlayer->getPosition().x() > pMonster->getPosition().x() )
103  pMonster->setFaceDirection(+1);
104  else
105  pMonster->setFaceDirection(-1);
106  break;
107  }
108 
109  // Default actions
110  //
111  aiMobState_Ramble::perceive_InRange(state);
112 }
113 
114 // The player is within monster's territory
115 //
116 void aiMobState_Territorial::perceive_InTerritory(unsigned state)
117 {
118  laMonster* pMonster = (laMonster*) self();
119  laPlayer* pPlayer = (laPlayer*) player();
120 
121  switch(state)
122  {
123  /*case PERCEPT_SET:
124  //Play on proximity sound
125  //
126  //if(pProximitySound) pProximitySound->play();
127  break;*/
128 
129  case PERCEPT_HOLD:
130  //Chase the player
131  //
132  _select_creature();
133 
134  if( pPlayer->getPosition().x() > pMonster->getPosition().x() ) pMonster->move(+1);
135  else pMonster->move(-1);
136  break;
137 
138  case PERCEPT_RESET:
139  _select_creature(M_FALSE);
140  break;
141  }
142 
143  // Default actions
144  //
145  aiMobState_Ramble::perceive_InTerritory(state);
146 }
147 
148 // Default
149 //
150 /*void aiMobState_Territorial::perceive(unsigned state, M_BOOL global, unsigned id, aiPerceptData data)
151 {
152  laMonster* pMonster = (laMonster*) self();
153  laPlayer* pPlayer = (laPlayer*) player();
154 
155  aiMobState_Ramble::perceive(state, global, id, data);
156 }*/
Playable Character.
Definition: laPlayer.h:46
Adds capabilities and percepts specific to monster creatures.
Definition: laMonster.h:45
File Parser.
Definition: laFileParser.h:41