- Timestamp:
- May 24, 2013, 1:23:49 AM (12 years ago)
- Branches:
- master
- Children:
- b81cea1
- Parents:
- 45b2750
- git-author:
- dportnoy <dmp1488@…> (05/24/13 01:14:53)
- git-committer:
- dportnoy <dmp1488@…> (05/24/13 01:23:49)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
server/server.cpp
r45b2750 r23559e7 139 139 140 140 // maybe put this in a separate method 141 map<unsigned int, Player>::iterator it, it2; 141 map<unsigned int, Player>::iterator it; 142 FLOAT_POSITION oldPos; 143 bool broadcastMove = false; 142 144 for (it = mapPlayers.begin(); it != mapPlayers.end(); it++) { 143 if (!it->second.move(gameMap)) { 144 cout << "Cenceling move" << endl; 145 serverMsg.type = MSG_TYPE_PLAYER; 146 it->second.serialize(serverMsg.buffer); 147 148 cout << "(" << it->second.pos.x << "," << it->second.pos.y << ")" << endl; 149 150 if (it->second.hasBlueFlag) 151 cout << "Got blue flag" << endl; 152 if (it->second.hasRedFlag) 153 cout << "Got red flag" << endl; 154 155 cout << "about to send move cencellation" << endl; 156 for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++) 157 { 158 if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 ) 159 error("sendMessage"); 145 oldPos = it->second.pos; 146 if (it->second.move(gameMap)) { 147 148 // check if the move needs to be canceled 149 switch(gameMap->getElement(it->second.pos.x/25, it->second.pos.y/25)) { 150 case WorldMap::TERRAIN_NONE: 151 case WorldMap::TERRAIN_OCEAN: 152 case WorldMap::TERRAIN_ROCK: 153 it->second.pos = oldPos; 154 it->second.target.x = it->second.pos.x; 155 it->second.target.y = it->second.pos.y; 156 broadcastMove = true; 157 break; 158 default: 159 // if there are no obstacles, do nothing 160 break; 161 } 162 163 switch(gameMap->getStructure(it->second.pos.x/25, it->second.pos.y/25)) { 164 case WorldMap::STRUCTURE_BLUE_FLAG: 165 cout << "Got blue flag" << endl; 166 it->second.hasBlueFlag = true; 167 broadcastMove = true; 168 break; 169 case WorldMap::STRUCTURE_RED_FLAG: 170 cout << "Got red flag" << endl; 171 it->second.hasRedFlag = true; 172 broadcastMove = true; 173 break; 174 } 175 176 if (broadcastMove) { 177 serverMsg.type = MSG_TYPE_PLAYER; 178 it->second.serialize(serverMsg.buffer); 179 180 cout << "about to broadcast move" << endl; 181 map<unsigned int, Player>::iterator it, it2; 182 for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++) 183 { 184 if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 ) 185 error("sendMessage"); 186 } 160 187 } 161 188 }
Note:
See TracChangeset
for help on using the changeset viewer.