Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/util/multiplayer_team_deathmatch.cc @ 7792

Last change on this file since 7792 was 7444, checked in by rennerc, 19 years ago

new network system implemented. yet with a lot of empty function bodys

File size: 6.2 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        //TODO handle this
206      }
207
208
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 &&
214           (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_right).len() > rSmall
215           && ss->getAbsCoor().x > -1000)
216      {
217        PRINTF(0)("KILLLLLLLL\n");
218
219        if((*it)->isA(CL_SPACE_SHIP))
220        {
221          //TODO handle this
222        }
223      }
224    }
225  }
226
227
228#if 0
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  }
250#endif
251
252}
253
254
255
256
257
258
Note: See TracBrowser for help on using the repository browser.