Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/world_entities/npcs/network_turret.cc @ 9716

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

more renamings

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"
[5739]32
[9716]33#include "class_id_DEPRECATED.h"
[9715]34ObjectListDefinitionID(NetworkTurret, CL_NETWORK_TURRET);
[9709]35CREATE_FACTORY(NetworkTurret);
[5596]36
37
38/**
[9608]39 * constructs and loads a NetworkTurret from a XML-element
[5596]40 * @param root the XML-element to load from
41 */
[9608]42NetworkTurret::NetworkTurret(const TiXmlElement* root)
[9518]43    : NPC(root)
[5596]44{
45  this->init();
46  if (root != NULL)
47    this->loadParams(root);
48}
49
50
51/**
52 * standard deconstructor
53 */
[9608]54NetworkTurret::~NetworkTurret ()
55{}
[5596]56
57
58/**
[9608]59 * initializes the NetworkTurret
[5596]60 * @todo change this to what you wish
61 */
[9608]62void NetworkTurret::init()
[5596]63{
[9709]64  this->registerObject(this, NetworkTurret::_objectList);
[9609]65  this->loadModel("models/ground_turret_#.obj", 5);
66
[9615]67  this->weapon = new AimingTurret();
[9608]68  this->weapon->loadModel("models/guns/turret2.obj", 10);
[9609]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);
[5795]74
[7076]75  this->setHealthMax(300);
76  this->setHealth(300);
77
[9608]78  this->weaponHolder.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
[7102]79
[9608]80  this->weaponHolder.setRelCoor(0,25,0);
81  this->weaponHolder.setParent(this);
[9610]82
[9611]83
84  this->targetGroup = OM_GROUP_01;
85  this->targetGroup_write = OM_GROUP_01;
[9625]86  this->targetGroup_handle = this->registerVarId( new SynchronizeableInt ( &targetGroup, &targetGroup_write, "targetgroup", PERMISSION_MASTER_SERVER ) );
[9611]87
88  this->setSynchronized( true );
[5596]89}
90
91
92/**
[9608]93 * @brief loads a NetworkTurret from a XML-element
[5596]94 * @param root the XML-element to load from
95 * @todo make the class Loadable
96 */
[9608]97void NetworkTurret::loadParams(const TiXmlElement* root)
[5596]98{
99  // all the clases this Entity is directly derived from must be called in this way, to load all settings.
[6512]100  NPC::loadParams(root);
[9610]101
102  LoadParam(root, "target-group", this, NetworkTurret, setTargetGroupS);
[5596]103}
104
105/**
[9608]106 * advances the NetworkTurret about time seconds
[5596]107 * @param time the Time to step
108 */
[9608]109void NetworkTurret::tick(float dt)
[5739]110{
[9612]111  ObjectManager::EntityList::iterator entity;
112  Vector diffVec;
[9709]113  for (entity = State::getObjectManager()->getEntityList((OM_LIST)this->targetGroup).begin();
114       entity != State::getObjectManager()->getEntityList((OM_LIST)this->targetGroup).end();
[9612]115       entity ++)
[7076]116  {
[9612]117    diffVec = ( (*entity)->getAbsCoor() - this->getAbsCoor() );
118
[9616]119    if ( diffVec.len() < 400.0 )//&&  acos( (this->source->getAbsDirX()).dot(diffVec)/(diffVec.len() * (this->source->getAbsDirX()).len() ) )  < angle)
[9518]120    {
[9612]121      //if (this->getParent() != (*entity))
122      {
123        this->weapon->requestAction(WA_SHOOT);
124        return;
125      }
[9518]126    }
[6433]127  }
[5739]128}
129
[5596]130/**
131 * draws this worldEntity
132 */
[9608]133void NetworkTurret::draw () const
[5596]134{
[6424]135  WorldEntity::draw();
[5596]136
[9608]137  if (this->weapon != NULL)
138    this->weapon->draw();
[5596]139}
140
[9610]141void NetworkTurret::setTargetGroup(int targetGroup)
142{
[9619]143  this->targetGroup = targetGroup;
[9610]144  this->weapon->setTargetGroup((OM_LIST)targetGroup);
145}
[5596]146
[5680]147
[9610]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
[5680]167/**
168 *
169 *
170 */
[9608]171void NetworkTurret::postSpawn ()
172{}
[5680]173
174/**
175 *
176 *
177 */
[9608]178void NetworkTurret::leftWorld ()
179{}
[6341]180
[9608]181void NetworkTurret::destroy(WorldEntity* killer)
[7076]182{
183  this->setAbsDirSoft(Quaternion(-90, Vector(0,0,1)), 90);
[7105]184  Explosion::explode(this, Vector(10,10,10));
[8777]185
186  this->toList(OM_DEAD);
[7076]187}
Note: See TracBrowser for help on using the repository browser.