- Timestamp:
- May 25, 2013, 9:37:47 PM (12 years ago)
- Branches:
- master
- Children:
- 5299436
- Parents:
- e4c60ba
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
server/server.cpp
re4c60ba r7553db9 165 165 WorldMap::ObjectType flagType; 166 166 POSITION pos; 167 bool flagTurnedIn = false; 168 167 169 switch(gameMap->getStructure(it->second.pos.x/25, it->second.pos.y/25)) { 168 170 case WorldMap::STRUCTURE_BLUE_FLAG: 169 171 { 170 if (!it->second.team == 0 || !it->second.hasRedFlag) 171 break; 172 else { 172 if (it->second.team == 0 && it->second.hasRedFlag) 173 { 173 174 it->second.hasRedFlag = false; 174 175 flagType = WorldMap::OBJECT_RED_FLAG; 175 176 pos = gameMap->getStructureLocation(WorldMap::STRUCTURE_RED_FLAG); 177 flagTurnedIn = true; 176 178 } 179 180 break; 177 181 } 178 182 case WorldMap::STRUCTURE_RED_FLAG: 179 183 { 180 if (!it->second.team == 1 || !it->second.hasBlueFlag) 181 break; 182 else { 184 if (it->second.team == 1 && it->second.hasBlueFlag) 185 { 183 186 it->second.hasBlueFlag = false; 184 187 flagType = WorldMap::OBJECT_BLUE_FLAG; 185 188 pos = gameMap->getStructureLocation(WorldMap::STRUCTURE_BLUE_FLAG); 189 flagTurnedIn = true; 186 190 } 187 188 // all code from here to the break is executed for both cases of the switch189 190 // send an OBJECT message to add the flag back to its spawn point191 pos.x = pos.x*25+12;192 pos.y = pos.y*25+12;193 gameMap->addObject(flagType, pos.x, pos.y);194 195 serverMsg.type = MSG_TYPE_OBJECT;196 gameMap->getObjects()->back().serialize(serverMsg.buffer);197 198 map<unsigned int, Player>::iterator it2;199 for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)200 {201 if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )202 error("sendMessage");203 }204 205 // this means a PLAYER message will be send206 broadcastMove = true;207 191 208 192 break; 209 193 } 210 default: 211 break; 194 } 195 196 if (flagTurnedIn) { 197 // send an OBJECT message to add the flag back to its spawn point 198 pos.x = pos.x*25+12; 199 pos.y = pos.y*25+12; 200 gameMap->addObject(flagType, pos.x, pos.y); 201 202 serverMsg.type = MSG_TYPE_OBJECT; 203 gameMap->getObjects()->back().serialize(serverMsg.buffer); 204 205 map<unsigned int, Player>::iterator it2; 206 for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++) 207 { 208 if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 ) 209 error("sendMessage"); 210 } 211 212 // this means a PLAYER message will be sent 213 broadcastMove = true; 212 214 } 213 215 … … 217 219 for (itObjects = vctObjects->begin(); itObjects != vctObjects->end();) { 218 220 POSITION pos = itObjects->pos; 221 bool gotFlag = false; 222 219 223 if (posDistance(it->second.pos, pos.toFloat()) < 10) { 220 224 switch (itObjects->type) { 221 225 case WorldMap::OBJECT_BLUE_FLAG: 222 cout << "Got blue flag" << endl; 223 it->second.hasBlueFlag = true; 224 broadcastMove = true; 226 if (it->second.team == 1) { 227 gotFlag = true; 228 it->second.hasBlueFlag = true; 229 broadcastMove = true; 230 } 225 231 break; 226 232 case WorldMap::OBJECT_RED_FLAG: 227 cout << "Got red flag" << endl; 228 it->second.hasRedFlag = true; 229 broadcastMove = true; 233 if (it->second.team == 0) { 234 gotFlag = true; 235 it->second.hasRedFlag = true; 236 broadcastMove = true; 237 } 230 238 break; 231 239 } 232 240 233 serverMsg.type = MSG_TYPE_REMOVE_OBJECT; 234 memcpy(serverMsg.buffer, &itObjects->id, 4); 235 236 map<unsigned int, Player>::iterator it2; 237 for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++) 238 { 239 if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 ) 240 error("sendMessage"); 241 if (gotFlag) { 242 serverMsg.type = MSG_TYPE_REMOVE_OBJECT; 243 memcpy(serverMsg.buffer, &itObjects->id, 4); 244 245 map<unsigned int, Player>::iterator it2; 246 for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++) 247 { 248 if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 ) 249 error("sendMessage"); 250 } 251 252 // remove the object from the server-side map 253 cout << "size before: " << gameMap->getObjects()->size() << endl; 254 itObjects = vctObjects->erase(itObjects); 255 cout << "size after: " << gameMap->getObjects()->size() << endl; 241 256 } 242 243 // remove the object from the server-side map244 cout << "size before: " << gameMap->getObjects()->size() << endl;245 itObjects = vctObjects->erase(itObjects);246 cout << "size after: " << gameMap->getObjects()->size() << endl;247 257 } 248 else 249 258 259 itObjects++; 250 260 } 251 261
Note:
See TracChangeset
for help on using the changeset viewer.