Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/resources/src/util/multiplayer_team_deathmatch.cc @ 8484

Last change on this file since 8484 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
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: Patrick Boenzli
13*/
14
15#define DEBUG_MODULE_GAME_RULES
16
17#include "multiplayer_team_deathmatch.h"
18
19#include "util/loading/load_param.h"
20#include "util/loading/factory.h"
21
22#include "render2D/billboard.h"
23#include "state.h"
24#include "class_list.h"
25
26#include "player.h"
27#include "playable.h"
28#include "space_ships/space_ship.h"
29
30
31#include "shared_network_data.h"
32#include "terrain.h"
33#include "class_list.h"
34#include "space_ships/space_ship.h"
35
36
37using namespace std;
38
39
40CREATE_FACTORY(MultiplayerTeamDeathmatch, CL_MULTIPLAYER_TEAM_DEATHMATCH);
41
42
43/**
44 * constructor
45 */
46MultiplayerTeamDeathmatch::MultiplayerTeamDeathmatch(const TiXmlElement* root)
47  : GameRules(root)
48{
49  this->setClassID(CL_MULTIPLAYER_TEAM_DEATHMATCH, "MultiplayerTeamDeathmatch");
50
51  this->bLocalPlayerDead = false;
52  this->deathTimeout = 10.0f;     // 5 seconds
53  this->timeout = 0.0f;
54
55  this->deathScreen = new Billboard();
56  this->deathScreen->setSize(State::getResX()/4.0, State::getResY()/4.0);
57  this->deathScreen->setAbsCoor2D(State::getResX()/2.0f, State::getResY()/2.0f);
58  this->deathScreen->setVisibility(false);
59
60  this->localPlayer = State::getPlayer();
61
62  if( root != NULL)
63    this->loadParams(root);
64}
65
66/**
67 * decontsructor
68 */
69MultiplayerTeamDeathmatch::~MultiplayerTeamDeathmatch()
70{
71  if( this->deathScreen)
72    delete this->deathScreen;
73}
74
75
76
77void MultiplayerTeamDeathmatch::loadParams(const TiXmlElement* root)
78{
79  GameRules::loadParams(root) ;
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");
86
87  LoadParam(root, "death-screen-image", this, MultiplayerTeamDeathmatch, setDeathScreen)
88      .describe("sets the death screen image");
89
90}
91
92
93
94void MultiplayerTeamDeathmatch::setDeathScreen(const std::string& imageName)
95{
96  if( this->deathScreen)
97    this->deathScreen->setTexture(imageName);
98}
99
100
101
102/**
103 * called when the player enters the game
104 * @param player the spawned player
105 */
106void MultiplayerTeamDeathmatch::onPlayerSpawn()
107{
108  this->bLocalPlayerDead = false;
109  this->deathScreen->setVisibility(false);
110}
111
112
113/**
114 * when the player is killed
115 * @param player the killed player
116 */
117void MultiplayerTeamDeathmatch::onPlayerDeath()
118{
119  this->bLocalPlayerDead = true;
120  this->deathScreen->setVisibility(true);
121}
122
123
124/**
125 * time tick
126 * @param dt time
127 */
128void MultiplayerTeamDeathmatch::tick(float dt)
129{
130  this->checkGameRules();
131
132  // is the local player dead and inactive
133  if( unlikely(this->bLocalPlayerDead))
134  {
135    this->timeout += dt;
136    PRINTF(0)("TICK DEATH: %f of %f\n", this->timeout, this->deathTimeout);
137    // long enough dead?
138    if( this->timeout >= this->deathTimeout)
139    {
140      this->timeout = 0.0f;
141      // respawn
142      PRINTF(0)("RESPAWN\n");
143      (State::getPlayer())->getPlayable()->respawn();
144    }
145  }
146}
147
148
149/**
150 * draws the stuff
151 */
152void MultiplayerTeamDeathmatch::draw()
153{
154  if( unlikely( this->bLocalPlayerDead))
155  {
156
157  }
158}
159
160
161/**
162 * check the game rules for consistency
163 */
164void MultiplayerTeamDeathmatch::checkGameRules()
165{
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
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  }
185
186
187  if ( SharedNetworkData::getInstance()->isGameServer() )
188  {
189    float offsetx = 500.0f;
190    float offsety = 323.0f;
191    float offsetz = 200.0f;
192
193    offsetz += 10;
194
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 );
211
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 &&
217           (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_right).len() > rSmall
218           && ss->getAbsCoor().x > -1000)
219      {
220        PRINTF(0)("KILLLLLLLL\n");
221
222        if((*it)->isA(CL_SPACE_SHIP))
223        {
224          dynamic_cast<SpaceShip*>(*it)->networkCollisionList.push_back(1163692);
225          dynamic_cast<SpaceShip*>(*it)->doCollideNetwork(11636922);
226        }
227      }
228    }
229  }
230
231
232#if 0
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  }
254#endif
255
256}
257
258
259
260
261
262
Note: See TracBrowser for help on using the repository browser.