Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/ai/src/world_entities/npcs/npc_test.cc @ 10041

Last change on this file since 10041 was 10041, checked in by tfahrni, 17 years ago

Tried to make some progress with the AI..

File size: 1.8 KB
Line 
1
2
3/*
4   orxonox - the future of 3D-vertical-scrollers
5
6   Copyright (C) 2004 orx
7
8   This program is free software; you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2, or (at your option)
11   any later version.
12
13   ### File Specific:
14   main-programmer: Patrick Boenzli
15   co-programmer:
16*/
17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
18
19
20#include "npc_test.h"
21
22
23#include "state.h"
24#include "debug.h"
25
26#include "loading/factory.h"
27#include "loading/load_param.h"
28
29#include "md2/md2Model.h"
30#include "player.h"
31#include "playable.h"
32
33#include "class_id_DEPRECATED.h"
34
35ObjectListDefinitionID(NPC2, CL_NPC_TEST2);
36CREATE_FACTORY(NPC2);
37
38
39NPC2::NPC2(const TiXmlElement* root)
40  : NPC(NULL)
41{
42  this->registerObject(this, NPC2::_objectList);
43
44
45  if (root != NULL)this->loadParams(root);
46 
47  addToTeam(0);
48}
49
50
51NPC2::~NPC2 ()
52{}
53
54
55void NPC2::loadParams(const TiXmlElement* root)
56{
57  NPC::loadParams(root);
58
59}
60
61
62
63
64
65void NPC2::tick(float dt)
66{
67       
68       
69  // animating the md2 model (uninteressant)
70  if( likely(this->getModel(0) != NULL))
71    ((MD2Model*)this->getModel(0))->tick(dt);
72
73        return; 
74        //this things will now be managed by the AI modules..../////
75
76  PRINTF(0)("====================\n");
77  PRINTF(0)("NPC2::tick(%f)\n", dt);
78
79  // information gathering
80
81  Vector absPosition = this->getAbsCoor();
82
83  PRINTF(0)(" npc abs coor: %f, %f, %f\n", absPosition.x, absPosition.y, absPosition.z);
84
85  Player* pl = State::getPlayer();
86  Vector playerAbsPos = pl->getPlayable()->getAbsCoor();
87
88  PRINTF(0)(" player abs coor: %f, %f, %f\n", playerAbsPos.x, playerAbsPos.y, playerAbsPos.z);
89
90
91  // intelligent reaction
92
93  Vector distanceVector = playerAbsPos - absPosition;
94  distanceVector.normalize();
95
96  float speed = 10.0f;
97
98  this->shiftCoor( distanceVector * speed * dt);
99
100
101
102}
103
104
105
Note: See TracBrowser for help on using the repository browser.