Update of /cvsroot/opentnl/tnl/zap
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14626/zap
Modified Files:
CTFGame.cpp game.cpp game.h gameConnection.cpp
gameConnection.h gameObject.h gameType.cpp gameType.h main.cpp
ship.cpp ship.h soccerGame.cpp soccerGame.h
Log Message:
Added sorting to Vector template class
Updated Zap level2 to include a 30 second time limit
Updated GameType base class to perform as a simple deathmatch game type
Added correct player counts to server in server browser
Fixed commander map scoping to scope fewer objects seen by remote players
Soccer ball now slows down when it reaches the goal
Scoping now handled in the game type instead of Ship
Teams are randomized after each map
Index: main.cpp
===================================================================
RCS file: /cvsroot/opentnl/tnl/zap/main.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** main.cpp 3 May 2004 02:41:01 -0000 1.15
--- main.cpp 3 May 2004 22:06:16 -0000 1.16
***************
*** 51,54 ****
--- 51,55 ----
const char *gWindowTitle = "ZAP II - The Return";
U32 gMaxPlayers = 128;
+
const char *gMasterAddressString = "IP:master.opentnl.org:29005";
Address gMasterAddress;
Index: gameType.cpp
===================================================================
RCS file: /cvsroot/opentnl/tnl/zap/gameType.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** gameType.cpp 2 May 2004 06:27:41 -0000 1.16
--- gameType.cpp 3 May 2004 22:06:16 -0000 1.17
***************
*** 29,32 ****
--- 29,33 ----
#include "UIGame.h"
#include "gameNetInterface.h"
+ #include "glutInclude.h"
namespace Zap
***************
*** 90,93 ****
--- 91,179 ----
}
+ void GameType::renderInterfaceOverlay(bool scoreboardVisible)
+ {
+ if((mGameOver || scoreboardVisible) && mTeams.size() > 0)
+ {
+ U32 totalWidth = 780;
+ U32 teamWidth = totalWidth / mTeams.size();
+ U32 maxTeamPlayers = 0;
+ countTeamPlayers();
+
+ for(S32 i = 0; i < mTeams.size(); i++)
+ if(mTeams[i].numPlayers > maxTeamPlayers)
+ maxTeamPlayers = mTeams[i].numPlayers;
+
+ U32 teamAreaHeight = 40;
+ if(mTeams.size() < 2)
+ teamAreaHeight = 0;
+
+ U32 totalHeight = 580;
+ U32 maxHeight = (totalHeight - teamAreaHeight) / maxTeamPlayers;
+ if(maxHeight > 30)
+ maxHeight = 30;
+
+ totalHeight = teamAreaHeight + maxHeight * maxTeamPlayers;
+ U32 yt = (600 - totalHeight) / 2;
+ U32 yb = yt + totalHeight;
+
+ for(S32 i = 0; i < mTeams.size(); i++)
+ {
+ U32 xl = 10 + i * teamWidth;
+ U32 xr = xl + teamWidth - 2;
+
+ Color c = mTeams[i].color;
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+ glColor4f(c.r, c.g, c.b, 0.6);
+ glBegin(GL_POLYGON);
+ glVertex2f(xl, yt);
+ glVertex2f(xr, yt);
+ glVertex2f(xr, yb);
+ glVertex2f(xl, yb);
+ glEnd();
+
+ glDisable(GL_BLEND);
+ glBlendFunc(GL_ONE, GL_ZERO);
+
+ glColor3f(1,1,1);
+ if(teamAreaHeight)
+ {
+ glBegin(GL_LINES);
+ glVertex2f(xl, yt + teamAreaHeight);
+ glVertex2f(xr, yt + teamAreaHeight);
+ glEnd();
+
+ UserInterface::drawString(xl + 40, yt + 2, 30, mTeams[i].name.getString());
+
+ UserInterface::drawStringf(xr - 140, yt + 2, 30, "%d", mTeams[i].score);
+ }
+
+ U32 curRowY = yt + teamAreaHeight + 1;
+ U32 fontSize = maxHeight * 0.8f;
+ for(S32 j = 0; j < mClientList.size(); j++)
+ {
+ if(mClientList[j].teamId == i)
+ {
+ UserInterface::drawString(xl + 40, curRowY, fontSize, mClientList[j].name.getString());
+
+ static char buff[255] = "";
+ dSprintf(buff, sizeof(buff), "%d", mClientList[j].score);
+
+ UserInterface::drawString(xr - (120 + UserInterface::getStringWidth(fontSize, buff)), curRowY, fontSize, buff);
+ UserInterface::drawStringf(xr - 70, curRowY, fontSize, "%d", mClientList[j].ping);
+ curRowY += maxHeight;
+ }
+ }
+ }
+ }
+ glColor3f(1,1,1);
+ U32 timeLeft = mGameTimer.getCurrent();
+
+ U32 minsRemaining = timeLeft / (60000);
+ U32 secsRemaining = (timeLeft - (minsRemaining * 60000)) / 1000;
+ UserInterface::drawStringf(720, 577, 20, "%02d:%02d", minsRemaining, secsRemaining);
+ }
+
void GameType::gameOverManGameOver()
{
***************
*** 171,174 ****
--- 257,298 ----
}
+ void GameType::performProxyScopeQuery(GameObject *scopeObject, GameConnection *connection)
+ {
+ static Vector<GameObject *> fillVector;
+ fillVector.clear();
+
+ if(connection->mInCommanderMap && mTeams.size() > 1)
+ {
+ S32 teamId = mClientList[findClientIndexByConnection(connection)].teamId;
+
+ for(S32 i = 0; i < mClientList.size(); i++)
+ {
+ if(mClientList[i].teamId == teamId)
+ {
+ GameObject *co = mClientList[i].clientConnection->getControlObject();
+ if(!co)
+ continue;
+
+ Point pos = co->getActualPos();
+
+ Rect queryRect(pos, pos);
+ queryRect.expand(Point(Game::PlayerHorizScopeDistance, Game::PlayerVertScopeDistance));
+ findObjects(scopeObject == co ? AllObjectTypes : CommandMapVisType, fillVector, queryRect);
+ }
+ }
+ }
+ else
+ {
+ Point pos = scopeObject->getActualPos();
+
+ Rect queryRect(pos, pos);
+ queryRect.expand(Point(Game::PlayerHorizScopeDistance, Game::PlayerVertScopeDistance));
+ findObjects(AllObjectTypes, fillVector, queryRect);
+ }
+
+ for(S32 i = 0; i < fillVector.size(); i++)
+ connection->objectInScope(fillVector[i]);
+ }
+
void GameType::countTeamPlayers()
{
***************
*** 211,217 ****
void GameType::controlObjectForClientKilled(GameConnection *theClient, GameObject *clientObject, GameObject *killerObject)
{
S32 clientIndex = findClientIndexByConnection(theClient);
! if(clientIndex != -1)
! mClientList[clientIndex].respawnTimer.reset(RespawnDelay);
}
--- 335,353 ----
void GameType::controlObjectForClientKilled(GameConnection *theClient, GameObject *clientObject, GameObject *killerObject)
{
+ GameConnection *killer = killerObject ? killerObject->getControllingClient() : NULL;
+ S32 killerIndex = findClientIndexByConnection(killer);
S32 clientIndex = findClientIndexByConnection(theClient);
!
! if(killerIndex != -1)
! {
! // Punish team killers slightly
! if(mTeams.size() > 1 && mClientList[killerIndex].teamId == mClientList[clientIndex].teamId)
! mClientList[killerIndex].score -= 1;
! else
! mClientList[killerIndex].score += 1;
!
! s2cKillMessage(mClientList[clientIndex].name, mClientList[killerIndex].name);
! }
! mClientList[clientIndex].respawnTimer.reset(RespawnDelay);
}
Index: soccerGame.cpp
===================================================================
RCS file: /cvsroot/opentnl/tnl/zap/soccerGame.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** soccerGame.cpp 2 May 2004 06:27:41 -0000 1.2
--- soccerGame.cpp 3 May 2004 22:06:16 -0000 1.3
***************
*** 125,128 ****
--- 125,129 ----
}
}
+ glColor3f(1,1,1);
U32 timeLeft = mGameTimer.getCurrent();
***************
*** 283,289 ****
void SoccerBallItem::processServer(U32 deltaT)
{
- Parent::processServer(deltaT);
if(sendHomeTime)
{
if(sendHomeTime > deltaT)
sendHomeTime -= deltaT;
--- 284,294 ----
void SoccerBallItem::processServer(U32 deltaT)
{
if(sendHomeTime)
{
+ F32 accelFraction = 1 - (0.98 * deltaT / 1000.0f);
+
+ mMoveState[ActualState].vel *= accelFraction;
+ mMoveState[RenderState].vel *= accelFraction;
+
if(sendHomeTime > deltaT)
sendHomeTime -= deltaT;
***************
*** 294,297 ****
--- 299,303 ----
}
}
+ Parent::processServer(deltaT);
}
Index: gameConnection.cpp
===================================================================
RCS file: /cvsroot/opentnl/tnl/zap/gameConnection.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** gameConnection.cpp 26 Apr 2004 23:35:00 -0000 1.9
--- gameConnection.cpp 3 May 2004 22:06:16 -0000 1.10
***************
*** 207,210 ****
--- 207,217 ----
if(!Parent::readConnectRequest(stream, errorString))
return false;
+
+ if(gServerGame->isFull())
+ {
+ *errorString = "Server Full.";
+ return false;
+ }
+
char buf[256];
***************
*** 266,269 ****
--- 273,281 ----
}
+ void GameConnection::onConnectionRejected(const char *reason)
+ {
+ gMainMenuUserInterface.activate();
+ }
+
void GameConnection::onDisconnect(const char *reason)
{
Index: game.h
===================================================================
RCS file: /cvsroot/opentnl/tnl/zap/game.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** game.h 2 May 2004 06:27:41 -0000 1.11
--- game.h 3 May 2004 22:06:16 -0000 1.12
***************
*** 159,162 ****
--- 159,163 ----
U32 getMaxPlayers() { return mMaxPlayers; }
const char *getHostName() { return mHostName; }
+ bool isFull() { return mPlayerCount == mMaxPlayers; }
void addClient(GameConnection *theConnection);
Index: gameConnection.h
===================================================================
RCS file: /cvsroot/opentnl/tnl/zap/gameConnection.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** gameConnection.h 30 Apr 2004 20:27:41 -0000 1.6
--- gameConnection.h 3 May 2004 22:06:16 -0000 1.7
***************
*** 217,220 ****
--- 217,221 ----
void onConnectionEstablished(bool isInitiator);
+ void onConnectionRejected(const char *reason);
void onDisconnect(const char *reason);
void onTimedOut();
Index: gameObject.h
===================================================================
RCS file: /cvsroot/opentnl/tnl/zap/gameObject.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** gameObject.h 30 Apr 2004 20:27:41 -0000 1.4
--- gameObject.h 3 May 2004 22:06:16 -0000 1.5
***************
*** 98,101 ****
--- 98,102 ----
F32 getUpdatePriority(NetObject *scopeObject, U32 updateMask, S32 updateSkips);
+ virtual S32 getRenderSortValue() { return 0; }
virtual void render();
Index: ship.h
===================================================================
RCS file: /cvsroot/opentnl/tnl/zap/ship.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** ship.h 30 Apr 2004 21:58:10 -0000 1.12
--- ship.h 3 May 2004 22:06:16 -0000 1.13
***************
*** 38,45 ****
class Ship : public MoveObject
{
- private:
- // This is called when we're doing team queries...
- void performInnerScopeQuery(GhostConnection *connection);
-
public:
enum {
--- 38,41 ----
Index: CTFGame.cpp
===================================================================
RCS file: /cvsroot/opentnl/tnl/zap/CTFGame.cpp,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** CTFGame.cpp 2 May 2004 06:27:41 -0000 1.19
--- CTFGame.cpp 3 May 2004 22:06:16 -0000 1.20
***************
*** 128,132 ****
static char buff[255] = "";
! sprintf(buff, "%d", mClientList[j].score);
UserInterface::drawString(xr - (120 + UserInterface::getStringWidth(fontSize, buff)), curRowY, fontSize, buff);
--- 128,132 ----
static char buff[255] = "";
! dSprintf(buff, sizeof(buff), "%d", mClientList[j].score);
UserInterface::drawString(xr - (120 + UserInterface::getStringWidth(fontSize, buff)), curRowY, fontSize, buff);
***************
*** 147,150 ****
--- 147,151 ----
}
}
+ glColor3f(1,1,1);
U32 timeLeft = mGameTimer.getCurrent();
Index: gameType.h
===================================================================
RCS file: /cvsroot/opentnl/tnl/zap/gameType.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** gameType.h 2 May 2004 06:27:41 -0000 1.7
--- gameType.h 3 May 2004 22:06:16 -0000 1.8
***************
*** 46,50 ****
StringTableEntry name; /// Name of client - guaranteed to be unique of current clients
S32 teamId;
! U32 score;
Timer respawnTimer;
--- 46,50 ----
StringTableEntry name; /// Name of client - guaranteed to be unique of current clients
S32 teamId;
! S32 score;
Timer respawnTimer;
***************
*** 119,125 ****
virtual void processClientGameMenuOption(U32 index);
! virtual void renderInterfaceOverlay(bool scoreboardVisible) {};
virtual void updateClientScoreboard(S32 clientIndex);
TNL_DECLARE_RPC(s2cAddTeam, (StringTableEntry teamName, F32 r, F32 g, F32 b));
TNL_DECLARE_RPC(s2cSetTeamScore, (U32 teamIndex, U32 score));
--- 119,127 ----
virtual void processClientGameMenuOption(U32 index);
! virtual void renderInterfaceOverlay(bool scoreboardVisible);
virtual void updateClientScoreboard(S32 clientIndex);
+ virtual void performProxyScopeQuery(GameObject *scopeObject, GameConnection *connection);
+
TNL_DECLARE_RPC(s2cAddTeam, (StringTableEntry teamName, F32 r, F32 g, F32 b));
TNL_DECLARE_RPC(s2cSetTeamScore, (U32 teamIndex, U32 score));
Index: game.cpp
===================================================================
RCS file: /cvsroot/opentnl/tnl/zap/game.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** game.cpp 2 May 2004 06:27:41 -0000 1.16
--- game.cpp 3 May 2004 22:06:16 -0000 1.17
***************
*** 197,200 ****
--- 197,203 ----
void ServerGame::cycleLevel()
{
+ // delete any objects on the delete list:
+ processDeleteList(0xFFFFFFFF);
+
// delete any objects that may exist
while(mGameObjects.size())
***************
*** 213,220 ****
g->addToGame(this);
}
for(GameConnection *walk = GameConnection::gClientList.mNext; walk != &GameConnection::gClientList; walk = walk->mNext)
{
! addClient(walk);
! walk->activateGhosting();
}
}
--- 216,234 ----
g->addToGame(this);
}
+ Vector<GameConnection *> connectionList;
+
for(GameConnection *walk = GameConnection::gClientList.mNext; walk != &GameConnection::gClientList; walk = walk->mNext)
+ connectionList.push_back(walk);
+
+ // now add the connections to the game type, in a random order
+ while(connectionList.size())
{
! U32 index = Random::readI() % connectionList.size();
! GameConnection *gc = connectionList[index];
! connectionList.erase(index);
!
! if(mGameType.isValid())
! mGameType->serverAddClient(gc);
! gc->activateGhosting();
}
}
***************
*** 255,258 ****
--- 269,273 ----
if(mGameType.isValid())
mGameType->serverAddClient(theConnection);
+ mPlayerCount++;
}
***************
*** 261,264 ****
--- 276,280 ----
if(mGameType.isValid())
mGameType->serverRemoveClient(theConnection);
+ mPlayerCount--;
}
***************
*** 431,435 ****
}
!
void ClientGame::renderCommander()
--- 447,454 ----
}
! S32 QSORT_CALLBACK renderSortCompare(GameObject **a, GameObject **b)
! {
! return (*a)->getRenderSortValue() - (*b)->getRenderSortValue();
! }
void ClientGame::renderCommander()
***************
*** 515,524 ****
}
for(S32 i = 0; i < renderObjects.size(); i++)
- {
renderObjects[i]->render();
- }
-
- //SparkManager::render();
glPopMatrix();
--- 534,541 ----
}
+ renderObjects.sort(renderSortCompare);
+
for(S32 i = 0; i < renderObjects.size(); i++)
renderObjects[i]->render();
glPopMatrix();
***************
*** 546,549 ****
--- 563,568 ----
mDatabase.findObjects(AllObjectTypes, renderObjects, extentRect);
+ renderObjects.sort(renderSortCompare);
+
for(S32 i = 0; i < renderObjects.size(); i++)
renderObjects[i]->render();
Index: soccerGame.h
===================================================================
RCS file: /cvsroot/opentnl/tnl/zap/soccerGame.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** soccerGame.h 2 May 2004 06:27:41 -0000 1.2
--- soccerGame.h 3 May 2004 22:06:16 -0000 1.3
***************
*** 95,98 ****
--- 95,99 ----
U32 getTeamIndex() { return teamIndex; }
void render();
+ S32 getRenderSortValue() { return -1; }
void processArguments(S32 argc, const char **argv);
void onAddedToGame(Game *theGame);
Index: ship.cpp
===================================================================
RCS file: /cvsroot/opentnl/tnl/zap/ship.cpp,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** ship.cpp 3 May 2004 02:41:01 -0000 1.22
--- ship.cpp 3 May 2004 22:06:16 -0000 1.23
***************
*** 526,568 ****
static Vector<GameObject *> fillVector;
- void Ship::performInnerScopeQuery(GhostConnection *connection)
- {
- Rect queryRect(mMoveState[ActualState].pos, mMoveState[ActualState].pos);
- queryRect.expand(Point(Game::PlayerHorizScopeDistance, Game::PlayerVertScopeDistance));
-
-
- fillVector.clear();
- findObjects(AllObjectTypes, fillVector, queryRect);
-
- for(S32 i = 0; i < fillVector.size(); i++)
- connection->objectInScope(fillVector[i]);
- }
-
void Ship::performScopeQuery(GhostConnection *connection)
{
! GameConnection *g = dynamic_cast<GameConnection*>(connection);
!
! if(g && g->mInCommanderMap)
! {
! GameType *gt = gServerGame->getGameType();
!
! S32 teamId = gt->mClientList[gt->findClientIndexByConnection(g)].teamId;
!
! // Scope for all ships on our team.
! for(S32 i=0; i<gt->mClientList.size(); i++)
! {
! if(gt->mClientList[i].teamId == teamId)
! {
! Ship *co = dynamic_cast<Ship*>(gt->mClientList[i].clientConnection->getControlObject());
! if(co)
! co->performInnerScopeQuery(connection);
! }
! }
! }
! else
! {
! // Just scope for the current ship...
! performInnerScopeQuery(connection);
! }
}
--- 526,533 ----
static Vector<GameObject *> fillVector;
void Ship::performScopeQuery(GhostConnection *connection)
{
! GameType *gt = gServerGame->getGameType();
! gt->performProxyScopeQuery(this, (GameConnection *) connection);
}
|