Skip to content

Commit 6421675

Browse files
committed
New function in AIControl: caculate distance betwwen lyubu and npcs
1 parent 82f397c commit 6421675

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

AIControl.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
#include "AIControl.h"
22

3+
using namespace std;
4+
extern char debug[1024];
35

4-
AIControl::AIControl(void)
6+
AIControl::AIControl(int id)
57
{
8+
this->lyubuId = id;
69
}
710

811

@@ -23,4 +26,30 @@ void AIControl::PlayAction(int skip){
2326
for (int i = 0;i< this->npcStateMachineList.size(); i++){
2427
npcStateMachineList[i]->PlayAction(skip);
2528
}
29+
}
30+
float AIControl::distanceBetweenLyubu() {
31+
for (int i = 0;i< this->npcStateMachineList.size(); i++){
32+
int npcId = npcStateMachineList[i]->character;
33+
34+
FnActor lyubu;
35+
FnActor npc;
36+
lyubu.Object(this->lyubuId);
37+
npc.Object(npcId);
38+
39+
float lyubuPos[3];
40+
float npcPos[3];
41+
42+
lyubu.GetWorldPosition(lyubuPos);
43+
npc.GetWorldPosition(npcPos);
44+
45+
float distance;
46+
distance = sqrt((npcPos[0] - lyubuPos[0]) * (npcPos[0] - lyubuPos[0])
47+
+ (npcPos[0] - lyubuPos[0]) * (npcPos[0] - lyubuPos[0])
48+
+ (npcPos[0] - lyubuPos[0]) * (npcPos[0] - lyubuPos[0]));
49+
50+
sprintf(debug, "%s distance = %f\n",debug,distance);
51+
52+
return distance;
53+
54+
}
2655
}

AIControl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@
88
class AIControl
99
{
1010
public:
11+
AIControl(int);
1112
std::vector<ActorStateMachine *> npcStateMachineList;
1213
AIControl(void);
1314
virtual ~AIControl(void);
1415
int AddNPC(ACTORid ncp, char * ActionFilename);
1516
void PlayAction(int skip);
17+
float distanceBetweenLyubu();
18+
private:
19+
int lyubuId;
1620
};
1721

Main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ BOOL initNPC(){
301301
}
302302

303303

304-
npc = new AIControl();
304+
npc = new AIControl(lyubu);
305305
npc->AddNPC(donzo,"Data\\DozonAction.txt");
306306
npc->AddNPC(robber,"Data\\Robber02Action.txt");
307307
return TRUE;
@@ -447,6 +447,8 @@ void GameAI(int skip)
447447
kc->Command();
448448
bRoom->RefreshArena();
449449
kc->CamPointToActor();
450+
npc->distanceBetweenLyubu();
451+
450452
}
451453

452454
void Render(int skip){

0 commit comments

Comments
 (0)