Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/util/multiplayer_team_deathmatch.cc @ 8019

Last change on this file since 8019 was 7954, checked in by patrick, 18 years ago

trunk: merged the network branche back to trunk.

File size: 6.2 KB
RevLine 
[7034]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: Patrick Boenzli
13*/
14
15#define DEBUG_MODULE_GAME_RULES
16
17#include "multiplayer_team_deathmatch.h"
18
[7193]19#include "util/loading/load_param.h"
20#include "util/loading/factory.h"
[7034]21
[7810]22#include "render2D/image_plane.h"
[7039]23#include "state.h"
[7101]24#include "class_list.h"
[7034]25
[7044]26#include "player.h"
27#include "playable.h"
[7101]28#include "space_ships/space_ship.h"
[7039]29
[7116]30
[7101]31#include "shared_network_data.h"
[7116]32#include "terrain.h"
33#include "class_list.h"
34#include "space_ships/space_ship.h"
[7044]35
[7101]36
[7034]37using namespace std;
38
39
[7035]40CREATE_FACTORY(MultiplayerTeamDeathmatch, CL_MULTIPLAYER_TEAM_DEATHMATCH);
41
42
[7034]43/**
44 * constructor
45 */
[7035]46MultiplayerTeamDeathmatch::MultiplayerTeamDeathmatch(const TiXmlElement* root)
[7034]47  : GameRules(root)
[7035]48{
49  this->setClassID(CL_MULTIPLAYER_TEAM_DEATHMATCH, "MultiplayerTeamDeathmatch");
[7034]50
[7037]51  this->bLocalPlayerDead = false;
52  this->deathTimeout = 10.0f;     // 5 seconds
[7082]53  this->timeout = 0.0f;
[7040]54
[7810]55  this->deathScreen = new ImagePlane();
[7044]56  this->deathScreen->setSize(State::getResX()/4.0, State::getResY()/4.0);
[7040]57  this->deathScreen->setAbsCoor2D(State::getResX()/2.0f, State::getResY()/2.0f);
[7044]58  this->deathScreen->setVisibility(false);
[7037]59
[7044]60  this->localPlayer = State::getPlayer();
61
[7035]62  if( root != NULL)
63    this->loadParams(root);
64}
65
[7034]66/**
67 * decontsructor
68 */
69MultiplayerTeamDeathmatch::~MultiplayerTeamDeathmatch()
[7044]70{
71  if( this->deathScreen)
72    delete this->deathScreen;
73}
[7034]74
75
76
77void MultiplayerTeamDeathmatch::loadParams(const TiXmlElement* root)
[7035]78{
[7040]79  GameRules::loadParams(root) ;
[7037]80
81  LoadParam(root, "death-penalty-timeout", this, MultiplayerTeamDeathmatch, setDeathPenaltyTimeout)
82      .describe("sets the time in seconds a player has to wait for respawn");
83
84  LoadParam(root, "max-kills", this, MultiplayerTeamDeathmatch, setMaxKills)
85      .describe("sets the maximal kills for winning condition");
[7039]86
87  LoadParam(root, "death-screen-image", this, MultiplayerTeamDeathmatch, setDeathScreen)
88      .describe("sets the death screen image");
89
[7035]90}
91
92
[7039]93
[7221]94void MultiplayerTeamDeathmatch::setDeathScreen(const std::string& imageName)
[7039]95{
96  if( this->deathScreen)
97    this->deathScreen->setTexture(imageName);
98}
99
100
101
[7035]102/**
103 * called when the player enters the game
104 * @param player the spawned player
105 */
[7044]106void MultiplayerTeamDeathmatch::onPlayerSpawn()
[7039]107{
[7044]108  this->bLocalPlayerDead = false;
109  this->deathScreen->setVisibility(false);
[7039]110}
[7034]111
[7035]112
113/**
114 * when the player is killed
115 * @param player the killed player
116 */
[7044]117void MultiplayerTeamDeathmatch::onPlayerDeath()
[7039]118{
119  this->bLocalPlayerDead = true;
[7044]120  this->deathScreen->setVisibility(true);
[7039]121}
[7035]122
123
124/**
125 * time tick
126 * @param dt time
127 */
128void MultiplayerTeamDeathmatch::tick(float dt)
[7037]129{
[7039]130  this->checkGameRules();
[7035]131
[7039]132  // is the local player dead and inactive
133  if( unlikely(this->bLocalPlayerDead))
134  {
135    this->timeout += dt;
[7088]136    PRINTF(0)("TICK DEATH: %f of %f\n", this->timeout, this->deathTimeout);
[7039]137    // long enough dead?
[7044]138    if( this->timeout >= this->deathTimeout)
[7039]139    {
140      this->timeout = 0.0f;
141      // respawn
[7079]142      PRINTF(0)("RESPAWN\n");
[7044]143      (State::getPlayer())->getPlayable()->respawn();
[7039]144    }
145  }
[7037]146}
[7035]147
[7037]148
[7035]149/**
150 * draws the stuff
151 */
152void MultiplayerTeamDeathmatch::draw()
[7039]153{
154  if( unlikely( this->bLocalPlayerDead))
155  {
[7035]156
[7039]157  }
158}
[7035]159
[7039]160
[7035]161/**
162 * check the game rules for consistency
163 */
164void MultiplayerTeamDeathmatch::checkGameRules()
[7039]165{
[7101]166
167  Vector big_left(-201, 0, 0);
168  float rBig = 176.0f;
169  Vector big_right(177, 0, 0);
170  Vector small_left(10, 0, 0);
171  Vector small_middle(0, 0, 0);
172  Vector small_right(-10, 0, 0);
173  float rSmall = 90.0f;
174
175
[7039]176  // check for max killing count
177  if( this->teamAKills >= this->maxKills)
178  {
179    // team A winns
180  }
181  else if( this->teamBKills >= this->maxKills)
182  {
183    // team B winns
184  }
[7101]185
[7118]186
[7116]187  if ( SharedNetworkData::getInstance()->isGameServer() )
188  {
189    float offsetx = 500.0f;
190    float offsety = 323.0f;
191    float offsetz = 200.0f;
[7118]192
[7116]193    offsetz += 10;
[7118]194
[7116]195    Terrain * terrain = dynamic_cast<Terrain*>(*(ClassList::getList( CL_TERRAIN )->begin()));
196    const std::list<BaseObject*> * list = ClassList::getList( CL_SPACE_SHIP );
197    for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++)
198    {
199      SpaceShip * ss = dynamic_cast<SpaceShip*>(*it);
200      float terrx = ss->getAbsCoor().x + offsetx;
201      float terry = ss->getAbsCoor().z + offsetz;
202      float terrz = ss->getAbsCoor().y + offsety;
203      if ( terrz < terrain->getHeight( terrx, terry ) && ss->getAbsCoor().x > -1000 )
204      {
[7954]205        //TODO handle this
[7116]206      }
[7118]207
[7954]208
[7116]209      float dist = (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_left).len();
210      if( (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_left).len() > rBig &&
211           (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_right).len() > rBig &&
212           (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_left).len() > rSmall &&
213           (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_middle).len() > rSmall &&
[7118]214           (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_right).len() > rSmall
215           && ss->getAbsCoor().x > -1000)
[7116]216      {
217        PRINTF(0)("KILLLLLLLL\n");
[7101]218
[7116]219        if((*it)->isA(CL_SPACE_SHIP))
220        {
[7954]221          //TODO handle this
[7116]222        }
223      }
224    }
225  }
[7101]226
227
[7116]228#if 0
[7101]229  std::list<BaseObject*>::const_iterator it;
230  const std::list<BaseObject*>* list = ClassList::getList(CL_PLAYABLE);
231
232  if( SharedNetworkData::getInstance()->isGameServer())
233  {
234    for(it = list->begin(); it != list->end(); it++)
235    {
236      float dist = (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_left).len();
237      if( (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_left).len() > rBig &&
238           (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_right).len() > rBig &&
239           (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_left).len() > rSmall &&
240           (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_middle).len() > rSmall &&
241           (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_right).len() > rSmall)
242      {
243        PRINTF(0)("KILLLLLLLL\n");
244
245        if((*it)->isA(CL_SPACE_SHIP))
246          dynamic_cast<SpaceShip*>(*it)->doCollideNetwork(116369220.33434f);
247      }
248    }
249  }
[7116]250#endif
[7101]251
[7039]252}
[7035]253
254
255
256
257
258
Note: See TracBrowser for help on using the repository browser.