Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/npcs/network_turret.cc @ 9838

Last change on this file since 9838 was 9656, checked in by bensch, 18 years ago

orxonox/trunk: merged the proxy bache back with no conflicts

File size: 4.2 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Manuel Leuenberger
13   co-programmer: ...
14*/
15
16#include "network_turret.h"
17#include "model.h"
18#include "world_entities/weapons/turret.h"
19
20#include "state.h"
21#include "playable.h"
22#include "player.h"
23
24
25#include "util/loading/factory.h"
26#include "network_game_manager.h"
27#include "util/loading/load_param.h"
28
29#include "effects/explosion.h"
30
31#include "weapons/aiming_turret.h"
32
33CREATE_FACTORY(NetworkTurret, CL_NETWORK_TURRET);
34
35
36
37
38/**
39 * constructs and loads a NetworkTurret from a XML-element
40 * @param root the XML-element to load from
41 */
42NetworkTurret::NetworkTurret(const TiXmlElement* root)
43    : NPC(root)
44{
45  this->init();
46  if (root != NULL)
47    this->loadParams(root);
48}
49
50
51/**
52 * standard deconstructor
53 */
54NetworkTurret::~NetworkTurret ()
55{}
56
57
58/**
59 * initializes the NetworkTurret
60 * @todo change this to what you wish
61 */
62void NetworkTurret::init()
63{
64  this->setClassID(CL_NETWORK_TURRET, "NetworkTurret");
65  this->loadModel("models/ground_turret_#.obj", 5);
66
67  this->weapon = new AimingTurret();
68  this->weapon->loadModel("models/guns/turret2.obj", 10);
69  this->weapon->setParent(this);
70  this->weapon->toList(this->getOMListNumber());
71  this->weapon->setRelCoor(0,10,-5);
72  this->weapon->requestAction( WA_ACTIVATE);
73  this->weapon->setParent(&this->weaponHolder);
74
75  this->setHealthMax(300);
76  this->setHealth(300);
77
78  this->weaponHolder.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
79
80  this->weaponHolder.setRelCoor(0,25,0);
81  this->weaponHolder.setParent(this);
82
83
84  this->targetGroup = OM_GROUP_01;
85  this->targetGroup_write = OM_GROUP_01;
86  this->targetGroup_handle = this->registerVarId( new SynchronizeableInt ( &targetGroup, &targetGroup_write, "targetgroup", PERMISSION_MASTER_SERVER ) );
87
88  this->setSynchronized( true );
89}
90
91
92/**
93 * @brief loads a NetworkTurret from a XML-element
94 * @param root the XML-element to load from
95 * @todo make the class Loadable
96 */
97void NetworkTurret::loadParams(const TiXmlElement* root)
98{
99  // all the clases this Entity is directly derived from must be called in this way, to load all settings.
100  NPC::loadParams(root);
101
102  LoadParam(root, "target-group", this, NetworkTurret, setTargetGroupS);
103}
104
105/**
106 * advances the NetworkTurret about time seconds
107 * @param time the Time to step
108 */
109void NetworkTurret::tick(float dt)
110{
111  ObjectManager::EntityList::iterator entity;
112  Vector diffVec;
113  for (entity = State::getObjectManager()->getObjectList((OM_LIST)this->targetGroup).begin();
114       entity != State::getObjectManager()->getObjectList((OM_LIST)this->targetGroup).end();
115       entity ++)
116  {
117    diffVec = ( (*entity)->getAbsCoor() - this->getAbsCoor() );
118
119    if ( diffVec.len() < 400.0 )//&&  acos( (this->source->getAbsDirX()).dot(diffVec)/(diffVec.len() * (this->source->getAbsDirX()).len() ) )  < angle)
120    {
121      //if (this->getParent() != (*entity))
122      {
123        this->weapon->requestAction(WA_SHOOT);
124        return;
125      }
126    }
127  }
128}
129
130/**
131 * draws this worldEntity
132 */
133void NetworkTurret::draw () const
134{
135  WorldEntity::draw();
136
137  if (this->weapon != NULL)
138    this->weapon->draw();
139}
140
141void NetworkTurret::setTargetGroup(int targetGroup)
142{
143  this->targetGroup = targetGroup;
144  this->weapon->setTargetGroup((OM_LIST)targetGroup);
145}
146
147
148void NetworkTurret::setTargetGroupS(const std::string& groupName)
149{
150  OM_LIST id = ObjectManager::StringToOMList(groupName);
151  if (id != OM_NULL)
152    this->setTargetGroup(id);
153  else
154    PRINTF(2)("List %s not found for targetting\n", groupName.c_str());
155}
156
157void NetworkTurret::varChangeHandler( std::list< int > & id )
158{
159  WorldEntity::varChangeHandler( id );
160
161  if ( std::find( id.begin(), id.end(), targetGroup_handle) != id.end() )
162  {
163    setTargetGroup( targetGroup_write );
164  }
165}
166
167/**
168 *
169 *
170 */
171void NetworkTurret::postSpawn ()
172{}
173
174/**
175 *
176 *
177 */
178void NetworkTurret::leftWorld ()
179{}
180
181void NetworkTurret::destroy(WorldEntity* killer)
182{
183  this->setAbsDirSoft(Quaternion(-90, Vector(0,0,1)), 90);
184  Explosion::explode(this, Vector(10,10,10));
185
186  this->toList(OM_DEAD);
187}
Note: See TracBrowser for help on using the repository browser.