Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file was 10114, checked in by patrick, 17 years ago

merged network back to trunk

File size: 4.3 KB
RevLine 
[5596]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
[9608]16#include "network_turret.h"
[5739]17#include "model.h"
[6432]18#include "world_entities/weapons/turret.h"
[5596]19
[7076]20#include "state.h"
21#include "playable.h"
22#include "player.h"
23
24
[7193]25#include "util/loading/factory.h"
[6341]26#include "network_game_manager.h"
[7193]27#include "util/loading/load_param.h"
[5795]28
[7103]29#include "effects/explosion.h"
30
[9615]31#include "weapons/aiming_turret.h"
[9869]32#include "debug.h"
[5739]33
[10114]34
35ObjectListDefinition(NetworkTurret);
[9869]36CREATE_FACTORY(NetworkTurret);
[5596]37
38
39/**
[9608]40 * constructs and loads a NetworkTurret from a XML-element
[5596]41 * @param root the XML-element to load from
42 */
[9608]43NetworkTurret::NetworkTurret(const TiXmlElement* root)
[9518]44    : NPC(root)
[5596]45{
46  this->init();
47  if (root != NULL)
48    this->loadParams(root);
49}
50
51
52/**
53 * standard deconstructor
54 */
[9608]55NetworkTurret::~NetworkTurret ()
56{}
[5596]57
58
59/**
[9608]60 * initializes the NetworkTurret
[5596]61 * @todo change this to what you wish
62 */
[9608]63void NetworkTurret::init()
[5596]64{
[9869]65  this->registerObject(this, NetworkTurret::_objectList);
[9609]66  this->loadModel("models/ground_turret_#.obj", 5);
67
[9615]68  this->weapon = new AimingTurret();
[9608]69  this->weapon->loadModel("models/guns/turret2.obj", 10);
[9609]70  this->weapon->setParent(this);
71  this->weapon->toList(this->getOMListNumber());
72  this->weapon->setRelCoor(0,10,-5);
73  this->weapon->requestAction( WA_ACTIVATE);
74  this->weapon->setParent(&this->weaponHolder);
[5795]75
[7076]76  this->setHealthMax(300);
77  this->setHealth(300);
78
[9608]79  this->weaponHolder.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
[7102]80
[9608]81  this->weaponHolder.setRelCoor(0,25,0);
82  this->weaponHolder.setParent(this);
[9610]83
[9611]84
85  this->targetGroup = OM_GROUP_01;
86  this->targetGroup_write = OM_GROUP_01;
[9625]87  this->targetGroup_handle = this->registerVarId( new SynchronizeableInt ( &targetGroup, &targetGroup_write, "targetgroup", PERMISSION_MASTER_SERVER ) );
[9611]88
89  this->setSynchronized( true );
[5596]90}
91
92
93/**
[9608]94 * @brief loads a NetworkTurret from a XML-element
[5596]95 * @param root the XML-element to load from
96 * @todo make the class Loadable
97 */
[9608]98void NetworkTurret::loadParams(const TiXmlElement* root)
[5596]99{
100  // all the clases this Entity is directly derived from must be called in this way, to load all settings.
[6512]101  NPC::loadParams(root);
[9610]102
103  LoadParam(root, "target-group", this, NetworkTurret, setTargetGroupS);
[5596]104}
105
106/**
[9608]107 * advances the NetworkTurret about time seconds
[5596]108 * @param time the Time to step
109 */
[9608]110void NetworkTurret::tick(float dt)
[5739]111{
[9612]112  ObjectManager::EntityList::iterator entity;
113  Vector diffVec;
[9869]114  for (entity = State::getObjectManager()->getEntityList((OM_LIST)this->targetGroup).begin();
115       entity != State::getObjectManager()->getEntityList((OM_LIST)this->targetGroup).end();
[9612]116       entity ++)
[7076]117  {
[9612]118    diffVec = ( (*entity)->getAbsCoor() - this->getAbsCoor() );
119
[9616]120    if ( diffVec.len() < 400.0 )//&&  acos( (this->source->getAbsDirX()).dot(diffVec)/(diffVec.len() * (this->source->getAbsDirX()).len() ) )  < angle)
[9518]121    {
[9612]122      //if (this->getParent() != (*entity))
123      {
124        this->weapon->requestAction(WA_SHOOT);
125        return;
126      }
[9518]127    }
[6433]128  }
[5739]129}
130
[5596]131/**
132 * draws this worldEntity
133 */
[9608]134void NetworkTurret::draw () const
[5596]135{
[6424]136  WorldEntity::draw();
[5596]137
[9608]138  if (this->weapon != NULL)
139    this->weapon->draw();
[5596]140}
141
[9610]142void NetworkTurret::setTargetGroup(int targetGroup)
143{
[9619]144  this->targetGroup = targetGroup;
[9610]145  this->weapon->setTargetGroup((OM_LIST)targetGroup);
146}
[5596]147
[5680]148
[9610]149void NetworkTurret::setTargetGroupS(const std::string& groupName)
150{
151  OM_LIST id = ObjectManager::StringToOMList(groupName);
152  if (id != OM_NULL)
153    this->setTargetGroup(id);
154  else
155    PRINTF(2)("List %s not found for targetting\n", groupName.c_str());
156}
157
158void NetworkTurret::varChangeHandler( std::list< int > & id )
159{
160  WorldEntity::varChangeHandler( id );
161
162  if ( std::find( id.begin(), id.end(), targetGroup_handle) != id.end() )
163  {
164    setTargetGroup( targetGroup_write );
165  }
166}
167
[5680]168/**
169 *
170 *
171 */
[9608]172void NetworkTurret::postSpawn ()
173{}
[5680]174
175/**
176 *
177 *
178 */
[9608]179void NetworkTurret::leftWorld ()
180{}
[6341]181
[9608]182void NetworkTurret::destroy(WorldEntity* killer)
[7076]183{
184  this->setAbsDirSoft(Quaternion(-90, Vector(0,0,1)), 90);
[7105]185  Explosion::explode(this, Vector(10,10,10));
[8777]186
187  this->toList(OM_DEAD);
[7076]188}
Note: See TracBrowser for help on using the repository browser.