[Opentnl-cvs] tnl/zap soccerGame.cpp,NONE,1.1 soccerGame.h,NONE,1.1 CTFGame.cpp,1.16,1.17 CTFGame.h,
Brought to you by:
mark_frohnmayer,
s_alanet
From: Mark F. <mar...@us...> - 2004-04-30 20:27:53
|
Update of /cvsroot/opentnl/tnl/zap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31349/zap Modified Files: CTFGame.cpp CTFGame.h ZAP.vcproj barrier.cpp game.cpp game.h gameConnection.h gameObject.h gameType.cpp gameType.h item.cpp moveObject.cpp point.h ship.cpp ship.h teleporter.cpp Added Files: soccerGame.cpp soccerGame.h Log Message: Added Soccer game type Index: moveObject.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/moveObject.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** moveObject.cpp 22 Apr 2004 05:22:32 -0000 1.5 --- moveObject.cpp 30 Apr 2004 20:27:41 -0000 1.6 *************** *** 226,229 **** --- 226,234 ---- if((cp - mMoveState[stateIndex].pos).dot(mMoveState[stateIndex].vel) > velocityEpsilon) { + bool collide1 = collide(fillVector[i]); + bool collide2 = fillVector[i]->collide(this); + + if(!(collide1 && collide2)) + continue; collisionPoint = cp; delta *= collisionFraction; *************** *** 255,259 **** if(p.len() <= R) { ! if(!(collide(otherShip) && otherShip->collide(this))) continue; --- 260,267 ---- if(p.len() <= R) { ! bool collide1 = collide(otherShip); ! bool collide2 = otherShip->collide(this); ! ! if(!(collide1 && collide2)) continue; *************** *** 270,274 **** if(FindLowestRootInInterval(a, b, c, collisionTime, t)) { ! if(!(collide(otherShip) && otherShip->collide(this))) continue; --- 278,285 ---- if(FindLowestRootInInterval(a, b, c, collisionTime, t)) { ! bool collide1 = collide(otherShip); ! bool collide2 = otherShip->collide(this); ! ! if(!(collide1 && collide2)) continue; Index: gameType.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/gameType.cpp,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** gameType.cpp 28 Apr 2004 00:30:53 -0000 1.14 --- gameType.cpp 30 Apr 2004 20:27:41 -0000 1.15 *************** *** 349,354 **** --- 349,394 ---- } + Vector<RangedU32<0, GameType::MaxPing> > GameType::mPingTimes; ///< Static vector used for constructing update RPCs + Vector<Int<24> > GameType::mScores; + void GameType::updateClientScoreboard(S32 clientIndex) { + mPingTimes.clear(); + mScores.clear(); + + for(S32 i = 0; i < mClientList.size(); i++) + { + if(mClientList[i].ping < MaxPing) + mPingTimes.push_back(mClientList[i].ping); + else + mPingTimes.push_back(MaxPing); + mScores.push_back(mClientList[i].score); + } + + NetObject::setRPCDestConnection(mClientList[clientIndex].clientConnection); + s2cScoreboardUpdate(mPingTimes, mScores); + NetObject::setRPCDestConnection(NULL); + } + + TNL_DECLARE_RPC_MEM_ENUM(GameType, MaxPing); + + TNL_IMPLEMENT_NETOBJECT_RPC(GameType, s2cScoreboardUpdate, (const Vector<RangedU32<0, GameType::MaxPing> > &pingTimes, const Vector<Int<24> > &scores), + NetClassGroupGameMask, RPCGuaranteedOrdered, RPCToGhost, 0) + { + for(S32 i = 0; i < mClientList.size(); i++) + { + if(i >= pingTimes.size()) + break; + + mClientList[i].ping = pingTimes[i]; + mClientList[i].score = scores[i]; + } + } + + TNL_IMPLEMENT_NETOBJECT_RPC(GameType, s2cKillMessage, (StringTableEntry victim, StringTableEntry killer), + NetClassGroupGameMask, RPCGuaranteedOrdered, RPCToGhost, 0) + { + gGameUserInterface.displayMessage(Color(1.0f, 1.0f, 0.8f), + "%s zapped %s", killer.getString(), victim.getString()); } --- NEW FILE: soccerGame.cpp --- //----------------------------------------------------------------------------------- // // 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 // //------------------------------------------------------------------------------------ #include "soccerGame.h" #include "glutInclude.h" #include "UIGame.h" #include "sfx.h" #include "gameNetInterface.h" #include "ship.h" namespace Zap { class Ship; class SoccerBallItem; extern void renderFlag(Point pos, Color c); TNL_IMPLEMENT_NETOBJECT(SoccerGameType); void SoccerGameType::renderInterfaceOverlay(bool scoreboardVisible) { if(scoreboardVisible) { 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 totalHeight = 580; U32 maxHeight = (totalHeight - 40) / maxTeamPlayers; if(maxHeight > 30) maxHeight = 30; totalHeight = 40 + 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); renderFlag(Point(xl + 20, yt + 18), c); renderFlag(Point(xr - 20, yt + 18), c); glColor3f(1,1,1); glBegin(GL_LINES); glVertex2f(xl, yt + 40); glVertex2f(xr, yt + 40); 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 + 41; 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; } } } } else { 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); } } } void SoccerGameType::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(mClientList[killerIndex].teamId == mClientList[clientIndex].teamId) mClientList[killerIndex].score -= KillScore/4; else mClientList[killerIndex].score += KillScore; s2cKillMessage(mClientList[clientIndex].name, mClientList[killerIndex].name); } mClientList[clientIndex].respawnDelay = RespawnDelay; } bool SoccerGameType::objectCanDamageObject(GameObject *damager, GameObject *victim) { GameConnection *c1 = (damager ? damager->getControllingClient() : NULL); GameConnection *c2 = (victim ? victim->getControllingClient() : NULL); if(!c1 || !c2) return true; return mClientList[findClientIndexByConnection(c1)].teamId != mClientList[findClientIndexByConnection(c2)].teamId; } 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); } TNL_IMPLEMENT_NETOBJECT(SoccerBallItem); SoccerBallItem::SoccerBallItem(Point pos) : Item(pos, true, 30, 4) { mObjectTypeMask |= CommandMapVisType; mNetFlags.set(Ghostable); initialPos = pos; sendHomeTime = 0; } void SoccerBallItem::processArguments(S32 argc, const char **argv) { Parent::processArguments(argc, argv); initialPos = mMoveState[ActualState].pos; } void SoccerBallItem::renderItem(Point pos) { glPushMatrix(); glTranslatef(pos.x, pos.y, 0); glColor3f(1, 1, 1); glBegin(GL_LINE_LOOP); for(F32 theta = 0; theta < 2 * 3.1415; theta += 0.2) glVertex2f(cos(theta) * mRadius, sin(theta) * mRadius); glEnd(); glPopMatrix(); } void SoccerBallItem::processServer(U32 deltaT) { Parent::processServer(deltaT); if(sendHomeTime) { if(sendHomeTime > deltaT) sendHomeTime -= deltaT; else { sendHomeTime = 0; sendHome(); } } } void SoccerBallItem::damageObject(DamageInfo *theInfo) { // compute impulse direction Point dv = theInfo->impulseVector - mMoveState[ActualState].vel; Point iv = mMoveState[ActualState].pos - theInfo->collisionPoint; iv.normalize(); mMoveState[ActualState].vel += iv * dv.dot(iv) * 0.3; if(theInfo->damagingObject && (theInfo->damagingObject->getObjectTypeMask() & ShipType)) { lastPlayerTouch = ((Ship *) theInfo->damagingObject)->mPlayerName; } } void SoccerBallItem::sendHome() { mMoveState[ActualState].vel = mMoveState[RenderState].vel = Point(); mMoveState[ActualState].pos = mMoveState[RenderState].pos = initialPos; setMaskBits(PositionMask); updateExtent(); } bool SoccerBallItem::collide(GameObject *hitObject) { if(isGhost()) return true; if(hitObject->getObjectTypeMask() & ShipType) { lastPlayerTouch = ((Ship *) hitObject)->mPlayerName; } else { SoccerGoalObject *goal = dynamic_cast<SoccerGoalObject *>(hitObject); if(goal && sendHomeTime == 0) { SoccerGameType *g = (SoccerGameType *) getGame()->getGameType(); g->scoreGoal(lastPlayerTouch, goal->getTeamIndex()); sendHomeTime = 1500; } } return true; } TNL_IMPLEMENT_NETOBJECT(SoccerGoalObject); SoccerGoalObject::SoccerGoalObject() { teamIndex = 0; mObjectTypeMask |= CommandMapVisType; mNetFlags.set(Ghostable); } void SoccerGoalObject::onAddedToGame(Game *theGame) { if(!isGhost()) { setInterface(theGame->getNetInterface()); setScopeAlways(); } } void SoccerGoalObject::render() { F32 alpha = 0.5; Color theColor = getGame()->getGameType()->mTeams[teamIndex].color; glColor3f(theColor.r * alpha, theColor.g * alpha, theColor.b * alpha); glBegin(GL_POLYGON); for(S32 i = 0; i < mPolyBounds.size(); i++) glVertex2f(mPolyBounds[i].x, mPolyBounds[i].y); glEnd(); } bool SoccerGoalObject::getCollisionPoly(Vector<Point> &polyPoints) { for(S32 i = 0; i < mPolyBounds.size(); i++) polyPoints.push_back(mPolyBounds[i]); return true; } void SoccerGoalObject::processArguments(S32 argc, const char **argv) { if(argc < 7) return; teamIndex = atoi(argv[0]); for(S32 i = 1; i < argc; i += 2) { Point p; p.x = atof(argv[i]) * getGame()->getGridSize(); p.y = atof(argv[i+1]) * getGame()->getGridSize(); mPolyBounds.push_back(p); } computeExtent(); } void SoccerGoalObject::computeExtent() { Rect extent(mPolyBounds[0], mPolyBounds[0]); for(S32 i = 1; i < mPolyBounds.size(); i++) extent.unionPoint(mPolyBounds[i]); setExtent(extent); } bool SoccerGoalObject::collide(GameObject *hitObject) { return false; } U32 SoccerGoalObject::packUpdate(GhostConnection *connection, U32 updateMask, BitStream *stream) { stream->write(teamIndex); stream->writeRangedU32(mPolyBounds.size(), 0, MaxPoints); for(S32 i = 0; i < mPolyBounds.size(); i++) { stream->write(mPolyBounds[i].x); stream->write(mPolyBounds[i].y); } return 0; } void SoccerGoalObject::unpackUpdate(GhostConnection *connection, BitStream *stream) { stream->read(&teamIndex); S32 size = stream->readRangedU32(0, MaxPoints); for(S32 i = 0; i < size; i++) { Point p; stream->read(&p.x); stream->read(&p.y); mPolyBounds.push_back(p); } if(size) computeExtent(); } }; Index: teleporter.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/teleporter.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** teleporter.cpp 20 Apr 2004 19:25:49 -0000 1.3 --- teleporter.cpp 30 Apr 2004 20:27:42 -0000 1.4 *************** *** 49,52 **** --- 49,53 ---- r.expand(Point(TeleporterRadius, TeleporterRadius)); setExtent(r); + mObjectTypeMask |= CommandMapVisType; } Index: game.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/game.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** game.h 27 Apr 2004 21:43:04 -0000 1.9 --- game.h 30 Apr 2004 20:27:41 -0000 1.10 *************** *** 104,117 **** SafePtr<MasterServerConnection> mConnectionToMaster; SafePtr<GameType> mGameType; - - enum { - NumStars = 2048, - }; - Point mStars[NumStars]; - public: enum { - WorldSize = 4096, DefaultGridSize = 256, PlayerHorizVisDistance = 600, --- 104,110 ---- *************** *** 171,174 **** --- 164,172 ---- class ClientGame : public Game { + enum { + NumStars = 256, + }; + Point mStars[NumStars]; + SafePtr<GameConnection> mConnectionToServer; // If this is a client game, this is the connection to the server bool mInCommanderMap; *************** *** 184,187 **** --- 182,186 ---- void setConnectionToServer(GameConnection *connection); + void drawStars(F32 alphaFrac, Point cameraPos, Point visibleExtent); GameConnection *getConnectionToServer(); void render(); *************** *** 201,205 **** extern void endGame(); ! #define ZAP_GAME_STRING "ZAP 1.1.2" }; --- 200,204 ---- extern void endGame(); ! #define ZAP_GAME_STRING "ZAP 1.1.3" }; Index: game.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/game.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** game.cpp 27 Apr 2004 23:27:51 -0000 1.13 --- game.cpp 30 Apr 2004 20:27:41 -0000 1.14 *************** *** 62,72 **** mLastIdleTime = Platform::getRealMilliseconds(); - // create random stars - for(U32 i = 0; i < NumStars; i++) - { - mStars[i].x = Random::readF() * WorldSize; - mStars[i].y = Random::readF() * WorldSize; - } - mNetInterface = new GameNetInterface(theBindAddress, this); } --- 62,65 ---- *************** *** 244,247 **** --- 237,246 ---- mInCommanderMap = false; mCommanderZoomDelta = 0; + // create random stars + for(U32 i = 0; i < NumStars; i++) + { + mStars[i].x = Random::readF(); + mStars[i].y = Random::readF(); + } } *************** *** 338,341 **** --- 337,382 ---- } + void ClientGame::drawStars(F32 alphaFrac, Point cameraPos, Point visibleExtent) + { + F32 starChunkSize = 1024; + + Point upperLeft = cameraPos - visibleExtent * 0.5f; + Point lowerRight = cameraPos + visibleExtent * 0.5f; + + upperLeft *= 1 / starChunkSize; + lowerRight *= 1 / starChunkSize; + + upperLeft.x = floor(upperLeft.x); + upperLeft.y = floor(upperLeft.y); + + lowerRight.x = floor(lowerRight.x) + 0.5; + lowerRight.y = floor(lowerRight.y) + 0.5; + + // render the stars + glPointSize( 1.0f ); + glColor3f(0.8 * alphaFrac, 0.8 * alphaFrac, 1.0 * alphaFrac); + + glPointSize(1); + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(2, GL_FLOAT, sizeof(Point), &mStars[0]); + + for(F32 xPage = upperLeft.x; xPage < lowerRight.x; xPage++) + { + for(F32 yPage = upperLeft.y; yPage < lowerRight.y; yPage++) + { + glPushMatrix(); + glScalef(starChunkSize, starChunkSize, 1); + glTranslatef(xPage, yPage, 0); + //glTranslatef(-xPage * starChunkSize, -yPage * starChunkSize, 0); + glDrawArrays(GL_POINTS, 0, NumStars); + glPopMatrix(); + } + } + + glDisableClientState(GL_VERTEX_ARRAY); + } + + + void ClientGame::renderCommander() { *************** *** 368,386 **** glTranslatef(-offset.x, -offset.y, 0); ! //glScalef(UserInterface::canvasHeight / worldExtents.x, UserInterface::canvasHeight / worldExtents.y, 0); ! //glTranslatef(-worldCenter.x, -worldCenter.y, 0); ! ! // render the stars, but only 1/8th of them so the screen isn't overcrowded. ! glPointSize( 1.0f ); ! glColor3f(0.8, 0.8, 1.0); ! ! // glEnableClientState(GL_VERTEX_ARRAY); ! // glVertexPointer(2, GL_FLOAT, 8*sizeof(Point), &mStars[0]); ! // glDrawArrays(GL_POINTS, 0, NumStars/8); ! // glDisableClientState(GL_VERTEX_ARRAY); // render the objects Vector<GameObject *> renderObjects; ! mDatabase.findObjects(BarrierType | ShipType | ItemType, renderObjects, worldBounds); // Deal with rendering sensor volumes --- 409,418 ---- glTranslatef(-offset.x, -offset.y, 0); ! if(zoomFrac < 0.95) ! drawStars(1 - zoomFrac, offset, modVisSize); // render the objects Vector<GameObject *> renderObjects; ! mDatabase.findObjects( CommandMapVisType, renderObjects, worldBounds); // Deal with rendering sensor volumes *************** *** 447,458 **** glTranslatef(-position.x, -position.y, 0); ! // render the stars ! glPointSize( 1.0f ); ! glColor3f(0.8, 0.8, 1.0); ! ! glEnableClientState(GL_VERTEX_ARRAY); ! glVertexPointer(2, GL_FLOAT, sizeof(Point), &mStars[0]); ! glDrawArrays(GL_POINTS, 0, NumStars); ! glDisableClientState(GL_VERTEX_ARRAY); // render the objects --- 479,483 ---- glTranslatef(-position.x, -position.y, 0); ! drawStars(1.0, position, Point(PlayerHorizVisDistance * 2, PlayerVertVisDistance * 2)); // render the objects Index: CTFGame.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/CTFGame.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** CTFGame.h 23 Apr 2004 01:49:46 -0000 1.5 --- CTFGame.h 30 Apr 2004 20:27:41 -0000 1.6 *************** *** 50,54 **** void shipTouchFlag(Ship *theShip, CTFFlagItem *theFlag); void renderInterfaceOverlay(bool scoreboardVisible); - void updateClientScoreboard(S32 clientIndex); void controlObjectForClientKilled(GameConnection *theClient, GameObject *clientObject, GameObject *killerObject); void controlObjectForClientRemoved(GameConnection *theClient, GameObject *clientObject); --- 50,53 ---- *************** *** 58,68 **** enum { - MaxPing = 999, - }; - - static Vector<RangedU32<0, MaxPing> > mPingTimes; ///< Static vector used for constructing update RPCs - static Vector<Int<24> > mScores; - - enum { CTFMsgReturnFlag, CTFMsgCaptureFlag, --- 57,60 ---- *************** *** 72,77 **** TNL_DECLARE_RPC(s2cCTFMessage, (U32 messageIndex, StringTableEntry clientName, U32 teamIndex)); - TNL_DECLARE_RPC(s2cKillMessage, (StringTableEntry victim, StringTableEntry killer)); - TNL_DECLARE_RPC(s2cScoreboardUpdate, (const Vector<RangedU32<0, MaxPing> > &pingTimes, const Vector<Int<24> > &scores)); TNL_DECLARE_CLASS(CTFGameType); }; --- 64,67 ---- Index: barrier.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/barrier.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** barrier.cpp 27 Apr 2004 20:41:53 -0000 1.5 --- barrier.cpp 30 Apr 2004 20:27:41 -0000 1.6 *************** *** 111,115 **** Barrier::Barrier(Point st, Point e) { ! mObjectTypeMask = BarrierType; mNetFlags.set(Ghostable); start = st; --- 111,115 ---- Barrier::Barrier(Point st, Point e) { ! mObjectTypeMask = BarrierType | CommandMapVisType; mNetFlags.set(Ghostable); start = st; Index: gameConnection.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/gameConnection.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** gameConnection.h 26 Apr 2004 07:36:06 -0000 1.5 --- gameConnection.h 30 Apr 2004 20:27:41 -0000 1.6 *************** *** 88,91 **** --- 88,93 ---- float angle; bool fire; + bool boost; + bool shield; U32 time; *************** *** 94,98 **** }; ! Move() { left = right = up = down = angle = 0; fire = false; time = 32; } bool isEqualMove(Move *prev) --- 96,100 ---- }; ! Move() { left = right = up = down = angle = 0; boost = shield = fire = false; time = 32; } bool isEqualMove(Move *prev) *************** *** 103,107 **** prev->down == down && prev->angle == angle && ! prev->fire == fire; } --- 105,111 ---- prev->down == down && prev->angle == angle && ! prev->fire == fire && ! prev->boost == boost && ! prev->shield == shield; } *************** *** 118,121 **** --- 122,127 ---- stream->writeInt(writeAngle, 12); stream->writeFlag(fire); + stream->writeFlag(boost); + stream->writeFlag(shield); } stream->writeRangedU32(time, 0, MaxMoveTime); *************** *** 131,134 **** --- 137,142 ---- angle = unitToRadians(stream->readInt(12) / F32(0xFFF)); fire = stream->readFlag(); + boost = stream->readFlag(); + shield = stream->readFlag(); } time = stream->readRangedU32(0, MaxMoveTime); Index: gameObject.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/gameObject.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** gameObject.h 27 Apr 2004 20:41:53 -0000 1.3 --- gameObject.h 30 Apr 2004 20:27:41 -0000 1.4 *************** *** 48,51 **** --- 48,52 ---- ItemType = 1 << 5, + CommandMapVisType = 1 << 31, AllObjectTypes = 0xFFFFFFFF, }; Index: ship.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/ship.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** ship.h 30 Apr 2004 08:33:20 -0000 1.10 --- ship.h 30 Apr 2004 20:27:42 -0000 1.11 *************** *** 72,75 **** --- 72,78 ---- U32 lastFireTime; F32 mHealth; + F32 mEnergy; + bool mShieldActive; + StringTableEntry mPlayerName; Index: CTFGame.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/CTFGame.cpp,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** CTFGame.cpp 30 Apr 2004 08:33:20 -0000 1.16 --- CTFGame.cpp 30 Apr 2004 20:27:41 -0000 1.17 *************** *** 36,40 **** { ! static void renderFlag(Point pos, Color c) { glPushMatrix(); --- 36,40 ---- { ! void renderFlag(Point pos, Color c) { glPushMatrix(); *************** *** 149,189 **** } - Vector<RangedU32<0, CTFGameType::MaxPing> > CTFGameType::mPingTimes; ///< Static vector used for constructing update RPCs - Vector<Int<24> > CTFGameType::mScores; - - void CTFGameType::updateClientScoreboard(S32 clientIndex) - { - mPingTimes.clear(); - mScores.clear(); - - for(S32 i = 0; i < mClientList.size(); i++) - { - if(mClientList[i].ping < MaxPing) - mPingTimes.push_back(mClientList[i].ping); - else - mPingTimes.push_back(MaxPing); - mScores.push_back(mClientList[i].score); - } - - NetObject::setRPCDestConnection(mClientList[clientIndex].clientConnection); - s2cScoreboardUpdate(mPingTimes, mScores); - NetObject::setRPCDestConnection(NULL); - } - - TNL_DECLARE_RPC_MEM_ENUM(CTFGameType, MaxPing); - - TNL_IMPLEMENT_NETOBJECT_RPC(CTFGameType, s2cScoreboardUpdate, (const Vector<RangedU32<0, CTFGameType::MaxPing> > &pingTimes, const Vector<Int<24> > &scores), - NetClassGroupGameMask, RPCGuaranteedOrdered, RPCToGhost, 0) - { - for(S32 i = 0; i < mClientList.size(); i++) - { - if(i >= pingTimes.size()) - break; - - mClientList[i].ping = pingTimes[i]; - mClientList[i].score = scores[i]; - } - } - void CTFGameType::shipTouchFlag(Ship *theShip, CTFFlagItem *theFlag) { --- 149,152 ---- *************** *** 305,343 **** } - static const char *CTFMessages[] = - { - "%s returned the %s flag.", - "%s captured the %s flag!", - "%s took the %s flag!", - "%s dropped the %s flag!", - }; - - static U32 CTFFlagSounds[] = - { - SFXFlagReturn, - SFXFlagCapture, - SFXFlagSnatch, - SFXFlagDrop, - }; - TNL_IMPLEMENT_NETOBJECT_RPC(CTFGameType, s2cCTFMessage, (U32 messageIndex, StringTableEntry clientName, U32 teamIndex), NetClassGroupGameMask, RPCGuaranteedOrdered, RPCToGhost, 0) { ! S32 clientIndex = findClientIndexByName(clientName); gGameUserInterface.displayMessage(Color(0.6f, 1.0f, 0.8f), CTFMessages[messageIndex], ! mClientList[clientIndex].name.getString(), mTeams[teamIndex].name.getString()); SFXObject::play(CTFFlagSounds[messageIndex]); } - TNL_IMPLEMENT_NETOBJECT_RPC(CTFGameType, s2cKillMessage, (StringTableEntry victim, StringTableEntry killer), - NetClassGroupGameMask, RPCGuaranteedOrdered, RPCToGhost, 0) - { - gGameUserInterface.displayMessage(Color(1.0f, 1.0f, 0.8f), - "%s zapped %s", killer.getString(), victim.getString()); - } - TNL_IMPLEMENT_NETOBJECT(CTFFlagItem); --- 268,297 ---- } TNL_IMPLEMENT_NETOBJECT_RPC(CTFGameType, s2cCTFMessage, (U32 messageIndex, StringTableEntry clientName, U32 teamIndex), NetClassGroupGameMask, RPCGuaranteedOrdered, RPCToGhost, 0) { ! static const char *CTFMessages[] = ! { ! "%s returned the %s flag.", ! "%s captured the %s flag!", ! "%s took the %s flag!", ! "%s dropped the %s flag!", ! }; ! ! static U32 CTFFlagSounds[] = ! { ! SFXFlagReturn, ! SFXFlagCapture, ! SFXFlagSnatch, ! SFXFlagDrop, ! }; gGameUserInterface.displayMessage(Color(0.6f, 1.0f, 0.8f), CTFMessages[messageIndex], ! clientName.getString(), mTeams[teamIndex].name.getString()); SFXObject::play(CTFFlagSounds[messageIndex]); } TNL_IMPLEMENT_NETOBJECT(CTFFlagItem); *************** *** 346,349 **** --- 300,304 ---- teamIndex = 0; mNetFlags.set(Ghostable); + mObjectTypeMask |= CommandMapVisType; } Index: gameType.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/gameType.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** gameType.h 27 Apr 2004 21:37:54 -0000 1.5 --- gameType.h 30 Apr 2004 20:27:41 -0000 1.6 *************** *** 69,72 **** --- 69,79 ---- U32 mTimeUntilScoreboardUpdate; + enum { + MaxPing = 999, + }; + + static Vector<RangedU32<0, MaxPing> > mPingTimes; ///< Static vector used for constructing update RPCs + static Vector<Int<24> > mScores; + GameType(); void countTeamPlayers(); *************** *** 115,118 **** --- 122,128 ---- TNL_DECLARE_RPC(s2cDisplayChatMessage, (bool global, StringTableEntry clientName, const char *message)); + TNL_DECLARE_RPC(s2cKillMessage, (StringTableEntry victim, StringTableEntry killer)); + TNL_DECLARE_RPC(s2cScoreboardUpdate, (const Vector<RangedU32<0, MaxPing> > &pingTimes, const Vector<Int<24> > &scores)); + TNL_DECLARE_RPC(c2sRequestScoreboardUpdates, (bool updates)); Index: point.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/point.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** point.h 27 Apr 2004 20:41:53 -0000 1.5 --- point.h 30 Apr 2004 20:27:41 -0000 1.6 *************** *** 113,116 **** --- 113,128 ---- } + void unionPoint(const Point &p) + { + if(p.x < min.x) + min.x = p.x; + else if(p.x > max.x) + max.x = p.x; + if(p.y < min.y) + min.y = p.y; + else if(p.y > max.y) + max.y = p.y; + } + void unionRect(const Rect &r) { Index: item.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/item.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** item.cpp 23 Apr 2004 01:49:46 -0000 1.5 --- item.cpp 30 Apr 2004 20:27:41 -0000 1.6 *************** *** 38,42 **** mIsCollideable = collideable; mInterpTime = 0; ! mObjectTypeMask = MoveableType | ItemType; } --- 38,42 ---- mIsCollideable = collideable; mInterpTime = 0; ! mObjectTypeMask = MoveableType | ItemType | CommandMapVisType; } Index: ZAP.vcproj =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/ZAP.vcproj,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** ZAP.vcproj 30 Apr 2004 10:26:25 -0000 1.9 --- ZAP.vcproj 30 Apr 2004 20:27:41 -0000 1.10 *************** *** 223,226 **** --- 223,229 ---- </File> <File + RelativePath="..\exe\README.txt"> + </File> + <File RelativePath=".\sfx.cpp"> </File> *************** *** 235,238 **** --- 238,247 ---- </File> <File + RelativePath=".\soccerGame.cpp"> + </File> + <File + RelativePath=".\soccerGame.h"> + </File> + <File RelativePath=".\sparkManager.cpp"> </File> --- NEW FILE: soccerGame.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 _SOCCERGAME_H_ #define _SOCCERGAME_H_ #include "gameType.h" #include "item.h" namespace Zap { class Ship; class SoccerBallItem; class SoccerGameType : public GameType { enum Scores { KillScore = 100, GoalScore = 500, }; public: void renderInterfaceOverlay(bool scoreboardVisible); void controlObjectForClientKilled(GameConnection *theClient, GameObject *clientObject, GameObject *killerObject); 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); }; class SoccerBallItem : public Item { typedef Item Parent; Point initialPos; U32 sendHomeTime; StringTableEntry lastPlayerTouch; public: SoccerBallItem(Point pos = Point()); void renderItem(Point pos); void sendHome(); void damageObject(DamageInfo *theInfo); void processServer(U32 deltaT); void processArguments(S32 argc, const char **argv); bool collide(GameObject *hitObject); TNL_DECLARE_CLASS(SoccerBallItem); }; class SoccerGoalObject : public GameObject { typedef GameObject Parent; Vector<Point> mPolyBounds; U32 teamIndex; enum { MaxPoints = 10, }; public: SoccerGoalObject(); U32 getTeamIndex() { return teamIndex; } void render(); void processArguments(S32 argc, const char **argv); void onAddedToGame(Game *theGame); void computeExtent(); bool getCollisionPoly(Vector<Point> &polyPoints); bool collide(GameObject *hitObject); U32 packUpdate(GhostConnection *connection, U32 mask, BitStream *stream); void unpackUpdate(GhostConnection *connection, BitStream *stream); TNL_DECLARE_CLASS(SoccerGoalObject); }; }; #endif Index: ship.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/ship.cpp,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** ship.cpp 30 Apr 2004 08:33:20 -0000 1.18 --- ship.cpp 30 Apr 2004 20:27:41 -0000 1.19 *************** *** 48,52 **** Ship::Ship(StringTableEntry playerName, Point p, F32 m) : MoveObject(p, CollisionRadius) { ! mObjectTypeMask = ShipType | MoveableType; mNetFlags.set(Ghostable); --- 48,52 ---- Ship::Ship(StringTableEntry playerName, Point p, F32 m) : MoveObject(p, CollisionRadius) { ! mObjectTypeMask = ShipType | MoveableType | CommandMapVisType; mNetFlags.set(Ghostable); *************** *** 285,288 **** --- 285,289 ---- stream->write(mMoveState[ActualState].vel.x); stream->write(mMoveState[ActualState].vel.y); + stream->write(mEnergy); } *************** *** 294,298 **** stream->read(&mMoveState[ActualState].vel.x); stream->read(&mMoveState[ActualState].vel.y); ! Point delta = mMoveState[ActualState].pos - mMoveState[RenderState].pos; if(delta.len() > MaxControlObjectInterpDistance) --- 295,300 ---- stream->read(&mMoveState[ActualState].vel.x); stream->read(&mMoveState[ActualState].vel.y); ! stream->read(&mEnergy); ! Point delta = mMoveState[ActualState].pos - mMoveState[RenderState].pos; if(delta.len() > MaxControlObjectInterpDistance) |