- Timestamp:
- Jun 26, 2006, 4:46:25 PM (19 years ago)
- Location:
- trunk/src
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/math/quaternion.h
r8731 r8802 50 50 /** @param q: the Quaternion to compare with this one. @returns true if the Quaternions are the same, false otherwise */ 51 51 inline bool operator== (const Quaternion& q) const { return (unlikely(this->v==q.v&&this->w==q.w))?true:false; }; 52 /** @param q: the Quaternion to compare with this one. @returns true if the Quaternions are the same, false otherwise */ 53 inline bool operator!= (const Quaternion& q) const { return (unlikely(this->v!=q.v&&this->w!=q.w))?true:false; }; 52 54 /** @param f: a real value @return a Quaternion containing the quotient */ 53 55 inline Quaternion operator/ (const float& f) const { return (unlikely(f==0.0)) ? Quaternion() : Quaternion(this->v/f, this->w/f); }; -
trunk/src/lib/network/netdefs.h
r7954 r8802 19 19 #define MAX_CONNECTIONS 1000 20 20 21 #define NETWORK_FREQUENCY 3321 #define NETWORK_FREQUENCY 66 22 22 23 23 -
trunk/src/lib/network/udp_server_socket.cc
r8623 r8802 147 147 res.length = packetBuffer[userId].front().length; 148 148 packetBuffer[userId].pop_front(); 149 150 if ( res.length == 0 )151 res.length = -1;152 149 } 153 150 … … 173 170 * @param ip users host / port 174 171 */ 175 void UdpServerSocket::initUser( int userId, IPaddress ip )172 void UdpServerSocket::initUser( int userId, IPaddress ip, byte randomByte ) 176 173 { 177 174 int channel = SDLNet_UDP_Bind( socket, userId, &ip ); … … 192 189 userList.resize( userId + 1 ); 193 190 194 userList[ userId ] = ip; 191 userList[ userId ].addr = ip; 192 userList[ userId ].randomByte = randomByte; 195 193 } 196 194 … … 206 204 return; 207 205 208 userList[userId]. host = 0;209 userList[userId]. port = 0;206 userList[userId].addr.host = 0; 207 userList[userId].addr.port = 0; 210 208 211 209 SDLNet_UDP_Unbind( socket, userId ); … … 234 232 return false; 235 233 } 236 234 237 235 return true; 238 236 } … … 251 249 bool isNewConnection = false; 252 250 251 if ( packet->len <= 0 ) 252 continue; 253 253 254 for ( userId =0; userId < (int)userList.size(); userId++ ) 254 if ( userList[userId]. host == packet->address.host && userList[userId].port == packet->address.port)255 if ( userList[userId].addr.host == packet->address.host && userList[userId].addr.port == packet->address.port && userList[userId].randomByte == ( packet->data[0] & 0xFC ) ) 255 256 break; 256 257 257 258 if ( userId >= (int)userList.size() ) 258 259 { 259 260 260 newConn++; 261 261 isNewConnection = true; … … 268 268 269 269 for ( userId =0; userId < (int)userList.size(); userId++ ) 270 if ( userList[userId]. host == 0 && userList[userId].port == 0 )270 if ( userList[userId].addr.host == 0 && userList[userId].addr.port == 0 ) 271 271 break; 272 272 273 initUser( userId, packet->address );274 UdpSocket * sock = new UdpSocket( this, packet->address, userId );273 initUser( userId, packet->address, packet->data[0] & 0xFC ); 274 UdpSocket * sock = new UdpSocket( this, packet->address, userId, packet->data[0] & 0xFC ); 275 275 newSocketList.push_back( sock ); 276 276 PRINTF(0)("NEW CONNECTION %x\n", packet->address.host ); … … 292 292 memcpy( networkPacket.data, packet->data, packet->len ); 293 293 packetBuffer[userId].push_back( networkPacket ); 294 295 294 } 296 295 -
trunk/src/lib/network/udp_server_socket.h
r7954 r8802 33 33 typedef std::vector<NetworkPacketList> PacketBuffer; 34 34 35 typedef std::vector<IPaddress> UserList; 35 struct UserInfo 36 { 37 IPaddress addr; 38 byte randomByte; 39 }; 40 41 typedef std::vector<UserInfo> UserList; 36 42 37 43 typedef std::list<UdpSocket*> UdpSocketList; … … 57 63 bool sendPacket( NetworkPacket networkPacket, int userId ); 58 64 int getPacketCount( int childId ); 59 void initUser( int childId, IPaddress ip );65 void initUser( int childId, IPaddress ip, byte randomByte ); 60 66 61 67 private: -
trunk/src/lib/network/udp_socket.cc
r8362 r8802 25 25 this->socket = NULL; 26 26 this->packet = NULL; 27 this->randomByte = 0; 27 28 } 28 29 … … 70 71 * @param userId userid used by serverSocket 71 72 */ 72 UdpSocket::UdpSocket( UdpServerSocket * serverSocket, IPaddress ip, int userId )73 UdpSocket::UdpSocket( UdpServerSocket * serverSocket, IPaddress ip, int userId, byte randomByte ) 73 74 { 74 75 this->init(); 75 76 this->serverSocket = serverSocket; 76 77 this->userId = userId; 78 this->randomByte = randomByte; 77 79 } 78 80 … … 104 106 105 107 IPaddress ip; 108 109 this->randomByte = generateNewRandomByte(); 106 110 107 111 PRINTF(0)("connect to server %s on port %d\n", host.c_str(), port); … … 137 141 { 138 142 PRINTF(0)("disconnect\n"); 139 writePacket( NULL, 0 ); 143 byte cmd = this->randomByte | UDPCMD_DISCONNECT; 144 writeRawPacket( &cmd, 1 ); 140 145 SDLNet_UDP_Unbind( socket, -1 ); 141 146 SDLNet_UDP_Close( socket ); … … 152 157 bool UdpSocket::writePacket( byte * data, int length ) 153 158 { 159 byte * buf = new byte[length+1]; 160 if ( length > 0 ) 161 memcpy( buf+1, data, length ); 162 buf[0] = this->randomByte; 163 return writeRawPacket( buf, length+1 ); 164 } 165 166 /** 167 * recieve one packet from another host 168 * @param data pointer to buffer to copy data into 169 * @param maxLength maximal length of buffer 170 * @return less than 0 on error, number bytes read else 171 */ 172 int UdpSocket::readPacket( byte * data, int maxLength ) 173 { 174 assert( maxLength <= UDP_PACKET_SIZE ); 175 176 if ( serverSocket ) 177 { 178 NetworkPacket networkPacket = serverSocket->getPacket( this->userId ); 179 180 byte udpCmd = 0; 181 182 if ( networkPacket.length > 0 ) 183 { 184 assert( maxLength > networkPacket.length ); 185 186 memcpy( data, networkPacket.data+1, networkPacket.length-1 ); 187 udpCmd = networkPacket.data[0]; 188 } 189 else 190 return 0; 191 192 if ( !checkRandomByte( networkPacket.data[0] ) ) 193 return 0; 194 195 if ( networkPacket.data ) 196 { 197 free( networkPacket.data ); 198 networkPacket.data = NULL; 199 } 200 201 if ( !checkUdpCmd( udpCmd ) ) 202 return 0; 203 204 return networkPacket.length-1; 205 } 206 else 207 { 208 int numrecv = SDLNet_UDP_Recv( socket, packet); 209 210 byte udpCmd = 0; 211 212 if ( numrecv > 0) 213 { 214 assert( packet->len <= maxLength ); 215 216 if ( packet->len > 0 ) 217 memcpy( data, packet->data+1, packet->len-1 ); 218 else 219 return 0; 220 221 if ( !checkRandomByte( packet->data[0] ) ) 222 return 0; 223 224 if ( !checkUdpCmd( udpCmd ) ) 225 return 0; 226 227 return packet->len-1; 228 } 229 else if ( numrecv < 0 ) 230 { 231 PRINTF(1)("SDLNet_UDP_Recv: %s\n", SDLNet_GetError()); 232 bOk = false; 233 return -1; 234 } 235 else 236 { 237 return 0; 238 } 239 } 240 241 return 0; 242 } 243 244 bool UdpSocket::writeRawPacket( byte * data, int length ) 245 { 154 246 if ( serverSocket ) 155 247 { … … 183 275 } 184 276 185 /** 186 * recieve one packet from another host 187 * @param data pointer to buffer to copy data into 188 * @param maxLength maximal length of buffer 189 * @return less than 0 on error, number bytes read else 190 */ 191 int UdpSocket::readPacket( byte * data, int maxLength ) 192 { 193 assert( maxLength <= UDP_PACKET_SIZE ); 194 195 if ( serverSocket ) 196 { 197 NetworkPacket networkPacket = serverSocket->getPacket( this->userId ); 198 199 if ( networkPacket.length == -1 ) 200 { 201 this->disconnectServer(); 202 return 0; 203 } 204 205 if ( networkPacket.length > 0 ) 206 { 207 assert( maxLength > networkPacket.length ); 208 209 memcpy( data, networkPacket.data, networkPacket.length ); 210 } 211 212 if ( networkPacket.data ) 213 { 214 free( networkPacket.data ); 215 networkPacket.data = NULL; 216 } 217 218 return networkPacket.length; 277 bool UdpSocket::checkUdpCmd( byte udpCmd ) 278 { 279 if ( udpCmd & UDPCMD_DISCONNECT ) 280 { 281 this->disconnectServer(); 282 PRINTF(0)("received disconnect byte\n"); 283 return false; 284 } 285 286 if ( !this->serverSocket && ( udpCmd & UDPCMD_INVALIDRNDBYTE ) ) 287 { 288 PRINTF(0)("received invlid random number byte\n"); 289 byte cmd = this->randomByte | UDPCMD_DISCONNECT; 290 writeRawPacket( &cmd, 1 ); 291 this->randomByte = generateNewRandomByte(); 292 return false; 293 } 294 295 return true; 296 } 297 298 byte UdpSocket::generateNewRandomByte( ) 299 { 300 srand( SDL_GetTicks() ); 301 byte res = ( rand() & 0xFC ); 302 303 PRINTF(0)("generated random byte: %x\n", res); 304 305 return res; 306 } 307 308 bool UdpSocket::checkRandomByte( byte rndByte ) 309 { 310 if ( ( rndByte & 0xFC ) == this->randomByte ) 311 { 312 return true; 219 313 } 220 314 else 221 315 { 222 int numrecv = SDLNet_UDP_Recv( socket, packet); 223 if ( numrecv > 0) 224 { 225 assert( packet->len <= maxLength ); 226 227 if ( packet->len == 0 ) 228 { 229 this->disconnectServer(); 230 return 0; 231 } 232 233 memcpy( data, packet->data, packet->len ); 234 return packet->len; 235 } 236 else if ( numrecv < 0 ) 237 { 238 PRINTF(1)("SDLNet_UDP_Recv: %s\n", SDLNet_GetError()); 239 bOk = false; 240 return -1; 241 } 242 else 243 { 244 return 0; 245 } 246 } 247 248 return 0; 249 } 250 251 252 316 PRINTF(2)("wrong random byte: %x\n", ( rndByte & 0xFC )); 317 return false; 318 } 319 } 320 321 322 -
trunk/src/lib/network/udp_socket.h
r7954 r8802 16 16 class UdpServerSocket; 17 17 18 enum 19 { 20 UDPCMD_DISCONNECT = 1, 21 UDPCMD_INVALIDRNDBYTE = 2 22 }; 23 18 24 class UdpSocket : public NetworkSocket 19 25 { 20 26 public: 21 27 UdpSocket(); 22 UdpSocket( UdpServerSocket * serverSocket, IPaddress ip, int userId );28 UdpSocket( UdpServerSocket * serverSocket, IPaddress ip, int userId, byte randomByte ); 23 29 UdpSocket( std::string host, int port ); 24 30 virtual ~UdpSocket(); … … 28 34 virtual void disconnectServer(); 29 35 30 virtual bool writePacket(byte * data, int length );36 virtual bool writePacket(byte * data, int length ); 31 37 32 38 virtual int readPacket(byte * data, int maxLength); … … 39 45 UDPpacket * packet; 40 46 47 byte randomByte; //!< contains random bytes & 0xFC 48 49 bool writeRawPacket( byte * data, int length ); 50 bool checkUdpCmd( byte udpCmd ); 51 bool checkRandomByte( byte rndByte ); 52 byte generateNewRandomByte(); 53 41 54 void init(); 42 55 -
trunk/src/util/game_rules.cc
r8362 r8802 21 21 22 22 #include "util/mission_goal.h" 23 24 #include "shared_network_data.h" 23 25 24 26 #include "debug.h" … … 86 88 void GameRules::registerKill(const Kill& kill) 87 89 { 90 if ( !SharedNetworkData::getInstance()->isGameServer() ) 91 return; 88 92 PRINTF(0)("Received Event: Kill\n"); 89 93 this->killList.push_back(kill); -
trunk/src/util/game_rules.h
r8623 r8802 35 35 /** adding a kill event to the kill list @param kill the kill object containing all infos */ 36 36 void registerKill(const Kill& kill); 37 virtual void registerSpawn( WorldEntity * we ){} 37 38 38 39 virtual void onPlayerSpawn() {} 39 40 virtual void onPlayerDeath() {} 40 41 41 42 42 virtual void tick(float dt) = 0; -
trunk/src/util/multiplayer_team_deathmatch.cc
r8717 r8802 45 45 46 46 #include "shell_command.h" 47 48 #include "spawning_point.h" 47 49 48 50 … … 70 72 71 73 this->box = NULL; 72 73 this->deathScreen = new ImagePlane(); 74 this->deathScreen->setSize(State::getResX()/4.0, State::getResY()/4.0); 75 this->deathScreen->setAbsCoor2D(State::getResX()/2.0f, State::getResY()/2.0f); 76 this->deathScreen->setVisibility(false); 74 this->table = NULL; 75 this->statsBox = NULL; 77 76 78 77 this->localPlayer = State::getPlayer(); … … 83 82 subscribeEvent( ES_GAME, SDLK_o ); 84 83 subscribeEvent( ES_GAME, SDLK_TAB ); 85 84 subscribeEvent( ES_GAME, SDLK_F1 ); 85 subscribeEvent( ES_MENU, SDLK_F1 ); 86 subscribeEvent( ES_MENU, KeyMapper::PEV_FIRE1 ); 87 86 88 this->notifier = new OrxGui::GLGuiNotifier(); 87 89 this->notifier->show(); … … 99 101 MultiplayerTeamDeathmatch::~MultiplayerTeamDeathmatch() 100 102 { 101 if( this->deathScreen)102 delete this->deathScreen;103 104 103 unsubscribeEvent( ES_GAME, SDLK_o ); 105 104 unsubscribeEvent( ES_GAME, SDLK_TAB ); 106 105 unsubscribeEvent( ES_GAME, SDLK_F1 ); 106 unsubscribeEvent( ES_MENU, SDLK_F1 ); 107 unsubscribeEvent( ES_MENU, KeyMapper::PEV_FIRE1 ); 108 107 109 if ( this->notifier ) 108 110 { … … 130 132 .describe("sets the maximal kills for winning condition"); 131 133 132 LoadParam(root, "death-screen-image", this, MultiplayerTeamDeathmatch, setDeathScreen)133 .describe("sets the death screen image");134 135 134 LoadParam(root, "num-teams", this, MultiplayerTeamDeathmatch, setNumTeams) 136 135 .describe("sets number of teams"); … … 139 138 140 139 141 142 void MultiplayerTeamDeathmatch::setDeathScreen(const std::string& imageName)143 {144 if( this->deathScreen)145 this->deathScreen->setTexture(imageName);146 }147 148 149 150 /**151 * called when the player enters the game152 * @param player the spawned player153 */154 void MultiplayerTeamDeathmatch::onPlayerSpawn()155 {156 this->bLocalPlayerDead = false;157 this->deathScreen->setVisibility(false);158 }159 160 161 /**162 * when the player is killed163 * @param player the killed player164 */165 void MultiplayerTeamDeathmatch::onPlayerDeath()166 {167 this->bLocalPlayerDead = true;168 this->deathScreen->setVisibility(true);169 }170 171 172 140 /** 173 141 * time tick … … 176 144 void MultiplayerTeamDeathmatch::tick(float dt) 177 145 { 146 tickStatsTable(); 178 147 //on client side hostId is -1 until hanshake finished 179 148 if ( SharedNetworkData::getInstance()->getHostID() < 0 ) … … 250 219 if ( !SharedNetworkData::getInstance()->isGameServer() ) 251 220 return; 252 221 222 //handle kills 223 for ( std::vector<Kill>::iterator it = this->killList.begin(); it != this->killList.end(); ) 224 { 225 std::vector<Kill>::iterator delit = it; 226 227 onKill( it->getKiller()->getOwner(), it->getVictim()->getOwner() ); 228 229 it++; 230 killList.erase( delit ); 231 } 232 253 233 gameStateTimer -= dt; 254 234 //PRINTF(0)("TICK %f\n", gameStateTimer); … … 310 290 if ( teamScore[i] >= maxKills ) 311 291 { 312 //team i wins 313 //TODO 292 nextGameState(); 314 293 } 315 294 } … … 435 414 if ( currentGameState == GAMESTATE_POST_GAME ) 436 415 { 437 //TODO end game 416 State::getCurrentStoryEntity()->stop(); 417 this->bShowTeamChange = false; 438 418 439 419 return; … … 563 543 if ( event.bPressed ) 564 544 this->bShowTeamChange = true; 545 } else if ( event.type == SDLK_F1 ) 546 { 547 if ( !this->statsBox && event.bPressed ) 548 { 549 PRINTF(0)("show stats\n"); 550 this->showStats(); 551 } 552 if ( this->statsBox && !this->bLocalPlayerDead && event.bPressed && this->table->rowCount() != 0 && this->table->columnCount() != 0 ) 553 { 554 PRINTF(0)("hide stats\n"); 555 this->hideStats(); 556 } 565 557 } 566 558 else if ( event.type == SDLK_TAB ) … … 576 568 } 577 569 } 570 else if ( this->bLocalPlayerDead && statsBox && event.type == KeyMapper::PEV_FIRE1 ) 571 { 572 this->hideStats(); 573 } 578 574 } 579 575 … … 623 619 } 624 620 625 626 627 621 /** 622 * show table with frags 623 */ 624 void MultiplayerTeamDeathmatch::showStats( ) 625 { 626 EventHandler::getInstance()->pushState( ES_MENU ); 627 statsBox = new OrxGui::GLGuiBox(); 628 statsBox->setAbsCoor2D( 300, 100 ); 629 630 this->table = new OrxGui::GLGuiTable(0,0); 631 632 statsBox->pack( this->table ); 633 634 statsBox->showAll(); 635 } 636 637 /** 638 * hide table with frags 639 */ 640 void MultiplayerTeamDeathmatch::hideStats( ) 641 { 642 if ( statsBox ) 643 { 644 delete statsBox; 645 statsBox = NULL; 646 } 647 648 EventHandler::getInstance()->popState(); 649 } 650 651 /** 652 * fill stats table with values 653 */ 654 void MultiplayerTeamDeathmatch::tickStatsTable( ) 655 { 656 if ( !this->statsBox ) 657 return; 658 659 std::vector<std::string> headers; 660 headers.push_back("Red Team"); 661 headers.push_back(""); 662 headers.push_back(""); 663 headers.push_back("Blue Team"); 664 headers.push_back(""); 665 this->table->setHeader(headers); 666 667 std::map<int,std::string> fragsTeam0; 668 std::map<int,std::string> fragsTeam1; 669 670 const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS ); 671 672 if ( !list ) 673 return; 674 675 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 676 { 677 PlayerStats & stats = *dynamic_cast<PlayerStats*>(*it); 678 679 if ( stats.getTeamId() == 0 || stats.getTeamId() == 1 ) 680 { 681 if ( stats.getTeamId() == 0 ) 682 fragsTeam0[stats.getScore()] = stats.getNickName(); 683 else 684 fragsTeam1[stats.getScore()] = stats.getNickName(); 685 } 686 } 687 688 char st[10]; 689 int i = 0; 690 691 692 i = 2; 693 for ( std::map<int,std::string>::const_iterator it = fragsTeam0.begin(); it != fragsTeam0.end(); it++ ) 694 { 695 this->table->setEntry( 0, i, it->second ); 696 snprintf( st, 10, "%d", it->first ); 697 this->table->setEntry( 1, i, st ); 698 this->table->setEntry( 2, i, "" ); 699 i++; 700 } 701 702 i = 2; 703 for ( std::map<int,std::string>::const_iterator it = fragsTeam1.begin(); it != fragsTeam1.end(); it++ ) 704 { 705 this->table->setEntry( 3, i, it->second ); 706 snprintf( st, 10, "%d", it->first ); 707 this->table->setEntry( 4, i, st ); 708 i++; 709 } 710 } 711 712 /** 713 * this function is called when a player kills another one or himself 714 * @param killedUserId 715 * @param userId 716 */ 717 void MultiplayerTeamDeathmatch::onKill( int killedUserId, int userId ) 718 { 719 assert( PlayerStats::getStats( killedUserId ) ); 720 assert( PlayerStats::getStats( userId ) ); 721 722 PlayerStats & killedStats = *PlayerStats::getStats( killedUserId ); 723 PlayerStats & stats = *PlayerStats::getStats( userId ); 724 725 if ( killedUserId != userId ) 726 stats.setScore( stats.getScore() + 1 ); 727 else 728 stats.setScore( stats.getScore() - 1 ); 729 730 if ( killedUserId == SharedNetworkData::getInstance()->getHostID() ) 731 { 732 this->bLocalPlayerDead = true; 733 this->showStats(); 734 } 735 736 const std::list<BaseObject*> * list = ClassList::getList( CL_SPAWNING_POINT ); 737 738 assert( list ); 739 740 std::vector<SpawningPoint*> spList; 741 742 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 743 { 744 SpawningPoint * sp = dynamic_cast<SpawningPoint*>(*it); 745 746 if ( sp->getTeamId() < 0 || sp->getTeamId() == killedStats.getTeamId() ) 747 spList.push_back( sp ); 748 } 749 750 int n = spList.size()*rand(); 751 752 spList[n]->pushEntity( killedStats.getPlayable(), 3 ); 753 } 754 755 /** 756 * this function is called on player respawn 757 * @param userId 758 */ 759 void MultiplayerTeamDeathmatch::onRespawn( int userId ) 760 { 761 if ( userId == SharedNetworkData::getInstance()->getHostID() ) 762 { 763 this->bLocalPlayerDead = false; 764 this->hideStats(); 765 } 766 } 767 768 /** 769 * this function is called on player respawn 770 * @param we 771 */ 772 void MultiplayerTeamDeathmatch::registerSpawn( WorldEntity * we ) 773 { 774 onRespawn( we->getOwner() ); 775 } 776 -
trunk/src/util/multiplayer_team_deathmatch.h
r8708 r8802 41 41 virtual std::string getPlayableModelFileName( int userId, int team, ClassID classId ); 42 42 43 virtual void onPlayerSpawn(); 44 virtual void onPlayerDeath(); 45 43 virtual void registerSpawn( WorldEntity * we ); 46 44 47 45 virtual void tick(float dt); … … 50 48 inline void setDeathPenaltyTimeout(float time) { this->deathTimeout = time; } 51 49 inline void setMaxKills(int kills) { this->maxKills = kills; } 52 void setDeathScreen(const std::string& imageName);53 50 54 51 inline void setNumTeams( int numTeams ){ this->numTeams = numTeams; } … … 58 55 59 56 virtual void process(const Event &event); 57 58 void onKill( int killedUserId, int userId ); 59 void onRespawn( int userId ); 60 60 61 61 virtual void handleChatMessage( int userId, const std::string & message, int messageType ); … … 73 73 74 74 std::map<int,int> teamScore; //!< team score 75 76 ImagePlane* deathScreen; //!< the death screen77 75 78 76 int currentGameState; //!< game state … … 100 98 101 99 void onInputEnter( const std::string & text ); 100 101 OrxGui::GLGuiBox* statsBox; 102 OrxGui::GLGuiTable* table; 103 void tickStatsTable(); 104 105 void showStats(); 106 void hideStats(); 102 107 }; 103 108 -
trunk/src/world_entities/npcs/generic_npc.cc
r8783 r8802 30 30 #include "generic_npc.h" 31 31 32 #include "animation/animation3d.h" 33 32 34 using namespace std; 33 35 … … 55 57 */ 56 58 GenericNPC::~GenericNPC () 57 {} 59 { 60 if( this->currentAnim != NULL) 61 delete this->currentAnim; 62 } 58 63 59 64 … … 138 143 float GenericNPC::walkTo(float x, float y, float z, float qu, float qx, float qy, float qz) 139 144 { 140 141 return true; 145 Vector destCoor = Vector(x, y, z); 146 Quaternion destDir = Quaternion(Vector(qx, qy, qz), qu); 147 148 // check if this is the current goal 149 if( this->destCoor != destCoor && this->destDir != destDir) 150 { 151 this->destCoor = Vector(x, y, 0.0f); 152 this->destDir = Quaternion(Vector(qx, qy, qz), qu); 153 154 float time = 5.0f; 155 156 if( this->currentAnim != NULL) 157 delete this->currentAnim; 158 159 this->currentAnim = new Animation3D(this); 160 this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), 0.0f); 161 this->currentAnim->addKeyFrame(this->destCoor, this->destDir, time); 162 } 163 164 // calculate the distance 165 Vector distance = this->getAbsCoor() - this->destCoor; 166 return distance.len(); 167 } 168 169 170 171 /** 172 * walk to a specific place with direction 173 * 174 * @param x: x coordinate to go to 175 * @param y: y coordinate to go to 176 * @param qu: angle to rotate 177 * @param qx: x coordinate of rotation vector 178 * @param qy: y coordinate of rotation vector 179 * @param qz: z coordinate of rotation vector 180 * 181 */ 182 float GenericNPC::walkTo(float x, float y, float qu, float qx, float qy, float qz) 183 { 184 return this->walkTo(x, y, 0.0f, qu, qx, qy, qz); 142 185 } 143 186 -
trunk/src/world_entities/npcs/generic_npc.h
r8796 r8802 22 22 23 23 class TiXmlElement; 24 class Animation3D; 24 25 25 26 … … 71 72 Vector destCoor; 72 73 Quaternion destDir; 74 75 Animation3D* currentAnim; 73 76 }; 74 77 -
trunk/src/world_entities/spawning_point.cc
r8068 r8802 24 24 #include "compiler.h" 25 25 26 #include <map> 26 #include "state.h" 27 #include "game_rules.h" 27 28 28 29 … … 59 60 { 60 61 this->setClassID(CL_SPAWNING_POINT, "SpawningPoint"); 62 63 this->teamId = -1; 61 64 } 62 65 … … 81 84 LoadParam(root, "delay", this, SpawningPoint, setSpawningDelay) 82 85 .describe("sets the delay of the spawning point"); 86 87 /* load teamId */ 88 LoadParam(root, "teamId", this, SpawningPoint, setTeamId) 89 .describe("sets teamId"); 83 90 84 91 … … 101 108 void SpawningPoint::pushEntity(WorldEntity* entity, float delay) 102 109 { 103 this->queue[entity] = this->localTimer + delay; 110 QueueEntry qe; 111 qe.entity = entity; 112 qe.list = entity->getOMListNumber(); 113 qe.respawnTime = this->localTimer + delay; 114 115 queue.push_back( qe ); 104 116 } 105 117 … … 113 125 114 126 115 //BaseObject* spawningEntity = Factory::fabricate(this->classID); 116 // if( likely(this->world != NULL)) 117 // this->world->spawn(dynamic_cast<WorldEntity*>(spawningEntity)); 127 entity->setAbsCoor( this->getAbsCoor() ); 128 entity->setAbsDir( this->getAbsDir() ); 129 130 //TODO set camera (not smooth) 118 131 } 119 132 … … 129 142 this->localTimer += dt; 130 143 131 std:: map<WorldEntity*, float>::iterator it = this->queue.begin();132 for( ; it != this->queue.end(); it++)144 std::list<QueueEntry>::iterator it = this->queue.begin(); 145 for( ; it != this->queue.end(); ) 133 146 { 134 //135 if( it-> second<= this->localTimer)147 148 if( it->respawnTime <= this->localTimer) 136 149 { 137 150 //spawn the player 138 this->spawn(it->first); 151 this->spawn(it->entity); 152 153 it->entity->toList( it->list ); 154 155 if ( State::getGameRules() ) 156 { 157 (State::getGameRules())->registerSpawn( it->entity ); 158 } 159 160 std::list<QueueEntry>::iterator delit = it; 161 it++; 162 163 queue.erase( delit ); 164 165 continue; 139 166 } 167 168 it++; 140 169 } 141 170 -
trunk/src/world_entities/spawning_point.h
r8068 r8802 8 8 #define _SPAWNING_POINT 9 9 10 #include " world_entity.h"10 #include "playable.h" 11 11 12 #include < map>12 #include <list> 13 13 14 14 class World; 15 15 class TiXmlElement; 16 16 17 struct QueueEntry 18 { 19 float respawnTime; 20 WorldEntity * entity; 21 OM_LIST list; 22 }; 17 23 18 24 //!< used to indicate what type of objects are spawned by this spawning point … … 50 56 /** sets the spawning point mode @param mode: the mode */ 51 57 void SpawningPoint::setSpawningMode(int mode) { this->mode = (SpawningPointMode)mode; } 58 59 inline int getTeamId(){ return this->teamId; } 60 inline void setTeamId( int teamId ){ this->teamId = teamId; } 52 61 53 62 void pushEntity(WorldEntity* entity, float delay = 0); … … 72 81 float localTimer; //!< the local timer 73 82 float seed; //!< the random seed of the position 83 int teamId; //!< only spawn players of this team 74 84 ClassID classid; //!< the classid of the entity to spawn 75 85 SpawningPointMode mode; //!< the mode of the spawning point 76 std:: map<WorldEntity*, float>queue; //!< queue of waiting WorldEntities to be spawned86 std::list<QueueEntry> queue; //!< queue of waiting WorldEntities to be spawned 77 87 bool bSpawning; //!< flag to indicate if this spawning point is active or not 78 88 };
Note: See TracChangeset
for help on using the changeset viewer.