Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7341 was 7221, checked in by bensch, 19 years ago

orxonox/trunk: merged the std-branche back, it runs on windows and Linux

svn merge https://svn.orxonox.net/orxonox/branches/std . -r7202:HEAD

File size: 6.7 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
[7039]22#include "render2D/billboard.h"
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
[7039]55  this->deathScreen = new Billboard();
[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      {
205        //PRINTF(0)("COLLLLLLIIIIIDDDDEEEE\n");
206        ss->networkCollisionList.push_back( 1234567890 );
207        ss->doCollideNetwork( 1234567890 );
208      }
209      //PRINTF(0)("x = %f, y = %f, z = %f, height = %f\n", terrx, terry, terrz, terrain->getHeight( terrx, terry ));
210      //ss->setRelCoorSoft( ss->getAbsCoor().x, terrain->getHeight( terrx, terry )-offsety, ss->getAbsCoor().z );
[7118]211
[7116]212      float dist = (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_left).len();
213      if( (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_left).len() > rBig &&
214           (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_right).len() > rBig &&
215           (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_left).len() > rSmall &&
216           (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_middle).len() > rSmall &&
[7118]217           (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_right).len() > rSmall
218           && ss->getAbsCoor().x > -1000)
[7116]219      {
220        PRINTF(0)("KILLLLLLLL\n");
[7101]221
[7116]222        if((*it)->isA(CL_SPACE_SHIP))
223        {
[7118]224          dynamic_cast<SpaceShip*>(*it)->networkCollisionList.push_back(1163692);
225          dynamic_cast<SpaceShip*>(*it)->doCollideNetwork(11636922);
[7116]226        }
227      }
228    }
229  }
[7101]230
231
[7116]232#if 0
[7101]233  std::list<BaseObject*>::const_iterator it;
234  const std::list<BaseObject*>* list = ClassList::getList(CL_PLAYABLE);
235
236  if( SharedNetworkData::getInstance()->isGameServer())
237  {
238    for(it = list->begin(); it != list->end(); it++)
239    {
240      float dist = (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_left).len();
241      if( (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_left).len() > rBig &&
242           (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_right).len() > rBig &&
243           (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_left).len() > rSmall &&
244           (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_middle).len() > rSmall &&
245           (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_right).len() > rSmall)
246      {
247        PRINTF(0)("KILLLLLLLL\n");
248
249        if((*it)->isA(CL_SPACE_SHIP))
250          dynamic_cast<SpaceShip*>(*it)->doCollideNetwork(116369220.33434f);
251      }
252    }
253  }
[7116]254#endif
[7101]255
[7039]256}
[7035]257
258
259
260
261
262
Note: See TracBrowser for help on using the repository browser.