Update of /cvsroot/opentnl/tnl/zap
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27167/zap
Modified Files:
CTFGame.cpp CTFGame.h UIGame.cpp ZAP.vcproj game.cpp game.h
gameType.cpp gameType.h main.cpp soccerGame.cpp soccerGame.h
Added Files:
timer.h
Log Message:
Fixed ghosting bug
Made games cycle after time or score limit are reached
--- NEW FILE: timer.h ---
//-----------------------------------------------------------------------------------
//
// Torque Network Library - ZAP example multiplayer vector graphics space game
// Copyright (C) 2004 GarageGames.com, Inc.
// For more information see http://www.opentnl.org
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// For use in products that are not compatible with the terms of the GNU
// General Public License, alternative licensing options are available
// from GarageGames.com.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
//------------------------------------------------------------------------------------
#ifndef _TIMER_H_
#define _TIMER_H_
namespace Zap
{
class Timer
{
U32 mPeriod;
U32 mCurrentCounter;
public:
Timer(U32 period = 0)
{
mCurrentCounter = mPeriod = period;
}
bool update(U32 timeDelta)
{
if(!mCurrentCounter)
return false;
if(timeDelta >= mCurrentCounter)
{
mCurrentCounter = 0;
return true;
}
mCurrentCounter -= timeDelta;
return false;
}
U32 getCurrent()
{
return mCurrentCounter;
}
void reset()
{
mCurrentCounter = mPeriod;
}
void reset(U32 newPeriod)
{
mCurrentCounter = mPeriod = newPeriod;
}
};
};
#endif
Index: gameType.cpp
===================================================================
RCS file: /cvsroot/opentnl/tnl/zap/gameType.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** gameType.cpp 30 Apr 2004 20:27:41 -0000 1.15
--- gameType.cpp 2 May 2004 06:27:41 -0000 1.16
***************
*** 36,53 ****
GameType::GameType()
{
mNetFlags.set(Ghostable);
! mTimeUntilScoreboardUpdate = 0;
}
void GameType::processArguments(S32 argc, const char **argv)
{
}
void GameType::processServer(U32 deltaT)
{
! if(deltaT > mTimeUntilScoreboardUpdate)
{
for(S32 i = 0; i < mClientList.size(); i++)
if(mClientList[i].clientConnection)
--- 36,66 ----
GameType::GameType()
+ : mScoreboardUpdateTimer(1000)
+ , mGameTimer(DefaultGameTime)
+ , mGameTimeUpdateTimer(30000)
{
mNetFlags.set(Ghostable);
! mGameOver = false;
! mTeamScoreLimit = DefaultTeamScoreLimit;
}
void GameType::processArguments(S32 argc, const char **argv)
{
+ if(argc > 0)
+ mGameTimer.reset(U32(atof(argv[0]) * 60 * 1000));
+ if(argc > 1)
+ mTeamScoreLimit = atoi(argv[1]);
+ }
+ void GameType::processClient(U32 deltaT)
+ {
+ mGameTimer.update(deltaT);
}
void GameType::processServer(U32 deltaT)
{
! if(mScoreboardUpdateTimer.update(deltaT))
{
+ mScoreboardUpdateTimer.reset();
for(S32 i = 0; i < mClientList.size(); i++)
if(mClientList[i].clientConnection)
***************
*** 55,78 ****
for(S32 i = 0; i < mClientList.size(); i++)
! if(mClientList[i].wantsScoreboardUpdates)
updateClientScoreboard(i);
! mTimeUntilScoreboardUpdate = 1000;
}
- else
- mTimeUntilScoreboardUpdate -= deltaT;
for(S32 i = 0; i < mClientList.size(); i++)
{
! if(mClientList[i].respawnDelay)
! {
! if(mClientList[i].respawnDelay <= deltaT)
! spawnShip(mClientList[i].clientConnection);
! else
! mClientList[i].respawnDelay -= deltaT;
! }
}
}
void GameType::onAddedToGame(Game *theGame)
{
--- 68,107 ----
for(S32 i = 0; i < mClientList.size(); i++)
! if(mGameOver || mClientList[i].wantsScoreboardUpdates)
updateClientScoreboard(i);
+ }
! if(mGameTimeUpdateTimer.update(deltaT))
! {
! mGameTimeUpdateTimer.reset();
! s2cSetTimeRemaining(mGameTimer.getCurrent());
}
for(S32 i = 0; i < mClientList.size(); i++)
{
! if(mClientList[i].respawnTimer.update(deltaT))
! spawnShip(mClientList[i].clientConnection);
! }
!
! if(mGameTimer.update(deltaT))
! {
! gameOverManGameOver();
}
}
+ void GameType::gameOverManGameOver()
+ {
+ // 17 days??? We won't last 17 hours!
+ mGameOver = true;
+ s2cSetGameOver(true);
+ gServerGame->gameEnded();
+ }
+
+ TNL_IMPLEMENT_NETOBJECT_RPC(GameType, s2cSetGameOver, (bool gameOver),
+ NetClassGroupGameMask, RPCGuaranteedOrdered, RPCToGhost, 0)
+ {
+ mGameOver = gameOver;
+ }
+
void GameType::onAddedToGame(Game *theGame)
{
***************
*** 133,137 ****
S32 teamIndex = mClientList[clientIndex].teamId;
- mClientList[clientIndex].respawnDelay = 0;
Point spawnPoint;
S32 spawnIndex = Random::readI() % mTeams[teamIndex].spawnPoints.size();
--- 162,165 ----
***************
*** 185,189 ****
S32 clientIndex = findClientIndexByConnection(theClient);
if(clientIndex != -1)
! mClientList[clientIndex].respawnDelay = RespawnDelay;
}
--- 213,217 ----
S32 clientIndex = findClientIndexByConnection(theClient);
if(clientIndex != -1)
! mClientList[clientIndex].respawnTimer.reset(RespawnDelay);
}
***************
*** 205,208 ****
--- 233,250 ----
}
+ void GameType::setTeamScore(S32 teamIndex, S32 newScore)
+ {
+ mTeams[teamIndex].score = newScore;
+ s2cSetTeamScore(teamIndex, newScore);
+ if(newScore >= mTeamScoreLimit)
+ gameOverManGameOver();
+ }
+
+ TNL_IMPLEMENT_NETOBJECT_RPC(GameType, s2cSetTimeRemaining, (U32 timeLeft),
+ NetClassGroupGameMask, RPCGuaranteedOrdered, RPCToGhost, 0)
+ {
+ mGameTimer.reset(timeLeft);
+ }
+
TNL_IMPLEMENT_NETOBJECT_RPC(GameType, c2sChangeTeams, (),
NetClassGroupGameMask, RPCGuaranteedOrdered, RPCToGhostParent, 0)
***************
*** 303,306 ****
--- 345,350 ----
s2cClientJoinedTeam(mClientList[i].name, mClientList[i].teamId);
}
+ s2cSetTimeRemaining(mGameTimer.getCurrent());
+ s2cSetGameOver(mGameOver);
NetObject::setRPCDestConnection(NULL);
}
Index: soccerGame.cpp
===================================================================
RCS file: /cvsroot/opentnl/tnl/zap/soccerGame.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** soccerGame.cpp 30 Apr 2004 20:27:42 -0000 1.1
--- soccerGame.cpp 2 May 2004 06:27:41 -0000 1.2
***************
*** 44,48 ****
void SoccerGameType::renderInterfaceOverlay(bool scoreboardVisible)
{
! if(scoreboardVisible)
{
U32 totalWidth = 780;
--- 44,48 ----
void SoccerGameType::renderInterfaceOverlay(bool scoreboardVisible)
{
! if(scoreboardVisible || mGameOver )
{
U32 totalWidth = 780;
***************
*** 119,123 ****
for(S32 i = 0; i < mTeams.size(); i++)
{
! Point pos(750, 550 - i * 38);
renderFlag(pos + Point(-20, 18), mTeams[i].color);
glColor3f(1,1,1);
--- 119,123 ----
for(S32 i = 0; i < mTeams.size(); i++)
{
! Point pos(750, 535 - i * 38);
renderFlag(pos + Point(-20, 18), mTeams[i].color);
glColor3f(1,1,1);
***************
*** 125,128 ****
--- 125,133 ----
}
}
+ U32 timeLeft = mGameTimer.getCurrent();
+
+ U32 minsRemaining = timeLeft / (60000);
+ U32 secsRemaining = (timeLeft - (minsRemaining * 60000)) / 1000;
+ UserInterface::drawStringf(720, 577, 20, "%02d:%02d", minsRemaining, secsRemaining);
}
***************
*** 143,147 ****
s2cKillMessage(mClientList[clientIndex].name, mClientList[killerIndex].name);
}
! mClientList[clientIndex].respawnDelay = RespawnDelay;
}
--- 148,152 ----
s2cKillMessage(mClientList[clientIndex].name, mClientList[killerIndex].name);
}
! mClientList[clientIndex].respawnTimer.reset(RespawnDelay);
}
***************
*** 158,174 ****
}
! TNL_IMPLEMENT_NETOBJECT_RPC(SoccerGameType, s2cSoccerScoreMessage, (StringTableEntry clientName, U32 teamIndex),
NetClassGroupGameMask, RPCGuaranteedOrdered, RPCToGhost, 0)
{
! gGameUserInterface.displayMessage(Color(0.6f, 1.0f, 0.8f),
! "%s scored a goal for team %s!",
! clientName.getString(),
! mTeams[teamIndex].name.getString());
! SFXObject::play(SFXFlagCapture);
}
void SoccerGameType::scoreGoal(StringTableEntry playerName, U32 goalTeamIndex)
{
! s2cSoccerScoreMessage(playerName, goalTeamIndex);
}
--- 163,251 ----
}
! TNL_IMPLEMENT_NETOBJECT_RPC(SoccerGameType, s2cSoccerScoreMessage, (U32 msgIndex, StringTableEntry clientName, U32 teamIndex),
NetClassGroupGameMask, RPCGuaranteedOrdered, RPCToGhost, 0)
{
! if(msgIndex == SoccerMsgScoreGoal)
! {
! SFXObject::play(SFXFlagCapture);
! gGameUserInterface.displayMessage(Color(0.6f, 1.0f, 0.8f),
! "%s scored a goal on team %s!",
! clientName.getString(),
! mTeams[teamIndex].name.getString());
! }
! else if(msgIndex == SoccerMsgScoreOwnGoal)
! {
! SFXObject::play(SFXFlagCapture);
! if(clientName.isNull())
! gGameUserInterface.displayMessage(Color(0.6f, 1.0f, 0.8f),
! "A goal was scored on team %s!",
! mTeams[teamIndex].name.getString());
! else
! gGameUserInterface.displayMessage(Color(0.6f, 1.0f, 0.8f),
! "%s scored a goal for the other team%s!",
! clientName.getString(),
! mTeams.size() > 2 ? "s" : "");
! }
! else if(msgIndex == SoccerMsgGameOverTeamWin)
! {
! gGameUserInterface.displayMessage(Color(0.6f, 1.0f, 0.8f),
! "Team %s wins the game!",
! mTeams[teamIndex].name.getString());
! SFXObject::play(SFXFlagCapture);
! }
! else if(msgIndex == SoccerMsgGameOverTie)
! {
! gGameUserInterface.displayMessage(Color(0.6f, 1.0f, 0.8f),
! "The game ended in a tie.");
! SFXObject::play(SFXFlagDrop);
! }
}
void SoccerGameType::scoreGoal(StringTableEntry playerName, U32 goalTeamIndex)
{
! S32 index = findClientIndexByName(playerName);
! S32 scoringTeam = -1;
! if(index != -1)
! scoringTeam = mClientList[index].teamId;
!
! if(scoringTeam == -1 || scoringTeam == goalTeamIndex)
! {
! // give all the other teams a point.
! for(S32 i = 0; i < mTeams.size(); i++)
! {
! if(i != goalTeamIndex)
! setTeamScore(i, mTeams[i].score + 1);
! }
! s2cSoccerScoreMessage(SoccerMsgScoreOwnGoal, playerName, goalTeamIndex);
! }
! else
! {
! mClientList[index].score += GoalScore;
! setTeamScore(scoringTeam, mTeams[scoringTeam].score + 1);
! s2cSoccerScoreMessage(SoccerMsgScoreGoal, playerName, goalTeamIndex);
! }
! }
!
! void SoccerGameType::gameOverManGameOver()
! {
! Parent::gameOverManGameOver();
! bool tied = false;
! S32 teamWinner = 0;
! U32 winningScore = mTeams[0].score;
! for(S32 i = 1; i < mTeams.size(); i++)
! {
! if(mTeams[i].score == winningScore)
! tied = true;
! else if(mTeams[i].score > winningScore)
! {
! teamWinner = i;
! winningScore = mTeams[i].score;
! tied = false;
! }
! }
! if(tied)
! s2cSoccerScoreMessage(SoccerMsgGameOverTie, StringTableEntry(), 0);
! else
! s2cSoccerScoreMessage(SoccerMsgGameOverTeamWin, StringTableEntry(), teamWinner);
}
Index: ZAP.vcproj
===================================================================
RCS file: /cvsroot/opentnl/tnl/zap/ZAP.vcproj,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** ZAP.vcproj 30 Apr 2004 20:27:41 -0000 1.10
--- ZAP.vcproj 2 May 2004 06:27:41 -0000 1.11
***************
*** 262,265 ****
--- 262,268 ----
</File>
<File
+ RelativePath=".\timer.h">
+ </File>
+ <File
RelativePath=".\UI.cpp">
</File>
Index: game.h
===================================================================
RCS file: /cvsroot/opentnl/tnl/zap/game.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** game.h 30 Apr 2004 20:27:41 -0000 1.10
--- game.h 2 May 2004 06:27:41 -0000 1.11
***************
*** 32,35 ****
--- 32,36 ----
#include "../tnl/tnlNetObject.h"
#include "gridDB.h"
+ #include "timer.h"
///
***************
*** 144,150 ****
--- 145,158 ----
class ServerGame : public Game
{
+ enum {
+ LevelSwitchTime = 5000,
+ };
+
U32 mPlayerCount;
U32 mMaxPlayers;
const char *mHostName;
+ Vector<StringTableEntry> mLevelList;
+ U32 mCurrentLevelIndex;
+ Timer mLevelSwitchTimer;
public:
U32 getPlayerCount() { return mPlayerCount; }
***************
*** 156,163 ****
--- 164,175 ----
ServerGame(const Address &theBindAddress, U32 maxPlayers, const char *hostName);
+ void setLevelList(const char *levelList);
void loadLevel(const char *fileName);
+ void cycleLevel();
+
void processLevelLoadLine(int argc, const char **argv);
bool isServer() { return true; }
void idle(U32 timeDelta);
+ void gameEnded();
};
Index: UIGame.cpp
===================================================================
RCS file: /cvsroot/opentnl/tnl/zap/UIGame.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** UIGame.cpp 30 Apr 2004 21:58:10 -0000 1.13
--- UIGame.cpp 2 May 2004 06:27:41 -0000 1.14
***************
*** 119,124 ****
}
- glTranslatef(400, 300, 0);
-
if(gClientGame)
gClientGame->render();
--- 119,122 ----
***************
*** 128,131 ****
--- 126,130 ----
{
glPushMatrix();
+ glTranslatef(400, 300, 0);
glTranslatef(mMousePoint.x, mMousePoint.y, 0);
Index: CTFGame.h
===================================================================
RCS file: /cvsroot/opentnl/tnl/zap/CTFGame.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** CTFGame.h 30 Apr 2004 20:27:41 -0000 1.6
--- CTFGame.h 2 May 2004 06:27:41 -0000 1.7
***************
*** 39,42 ****
--- 39,43 ----
class CTFGameType : public GameType
{
+ typedef GameType Parent;
enum Scores
{
***************
*** 55,58 ****
--- 56,60 ----
U32 checkFlagDrop(GameObject *theObject);
+ void gameOverManGameOver();
enum {
***************
*** 61,64 ****
--- 63,68 ----
CTFMsgTakeFlag,
CTFMsgDropFlag,
+ CTFMsgGameOverTeamWin,
+ CTFMsgGameOverTie,
};
Index: main.cpp
===================================================================
RCS file: /cvsroot/opentnl/tnl/zap/main.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** main.cpp 27 Apr 2004 21:43:04 -0000 1.13
--- main.cpp 2 May 2004 06:27:41 -0000 1.14
***************
*** 52,56 ****
const char *gMasterAddressString = "IP:master.opentnl.org:29005";
Address gMasterAddress;
! const char *gLoadLevel = "level1.txt";
void reshape(int nw, int nh)
--- 52,56 ----
const char *gMasterAddressString = "IP:master.opentnl.org:29005";
Address gMasterAddress;
! const char *gLevelList = "level1.txt level3.txt";
void reshape(int nw, int nh)
***************
*** 206,210 ****
{
gServerGame = new ServerGame(bindAddress, gMaxPlayers, gHostName);
! gServerGame->loadLevel(gLoadLevel);
if(!dedicated)
--- 206,210 ----
{
gServerGame = new ServerGame(bindAddress, gMaxPlayers, gHostName);
! gServerGame->setLevelList(gLevelList);
if(!dedicated)
***************
*** 314,321 ****
}
}
! else if(!stricmp(argv[i], "-level"))
{
if(hasAdditionalArg)
! gLoadLevel = argv[i+1];
}
else if(!stricmp(argv[i], "-hostname"))
--- 314,321 ----
}
}
! else if(!stricmp(argv[i], "-levels"))
{
if(hasAdditionalArg)
! gLevelList = argv[i+1];
}
else if(!stricmp(argv[i], "-hostname"))
Index: CTFGame.cpp
===================================================================
RCS file: /cvsroot/opentnl/tnl/zap/CTFGame.cpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** CTFGame.cpp 30 Apr 2004 21:58:10 -0000 1.18
--- CTFGame.cpp 2 May 2004 06:27:41 -0000 1.19
***************
*** 66,70 ****
void CTFGameType::renderInterfaceOverlay(bool scoreboardVisible)
{
! if(scoreboardVisible && mTeams.size() > 0)
{
U32 totalWidth = 780;
--- 66,70 ----
void CTFGameType::renderInterfaceOverlay(bool scoreboardVisible)
{
! if((mGameOver || scoreboardVisible) && mTeams.size() > 0)
{
U32 totalWidth = 780;
***************
*** 141,196 ****
for(S32 i = 0; i < mTeams.size(); i++)
{
! Point pos(750, 550 - i * 38);
renderFlag(pos + Point(-20, 18), mTeams[i].color);
glColor3f(1,1,1);
UserInterface::drawStringf(pos.x, pos.y, 32, "%d", mTeams[i].score);
}
-
- // Render current ship's energy, too.
- if(gClientGame && gClientGame->getConnectionToServer())
- {
- Ship *s = dynamic_cast<Ship*>(gClientGame->getConnectionToServer()->getControlObject());
- if(s)
- {
- static F32 curEnergy = 0.f;
-
- curEnergy = (curEnergy + s->mEnergy) * 0.5f;
-
- const F32 offset = 50;
-
- glColor3f(0.0, 0.0, 1);
- glBegin(GL_POLYGON);
- glVertex2f(15, 515 + offset);
- glVertex2f(15 + curEnergy, 515 + offset);
- glVertex2f(15 + curEnergy, 535 + offset);
- glVertex2f(15, 535 + offset);
- glEnd();
-
- // Show danger line.
- glColor3f(1, 0, 0);
- glBegin(GL_LINES);
- glVertex2f(15 + 5, 512 + offset);
- glVertex2f(15 + 5, 539 + offset);
- glEnd();
-
- // Show safety line.
- glColor3f(1, 1, 0);
- glBegin(GL_LINES);
- glVertex2f(15 + 15, 512 + offset);
- glVertex2f(15 + 15, 539 + offset);
- glEnd();
-
- // Show full marker
- glColor3f(0, 1, 0);
- glBegin(GL_LINE_STRIP);
- glVertex2f(15 + 90, 512 + offset);
- glVertex2f(15 + 101, 512 + offset);
- glVertex2f(15 + 101, 539 + offset);
- glVertex2f(15 + 90, 539 + offset);
- glEnd();
-
- }
- }
}
}
--- 141,155 ----
for(S32 i = 0; i < mTeams.size(); i++)
{
! Point pos(750, 535 - i * 38);
renderFlag(pos + Point(-20, 18), mTeams[i].color);
glColor3f(1,1,1);
UserInterface::drawStringf(pos.x, pos.y, 32, "%d", mTeams[i].score);
}
}
+ U32 timeLeft = mGameTimer.getCurrent();
+
+ U32 minsRemaining = timeLeft / (60000);
+ U32 secsRemaining = (timeLeft - (minsRemaining * 60000)) / 1000;
+ UserInterface::drawStringf(720, 577, 20, "%02d:%02d", minsRemaining, secsRemaining);
}
***************
*** 222,227 ****
if(mountedFlag)
{
! mTeams[cl.teamId].score++;
! s2cSetTeamScore(cl.teamId, mTeams[cl.teamId].score);
s2cCTFMessage(CTFMsgCaptureFlag, cl.name, mountedFlag->getTeamIndex());
--- 181,185 ----
if(mountedFlag)
{
! setTeamScore(cl.teamId, mTeams[cl.teamId].score + 1);
s2cCTFMessage(CTFMsgCaptureFlag, cl.name, mountedFlag->getTeamIndex());
***************
*** 306,310 ****
}
checkFlagDrop(clientObject);
! mClientList[clientIndex].respawnDelay = RespawnDelay;
}
--- 264,268 ----
}
checkFlagDrop(clientObject);
! mClientList[clientIndex].respawnTimer.reset(RespawnDelay);
}
***************
*** 314,317 ****
--- 272,298 ----
}
+ void CTFGameType::gameOverManGameOver()
+ {
+ Parent::gameOverManGameOver();
+ bool tied = false;
+ S32 teamWinner = 0;
+ U32 winningScore = mTeams[0].score;
+ for(S32 i = 1; i < mTeams.size(); i++)
+ {
+ if(mTeams[i].score == winningScore)
+ tied = true;
+ else if(mTeams[i].score > winningScore)
+ {
+ teamWinner = i;
+ winningScore = mTeams[i].score;
+ tied = false;
+ }
+ }
+ if(tied)
+ s2cCTFMessage(CTFMsgGameOverTie, StringTableEntry(), 0);
+ else
+ s2cCTFMessage(CTFMsgGameOverTeamWin, StringTableEntry(), teamWinner);
+ }
+
TNL_IMPLEMENT_NETOBJECT_RPC(CTFGameType, s2cCTFMessage, (U32 messageIndex, StringTableEntry clientName, U32 teamIndex),
NetClassGroupGameMask, RPCGuaranteedOrdered, RPCToGhost, 0)
***************
*** 323,326 ****
--- 304,309 ----
"%s took the %s flag!",
"%s dropped the %s flag!",
+ "%sTeam %s wins the game!",
+ "The game ended in a tie.",
};
***************
*** 331,334 ****
--- 314,319 ----
SFXFlagSnatch,
SFXFlagDrop,
+ SFXFlagCapture,
+ SFXFlagDrop,
};
Index: gameType.h
===================================================================
RCS file: /cvsroot/opentnl/tnl/zap/gameType.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** gameType.h 30 Apr 2004 20:27:41 -0000 1.6
--- gameType.h 2 May 2004 06:27:41 -0000 1.7
***************
*** 29,32 ****
--- 29,33 ----
#include "gameObject.h"
+ #include "timer.h"
namespace Zap
***************
*** 46,55 ****
S32 teamId;
U32 score;
! U32 respawnDelay;
bool wantsScoreboardUpdates;
SafePtr<GameConnection> clientConnection;
U32 ping;
! ClientRef() { ping = 0; score = 0; respawnDelay = 0; }
};
--- 47,56 ----
S32 teamId;
U32 score;
! Timer respawnTimer;
bool wantsScoreboardUpdates;
SafePtr<GameConnection> clientConnection;
U32 ping;
! ClientRef() { ping = 0; score = 0; }
};
***************
*** 67,74 ****
Vector<Team> mTeams;
U32 mThisClientName; ///< Set to the client name of this client (only on the ghost of the GameType)
! U32 mTimeUntilScoreboardUpdate;
enum {
MaxPing = 999,
};
--- 68,81 ----
Vector<Team> mTeams;
U32 mThisClientName; ///< Set to the client name of this client (only on the ghost of the GameType)
! Timer mScoreboardUpdateTimer;
! Timer mGameTimer;
! Timer mGameTimeUpdateTimer;
! U32 mTeamScoreLimit;
! bool mGameOver; // set to true when an end condition is met
enum {
MaxPing = 999,
+ DefaultGameTime = 20 * 60 * 1000,
+ DefaultTeamScoreLimit = 8,
};
***************
*** 94,99 ****
--- 101,110 ----
void onAddedToGame(Game *theGame);
void onGhostAvailable(GhostConnection *theConnection);
+ void processClient(U32 deltaT);
void processServer(U32 deltaT);
+ void setTeamScore(S32 teamIndex, S32 newScore);
+ virtual void gameOverManGameOver();
+
virtual void serverAddClient(GameConnection *theClient);
virtual void serverRemoveClient(GameConnection *theClient);
***************
*** 125,128 ****
--- 136,141 ----
TNL_DECLARE_RPC(s2cScoreboardUpdate, (const Vector<RangedU32<0, MaxPing> > &pingTimes, const Vector<Int<24> > &scores));
+ TNL_DECLARE_RPC(s2cSetGameOver, (bool gameOver));
+ TNL_DECLARE_RPC(s2cSetTimeRemaining, (U32 timeLeft));
TNL_DECLARE_RPC(c2sRequestScoreboardUpdates, (bool updates));
Index: game.cpp
===================================================================
RCS file: /cvsroot/opentnl/tnl/zap/game.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** game.cpp 30 Apr 2004 21:58:10 -0000 1.15
--- game.cpp 2 May 2004 06:27:41 -0000 1.16
***************
*** 174,177 ****
--- 174,223 ----
}
+ void ServerGame::setLevelList(const char *levelList)
+ {
+ for(;;)
+ {
+ const char *firstSpace = strchr(levelList, ' ');
+ StringTableEntry st;
+ if(firstSpace)
+ st.setn(levelList, firstSpace - levelList);
+ else
+ st.set(levelList);
+
+ if(st.getString()[0])
+ mLevelList.push_back(st);
+ if(!firstSpace)
+ break;
+ levelList = firstSpace + 1;
+ }
+ mCurrentLevelIndex = mLevelList.size() - 1;
+ cycleLevel();
+ }
+
+ void ServerGame::cycleLevel()
+ {
+ // delete any objects that may exist
+ while(mGameObjects.size())
+ delete mGameObjects[0];
+
+ for(GameConnection *walk = GameConnection::gClientList.mNext; walk != &GameConnection::gClientList; walk = walk->mNext)
+ walk->resetGhosting();
+
+ mCurrentLevelIndex++;
+ if(mCurrentLevelIndex >= mLevelList.size())
+ mCurrentLevelIndex = 0;
+ loadLevel(mLevelList[mCurrentLevelIndex].getString());
+ if(!getGameType())
+ {
+ GameType *g = new GameType;
+ g->addToGame(this);
+ }
+ for(GameConnection *walk = GameConnection::gClientList.mNext; walk != &GameConnection::gClientList; walk = walk->mNext)
+ {
+ addClient(walk);
+ walk->activateGhosting();
+ }
+ }
+
void ServerGame::loadLevel(const char *fileName)
{
***************
*** 227,230 ****
--- 273,284 ----
processDeleteList(timeDelta);
mNetInterface->processConnections();
+
+ if(mLevelSwitchTimer.update(timeDelta))
+ cycleLevel();
+ }
+
+ void ServerGame::gameEnded()
+ {
+ mLevelSwitchTimer.reset(LevelSwitchTime);
}
***************
*** 406,409 ****
--- 460,465 ----
glPushMatrix();
+ glTranslatef(400, 300, 0);
+
glScalef(visScale.x, visScale.y, 1);
glTranslatef(-offset.x, -offset.y, 0);
***************
*** 475,478 ****
--- 531,536 ----
glPushMatrix();
+ glTranslatef(400, 300, 0);
+
glScalef(400 / F32(PlayerHorizVisDistance), 300 / F32(PlayerVertVisDistance), 1);
***************
*** 495,498 ****
--- 553,602 ----
glPopMatrix();
+
+ // Render current ship's energy, too.
+ if(mConnectionToServer.isValid())
+ {
+ Ship *s = dynamic_cast<Ship*>(mConnectionToServer->getControlObject());
+ if(s)
+ {
+ static F32 curEnergy = 0.f;
+
+ curEnergy = (curEnergy + s->mEnergy) * 0.5f;
+
+ const F32 offset = 50;
+
+ glColor3f(0.0, 0.0, 1);
+ glBegin(GL_POLYGON);
+ glVertex2f(15, 515 + offset);
+ glVertex2f(15 + curEnergy, 515 + offset);
+ glVertex2f(15 + curEnergy, 535 + offset);
+ glVertex2f(15, 535 + offset);
+ glEnd();
+
+ // Show danger line.
+ glColor3f(1, 0, 0);
+ glBegin(GL_LINES);
+ glVertex2f(15 + 5, 512 + offset);
+ glVertex2f(15 + 5, 539 + offset);
+ glEnd();
+
+ // Show safety line.
+ glColor3f(1, 1, 0);
+ glBegin(GL_LINES);
+ glVertex2f(15 + 15, 512 + offset);
+ glVertex2f(15 + 15, 539 + offset);
+ glEnd();
+
+ // Show full marker
+ glColor3f(0, 1, 0);
+ glBegin(GL_LINE_STRIP);
+ glVertex2f(15 + 90, 512 + offset);
+ glVertex2f(15 + 101, 512 + offset);
+ glVertex2f(15 + 101, 539 + offset);
+ glVertex2f(15 + 90, 539 + offset);
+ glEnd();
+
+ }
+ }
}
Index: soccerGame.h
===================================================================
RCS file: /cvsroot/opentnl/tnl/zap/soccerGame.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** soccerGame.h 30 Apr 2004 20:27:42 -0000 1.1
--- soccerGame.h 2 May 2004 06:27:41 -0000 1.2
***************
*** 39,42 ****
--- 39,43 ----
class SoccerGameType : public GameType
{
+ typedef GameType Parent;
enum Scores
{
***************
*** 49,58 ****
bool objectCanDamageObject(GameObject *damager, GameObject *victim);
void scoreGoal(StringTableEntry playerName, U32 goalTeamIndex);
enum {
SoccerMsgScoreGoal,
};
! TNL_DECLARE_RPC(s2cSoccerScoreMessage, (StringTableEntry clientName, U32 teamIndex));
TNL_DECLARE_CLASS(SoccerGameType);
};
--- 50,63 ----
bool objectCanDamageObject(GameObject *damager, GameObject *victim);
void scoreGoal(StringTableEntry playerName, U32 goalTeamIndex);
+ void gameOverManGameOver();
enum {
SoccerMsgScoreGoal,
+ SoccerMsgScoreOwnGoal,
+ SoccerMsgGameOverTeamWin,
+ SoccerMsgGameOverTie,
};
! TNL_DECLARE_RPC(s2cSoccerScoreMessage, (U32 msgIndex, StringTableEntry clientName, U32 teamIndex));
TNL_DECLARE_CLASS(SoccerGameType);
};
|