// //////////////////////////////////////////////////////////////////////////// // A remote player has left the game bool MultiPlayerLeave(UDWORD playerIndex) { char buf[255]; if (playerIndex >= MAX_PLAYERS) { ASSERT(false, "Bad player number"); return false; } NETlogEntry("Player leaving game", SYNC_FLAG, playerIndex); debug(LOG_NET,"** Player %u [%s], has left the game at game time %u.", playerIndex, getPlayerName(playerIndex), gameTime); ssprintf(buf, _("%s has Left the Game"), getPlayerName(playerIndex)); if (ingame.localJoiningInProgress) { clearPlayer(playerIndex, false); } else if (NetPlay.isHost) // If hosting, and game has started (not in pre-game lobby screen, that is). { sendPlayerLeft(playerIndex); } game.skDiff[playerIndex] = 0; addConsoleMessage(buf, DEFAULT_JUSTIFY, SYSTEM_MESSAGE); if (NetPlay.players[playerIndex].wzFile.isSending) { char buf[256]; ssprintf(buf, _("File transfer has been aborted for %d.") , playerIndex); addConsoleMessage(buf, DEFAULT_JUSTIFY, SYSTEM_MESSAGE); debug(LOG_INFO, "=== File has been aborted for %d ===", playerIndex); NetPlay.players[playerIndex].wzFile.isSending = false; NetPlay.players[playerIndex].needFile = false; } NetPlay.players[playerIndex].kick = true; // Don't wait for GAME_GAME_TIME messages from them. if (widgGetFromID(psWScreen, IDRET_FORM)) { audio_QueueTrack(ID_CLAN_EXIT); } // fire script callback to reassign skirmish players. CBPlayerLeft = playerIndex; eventFireCallbackTrigger((TRIGGER_TYPE)CALL_PLAYERLEFT); netPlayersUpdated = true; return true; }
void HandleBadParam(const char *msg, const int from, const int actual) { char buf[255]; LOBBY_ERROR_TYPES KICK_TYPE = ERROR_INVALID; ssprintf(buf, "!!>Msg: %s, Actual: %d, Bad: %d", msg, actual, from); NETlogEntry(buf, SYNC_FLAG, actual); if (NetPlay.isHost) { ssprintf(buf, "Auto kicking player %s, invalid command received.", NetPlay.players[actual].name); sendTextMessage(buf, true); kickPlayer(actual, buf, KICK_TYPE); } }
// ******************************************************************************************** bool scrSkDoResearch(void) { SDWORD player, bias;//,timeToResearch;//,*x,*y; UWORD i; STRUCTURE *psBuilding; RESEARCH_FACILITY *psResFacilty; if (!stackPopParams(3, ST_STRUCTURE, &psBuilding, VAL_INT, &player, VAL_INT, &bias)) { return false; } psResFacilty = (RESEARCH_FACILITY*)psBuilding->pFunctionality; if(psResFacilty->psSubject != NULL) { // not finshed yet.. return true; } // choose a topic to complete. for(i=0; i < numResearch; i++) { if (skTopicAvail(i, player) && (!bMultiPlayer || !beingResearchedByAlly(i, player))) { break; } } if(i != numResearch) { sendResearchStatus(psBuilding, i, player, true); // inform others, I'm researching this. #if defined (DEBUG) { char sTemp[128]; sprintf(sTemp,"[debug]player:%d starts topic: %s",player, asResearch[i].pName ); NETlogEntry(sTemp, SYNC_FLAG, 0); } #endif } return true; }
// //////////////////////////////////////////////////////////////////////////// BOOL recvBuildFinished(NETQUEUE queue) { uint32_t structId; STRUCTURE *psStruct; Position pos; uint32_t type,typeindex; uint8_t player; NETbeginDecode(queue, GAME_BUILDFINISHED); NETuint32_t(&structId); // get the struct id. NETuint32_t(&type); // Kind of building. NETPosition(&pos); // pos NETuint8_t(&player); NETend(); ASSERT( player < MAX_PLAYERS, "invalid player %u", player); psStruct = IdToStruct(structId,ANYPLAYER); if (psStruct) { // make it complete. psStruct->currentBuildPts = psStruct->pStructureType->buildPoints+1; if (psStruct->status != SS_BUILT) { debug(LOG_SYNC, "Synch error, structure %u was not complete, and should have been.", structId); psStruct->status = SS_BUILT; buildingComplete(psStruct); } debug(LOG_SYNC, "Created normal building %u for player %u", psStruct->id, player); return true; } // The building wasn't started, so we'll have to just plonk it down in the map. // Find the structures stats for (typeindex=0; // Find structure target (typeindex<numStructureStats ) && (asStructureStats[typeindex].ref != type); typeindex++); // Check for similar buildings, to avoid overlaps if (TileHasStructure(mapTile(map_coord(pos.x), map_coord(pos.y)))) { // Get the current structure psStruct = getTileStructure(map_coord(pos.x), map_coord(pos.y)); if (asStructureStats[typeindex].type == psStruct->pStructureType->type) { // Correct type, correct location, just rename the id's to sync it.. (urgh) psStruct->id = structId; psStruct->status = SS_BUILT; buildingComplete(psStruct); debug(LOG_SYNC, "Created modified building %u for player %u", psStruct->id, player); #if defined (DEBUG) NETlogEntry("structure id modified", SYNC_FLAG, player); #endif return true; } } // Build the structure psStruct = buildStructure(&(asStructureStats[typeindex]), pos.x, pos.y, player, true); if (psStruct) { psStruct->id = structId; psStruct->status = SS_BUILT; buildingComplete(psStruct); debug(LOG_SYNC, "Huge synch error, forced to create building %u for player %u", psStruct->id, player); #if defined (DEBUG) NETlogEntry("had to plonk down a building", SYNC_FLAG, player); #endif } else { debug(LOG_SYNC, "Gigantic synch error, unable to create building for player %u", player); NETlogEntry("had to plonk down a building, BUT FAILED!", SYNC_FLAG, player); } return false; }
// //////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////// // Recv Messages. Get a message and dispatch to relevant function. bool recvMessage(void) { NETQUEUE queue; uint8_t type; while (NETrecvNet(&queue, &type) || NETrecvGame(&queue, &type)) // for all incoming messages. { bool processedMessage1 = false; bool processedMessage2 = false; if (queue.queueType == QUEUE_GAME) { syncDebug("Processing player %d, message %s", queue.index, messageTypeToString(type)); } // messages only in game. if(!ingame.localJoiningInProgress) { processedMessage1 = true; switch(type) { case GAME_DROIDINFO: //droid update info recvDroidInfo(queue); break; case NET_TEXTMSG: // simple text message recvTextMessage(queue); break; case NET_DATA_CHECK: recvDataCheck(queue); break; case NET_AITEXTMSG: //multiplayer AI text message recvTextMessageAI(queue); break; case NET_BEACONMSG: //beacon (blip) message recvBeacon(queue); break; case GAME_DROIDDISEMBARK: recvDroidDisEmbark(queue); //droid has disembarked from a Transporter break; case GAME_GIFT: // an alliance gift from one player to another. recvGift(queue); break; case GAME_LASSAT: recvLasSat(queue); break; case GAME_DEBUG_MODE: recvProcessDebugMappings(queue); break; case GAME_DEBUG_ADD_DROID: recvDroid(queue); break; case GAME_DEBUG_ADD_STRUCTURE: recvBuildFinished(queue); break; case GAME_DEBUG_ADD_FEATURE: recvMultiPlayerFeature(queue); break; case GAME_DEBUG_REMOVE_DROID: recvDestroyDroid(queue); break; case GAME_DEBUG_REMOVE_STRUCTURE: recvDestroyStructure(queue); break; case GAME_DEBUG_REMOVE_FEATURE: recvDestroyFeature(queue); break; case GAME_DEBUG_FINISH_RESEARCH: recvResearch(queue); break; default: processedMessage1 = false; break; } } // messages usable all the time processedMessage2 = true; switch(type) { case GAME_TEMPLATE: // new template recvTemplate(queue); break; case GAME_TEMPLATEDEST: // template destroy recvDestroyTemplate(queue); break; case NET_PING: // diagnostic ping msg. recvPing(queue); break; case NET_OPTIONS: recvOptions(queue); break; case NET_PLAYER_DROPPED: // remote player got disconnected { uint32_t player_id; NETbeginDecode(queue, NET_PLAYER_DROPPED); { NETuint32_t(&player_id); } NETend(); if (whosResponsible(player_id) != queue.index && queue.index != NET_HOST_ONLY) { HandleBadParam("NET_PLAYER_DROPPED given incorrect params.", player_id, queue.index); break; } debug(LOG_INFO,"** player %u has dropped!", player_id); if (NetPlay.players[player_id].allocated) { MultiPlayerLeave(player_id); // get rid of their stuff NET_InitPlayer(player_id, false); } NETsetPlayerConnectionStatus(CONNECTIONSTATUS_PLAYER_DROPPED, player_id); break; } case NET_PLAYERRESPONDING: // remote player is now playing { uint32_t player_id; resetReadyStatus(false); NETbeginDecode(queue, NET_PLAYERRESPONDING); // the player that has just responded NETuint32_t(&player_id); NETend(); if (player_id >= MAX_PLAYERS) { debug(LOG_ERROR, "Bad NET_PLAYERRESPONDING received, ID is %d", (int)player_id); break; } // This player is now with us! ingame.JoiningInProgress[player_id] = false; break; } // FIXME: the next 4 cases might not belong here --check (we got two loops for this) case NET_COLOURREQUEST: recvColourRequest(queue); break; case NET_POSITIONREQUEST: recvPositionRequest(queue); break; case NET_TEAMREQUEST: recvTeamRequest(queue); break; case NET_READY_REQUEST: recvReadyRequest(queue); // if hosting try to start the game if everyone is ready if(NetPlay.isHost && multiplayPlayersReady(false)) { startMultiplayerGame(); } break; case GAME_ALLIANCE: recvAlliance(queue, true); break; case NET_KICK: // in-game kick message { uint32_t player_id; char reason[MAX_KICK_REASON]; LOBBY_ERROR_TYPES KICK_TYPE = ERROR_NOERROR; NETbeginDecode(queue, NET_KICK); NETuint32_t(&player_id); NETstring(reason, MAX_KICK_REASON); NETenum(&KICK_TYPE); NETend(); if (player_id == NET_HOST_ONLY) { char buf[250]= {'\0'}; ssprintf(buf, "Player %d (%s : %s) tried to kick %u", (int) queue.index, NetPlay.players[queue.index].name, NetPlay.players[queue.index].IPtextAddress, player_id); NETlogEntry(buf, SYNC_FLAG, 0); debug(LOG_ERROR, "%s", buf); if (NetPlay.isHost) { NETplayerKicked((unsigned int) queue.index); } break; } else if (selectedPlayer == player_id) // we've been told to leave. { debug(LOG_ERROR, "You were kicked because %s", reason); setPlayerHasLost(true); } else { debug(LOG_NET, "Player %d was kicked: %s", player_id, reason); NETplayerKicked(player_id); } break; } case GAME_RESEARCHSTATUS: recvResearchStatus(queue); break; case GAME_STRUCTUREINFO: recvStructureInfo(queue); break; case NET_PLAYER_STATS: recvMultiStats(queue); break; case GAME_PLAYER_LEFT: recvPlayerLeft(queue); break; default: processedMessage2 = false; break; } if (processedMessage1 && processedMessage2) { debug(LOG_ERROR, "Processed %s message twice!", messageTypeToString(type)); } if (!processedMessage1 && !processedMessage2) { debug(LOG_ERROR, "Didn't handle %s message!", messageTypeToString(type)); } NETpop(queue); } return true; }
// //////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////// // MultiPlayer main game loop code. bool multiPlayerLoop(void) { UDWORD i; UBYTE joinCount; joinCount =0; for(i=0;i<MAX_PLAYERS;i++) { if(isHumanPlayer(i) && ingame.JoiningInProgress[i] ) { joinCount++; } } if(joinCount) { setWidgetsStatus(false); bDisplayMultiJoiningStatus = joinCount; // someone is still joining! say So // deselect anything selected. selDroidDeselect(selectedPlayer); if(keyPressed(KEY_ESC) )// check for cancel { bDisplayMultiJoiningStatus = 0; setWidgetsStatus(true); setPlayerHasLost(true); } } else //everyone is in the game now! { if(bDisplayMultiJoiningStatus) { bDisplayMultiJoiningStatus = 0; setWidgetsStatus(true); } if (!ingame.TimeEveryoneIsInGame) { ingame.TimeEveryoneIsInGame = gameTime; debug(LOG_NET, "I have entered the game @ %d", ingame.TimeEveryoneIsInGame ); if (!NetPlay.isHost) { debug(LOG_NET, "=== Sending hash to host ==="); sendDataCheck(); } } if (NetPlay.bComms) { sendPing(); } // Only have to do this on a true MP game if (NetPlay.isHost && !ingame.isAllPlayersDataOK && NetPlay.bComms) { if (gameTime - ingame.TimeEveryoneIsInGame > GAME_TICKS_PER_SEC * 60) { // we waited 60 secs to make sure people didn't bypass the data integrity checks int index; for (index=0; index < MAX_PLAYERS; index++) { if (ingame.DataIntegrity[index] == false && isHumanPlayer(index) && index != NET_HOST_ONLY) { char msg[256] = {'\0'}; sprintf(msg, _("Kicking player %s, because they tried to bypass data integrity check!"), getPlayerName(index)); sendTextMessage(msg, true); addConsoleMessage(msg, LEFT_JUSTIFY, NOTIFY_MESSAGE); NETlogEntry(msg, SYNC_FLAG, index); #ifndef DEBUG kickPlayer(index, "invalid data!", ERROR_INVALID); #endif debug(LOG_WARNING, "Kicking Player %s (%u), they tried to bypass data integrity check!", getPlayerName(index), index); } } ingame.isAllPlayersDataOK = true; } } } // if player has won then process the win effects... if(testPlayerHasWon()) { multiplayerWinSequence(false); } return true; }
// //////////////////////////////////////////////////////////////////////////// BOOL recvBuildFinished(NETMSG *m) { UDWORD strId;//,i; STRUCTURE *psStr; UWORD x,y,z; UDWORD type,typeindex; UBYTE player; NetGet(m,0,strId); // get the struct id. psStr = IdToStruct(strId,ANYPLAYER); if(psStr) { // make it complete. psStr->currentBuildPts = psStr->pStructureType->buildPoints+1; if(psStr->status != SS_BUILT) { psStr->status = SS_BUILT; buildingComplete(psStr); } NETlogEntry("building finished ok." ,0,0); return TRUE; } // the building wasn't started, so we'll have to just plonk it down in the map. NetGet(m,4,type); // kind of building. NetGet(m,8,x); // x pos NetGet(m,10,y); // y pos NetGet(m,12,z); // z pos player = m->body[14]; // player for(typeindex=0; // find structure target (typeindex<numStructureStats ) && (asStructureStats[typeindex].ref != type); typeindex++); psStr = 0; // check for similar buildings, to avoid overlaps if( TILE_HAS_STRUCTURE(mapTile(x>>TILE_SHIFT,y>>TILE_SHIFT)) ) { // get structure; psStr = getTileStructure(x>>TILE_SHIFT, y>>TILE_SHIFT); if(asStructureStats[typeindex].type == psStr->pStructureType->type) { // correct type, correct location, just rename the id's to sync it.. (urgh) psStr->id = strId; psStr->status = SS_BUILT; buildingComplete(psStr); NETlogEntry("structure id modified" ,0,player); return TRUE; } } psStr = buildStructure(&(asStructureStats[typeindex]), // build the structure. x,y, player,TRUE); if (psStr) { psStr->id = strId; psStr->status = SS_BUILT; buildingComplete(psStr); DBCONPRINTF(ConsoleString,(ConsoleString,"MultiPlayer: Struct not found on recvbuildcomplete :%d",strId )); NETlogEntry("had to plonk down a building" ,0,player); } else { DBCONPRINTF(ConsoleString,(ConsoleString,"MultiPlayer: Struct not found on recvbuildcomplete BUILDIT FAILED TOO!:%d",strId )); NETlogEntry("had to plonk down a building, BUT FAILED OH S**T." ,0,player); } return FALSE; }
// //////////////////////////////////////////////////////////////////////////// // receive a check and update the local world state accordingly BOOL recvDroidCheck(NETQUEUE queue) { uint8_t count; int i; uint32_t synchTime; NETbeginDecode(queue, GAME_CHECK_DROID); // Get the number of droids to expect NETuint8_t(&count); NETuint32_t(&synchTime); // Get game time. for (i = 0; i < count; i++) { DROID * pD; PACKAGED_CHECK pc, pc2; Position precPos; NETPACKAGED_CHECK(&pc); // Find the droid in question if (!IdToDroid(pc.droidID, pc.player, &pD)) { NETlogEntry("Recvd Unknown droid info. val=player", SYNC_FLAG, pc.player); debug(LOG_SYNC, "Received checking info for an unknown (as yet) droid. player:%d ref:%d", pc.player, pc.droidID); continue; } syncDebugDroid(pD, '<'); if (pD->gameCheckDroid == NULL) { debug(LOG_SYNC, "We got a droid %u synch, but we couldn't find the droid!", pc.droidID); continue; // Can't synch, since we didn't save data to be able to calculate a delta. } pc2 = *(PACKAGED_CHECK *)pD->gameCheckDroid; // pc2 should be declared here, as const. if (pc2.gameTime != synchTime + MIN_DELAY_BETWEEN_DROID_SYNCHS) { debug(LOG_SYNC, "We got a droid %u synch, but we didn't choose the same droid to synch.", pc.droidID); ((PACKAGED_CHECK *)pD->gameCheckDroid)->gameTime = synchTime + MIN_DELAY_BETWEEN_DROID_SYNCHS; // Get droid synch time back in synch. continue; // Can't synch, since we didn't save data to be able to calculate a delta. } #define MERGECOPY(x, y, z) if (pc.y != pc2.y) { debug(LOG_SYNC, "Droid %u out of synch, changing "#x" from %"z" to %"z".", pc.droidID, x, pc.y); x = pc.y; } #define MERGEDELTA(x, y, z) if (pc.y != pc2.y) { debug(LOG_SYNC, "Droid %u out of synch, changing "#x" from %"z" to %"z".", pc.droidID, x, x + pc.y - pc2.y); x += pc.y - pc2.y; } // player not synched here... precPos = droidGetPrecisePosition(pD); MERGEDELTA(precPos.x, pos.x, "d"); MERGEDELTA(precPos.y, pos.y, "d"); MERGEDELTA(precPos.z, pos.z, "d"); droidSetPrecisePosition(pD, precPos); MERGEDELTA(pD->rot.direction, rot.direction, "d"); MERGEDELTA(pD->rot.pitch, rot.pitch, "d"); MERGEDELTA(pD->rot.roll, rot.roll, "d"); MERGEDELTA(pD->body, body, "u"); if (pD->body > pD->originalBody) { pD->body = pD->originalBody; debug(LOG_SYNC, "Droid %u body was too high after synch, reducing to %u.", pc.droidID, pD->body); } MERGEDELTA(pD->experience, experience, "u"); if (pc.pos.x != pc2.pos.x || pc.pos.y != pc2.pos.y) { // snap droid(if on ground) to terrain level at x,y. if ((asPropulsionStats + pD->asBits[COMP_PROPULSION].nStat)->propulsionType != PROPULSION_TYPE_LIFT) // if not airborne. { pD->pos.z = map_Height(pD->pos.x, pD->pos.y); } } // Doesn't cover all cases, but at least doesn't actively break stuff randomly. switch (pc.order) { case DORDER_MOVE: if (pc.order != pc2.order || pc.orderX != pc2.orderX || pc.orderY != pc2.orderY) { debug(LOG_SYNC, "Droid %u out of synch, changing order from %s to %s(%d, %d).", pc.droidID, getDroidOrderName(pc2.order), getDroidOrderName(pc.order), pc.orderX, pc.orderY); // reroute the droid. orderDroidLoc(pD, pc.order, pc.orderX, pc.orderY, ModeImmediate); } break; case DORDER_ATTACK: if (pc.order != pc2.order || pc.targetID != pc2.targetID) { BASE_OBJECT *obj = IdToPointer(pc.targetID, ANYPLAYER); if (obj != NULL) { debug(LOG_SYNC, "Droid %u out of synch, changing order from %s to %s(%u).", pc.droidID, getDroidOrderName(pc2.order), getDroidOrderName(pc.order), pc.targetID); // remote droid is attacking, not here tho! orderDroidObj(pD, pc.order, IdToPointer(pc.targetID, ANYPLAYER), ModeImmediate); } else { debug(LOG_SYNC, "Droid %u out of synch, would change order from %s to %s(%u), but can't find target.", pc.droidID, getDroidOrderName(pc2.order), getDroidOrderName(pc.order), pc.targetID); } } break; case DORDER_NONE: case DORDER_GUARD: if (pc.order != pc2.order) { DROID_ORDER_DATA sOrder; memset(&sOrder, 0, sizeof(DROID_ORDER_DATA)); sOrder.order = pc.order; debug(LOG_SYNC, "Droid %u out of synch, changing order from %s to %s.", pc.droidID, getDroidOrderName(pc2.order), getDroidOrderName(pc.order)); turnOffMultiMsg(true); moveStopDroid(pD); orderDroidBase(pD, &sOrder); turnOffMultiMsg(false); } break; default: break; // Don't know what to do, but at least won't be actively breaking anything. } MERGECOPY(pD->secondaryOrder, secondaryOrder, "u"); // The old code set this after changing orders, so doing that in case. #undef MERGECOPY #undef MERGEDELTA syncDebugDroid(pD, '>'); // ...and repeat! } NETend(); return true; }
// //////////////////////////////////////////////////////////////////////////// BOOL recvBuildFinished() { uint32_t structId; STRUCTURE *psStruct; int32_t x,y,z; uint32_t type,typeindex; uint8_t player; uint32_t power; NETbeginDecode(NET_BUILDFINISHED); NETuint32_t(&power); // get the player's power level NETuint32_t(&structId); // get the struct id. NETuint32_t(&type); // Kind of building. NETint32_t(&x); // x pos NETint32_t(&y); // y pos NETint32_t(&z); // z pos NETuint8_t(&player); NETend(); ASSERT( player < MAX_PLAYERS, "invalid player %u", player); psStruct = IdToStruct(structId,ANYPLAYER); setPower( (uint32_t)player, power); // we sync the power level as well if (psStruct) { // make it complete. psStruct->currentBuildPts = psStruct->pStructureType->buildPoints+1; if (psStruct->status != SS_BUILT) { psStruct->status = SS_BUILT; buildingComplete(psStruct); } debug(LOG_SYNC, "Created normal building %u for player %u", psStruct->id, player); return true; } // The building wasn't started, so we'll have to just plonk it down in the map. // Find the structures stats for (typeindex=0; // Find structure target (typeindex<numStructureStats ) && (asStructureStats[typeindex].ref != type); typeindex++); // Check for similar buildings, to avoid overlaps if (TileHasStructure(mapTile(map_coord(x), map_coord(y)))) { // Get the current structure psStruct = getTileStructure(map_coord(x), map_coord(y)); if (asStructureStats[typeindex].type == psStruct->pStructureType->type) { // Correct type, correct location, just rename the id's to sync it.. (urgh) psStruct->id = structId; psStruct->status = SS_BUILT; buildingComplete(psStruct); debug(LOG_SYNC, "Created modified building %u for player %u", psStruct->id, player); #if defined (DEBUG) NETlogEntry("structure id modified", SYNC_FLAG, player); #endif return true; } } // Build the structure psStruct = buildStructure(&(asStructureStats[typeindex]), x, y, player, true); if (psStruct) { psStruct->id = structId; psStruct->status = SS_BUILT; buildingComplete(psStruct); debug(LOG_SYNC, "Forced to create building %u for player %u", psStruct->id, player); #if defined (DEBUG) NETlogEntry("had to plonk down a building" ,SYNC_FLAG, player); #endif } else { debug(LOG_SYNC, "Unable to create building for player %u", player); NETlogEntry("had to plonk down a building, BUT FAILED!" , SYNC_FLAG, player); } return false; }
// //////////////////////////////////////////////////////////////////////////// // process clicks made by user. void intProcessMultiMenu(UDWORD id) { UBYTE i; //close if (id == MULTIMENU_CLOSE) { intCloseMultiMenu(); } //alliance button if(id >=MULTIMENU_ALLIANCE_BASE && id<MULTIMENU_ALLIANCE_BASE+MAX_PLAYERS) { i =(UBYTE)( id - MULTIMENU_ALLIANCE_BASE); switch(alliances[selectedPlayer][i]) { case ALLIANCE_BROKEN: requestAlliance((UBYTE)selectedPlayer,i,true,true); // request an alliance break; case ALLIANCE_INVITATION: formAlliance((UBYTE)selectedPlayer,i,true,true,true); // form an alliance break; case ALLIANCE_REQUESTED: breakAlliance((UBYTE)selectedPlayer,i,true,true); // break an alliance break; case ALLIANCE_FORMED: breakAlliance((UBYTE)selectedPlayer,i,true,true); // break an alliance break; default: break; } } //channel opens. if(id >=MULTIMENU_CHANNEL && id<MULTIMENU_CHANNEL+MAX_PLAYERS) { i = id - MULTIMENU_CHANNEL; openchannels[i] = !openchannels[i]; if(mouseDown(MOUSE_RMB) && NetPlay.isHost) // both buttons.... { char buf[250]; // Allow the host to kick the AI only in a MP game, or if they activated cheats in a skirmish game if ((NetPlay.bComms || Cheated) && (NetPlay.players[i].allocated || (NetPlay.players[i].allocated == false && NetPlay.players[i].ai != AI_OPEN))) { inputLoseFocus(); ssprintf(buf, _("The host has kicked %s from the game!"), getPlayerName((unsigned int) i)); sendTextMessage(buf, true); ssprintf(buf, _("kicked %s : %s from the game, and added them to the banned list!"), getPlayerName((unsigned int) i), NetPlay.players[i].IPtextAddress); NETlogEntry(buf, SYNC_FLAG, (unsigned int) i); kickPlayer((unsigned int) i, "you are unwanted by the host.", ERROR_KICKED); return; } } } //radar gifts if(id >= MULTIMENU_GIFT_RAD && id< MULTIMENU_GIFT_RAD +MAX_PLAYERS) { sendGift(RADAR_GIFT, id - MULTIMENU_GIFT_RAD); } // research gift if(id >= MULTIMENU_GIFT_RES && id<MULTIMENU_GIFT_RES +MAX_PLAYERS) { sendGift(RESEARCH_GIFT, id - MULTIMENU_GIFT_RES); } //droid gift if(id >= MULTIMENU_GIFT_DRO && id< MULTIMENU_GIFT_DRO +MAX_PLAYERS) { sendGift(DROID_GIFT, id - MULTIMENU_GIFT_DRO); } //power gift if(id >= MULTIMENU_GIFT_POW && id< MULTIMENU_GIFT_POW +MAX_PLAYERS) { sendGift(POWER_GIFT, id - MULTIMENU_GIFT_POW); } }
// ******************************************************************************************** BOOL scrSkDoResearch(void) { SDWORD structure, player, bias;//,timeToResearch;//,*x,*y; UWORD i; STRING sTemp[128]; STRUCTURE *psBuilding; RESEARCH_FACILITY *psResFacilty; PLAYER_RESEARCH *pPlayerRes; RESEARCH *pResearch; if (!stackPopParams(3,ST_STRUCTURE, &structure, VAL_INT, &player, VAL_INT,&bias )) { return FALSE; } psBuilding = (STRUCTURE *) structure; psResFacilty = (RESEARCH_FACILITY*)psBuilding->pFunctionality; if(psResFacilty->psSubject != NULL) { // not finshed yet.. return TRUE; } // choose a topic to complete. for(i=0;i<numResearch;i++) { if( skTopicAvail(i,player) ) { break; } } if(i != numResearch) { pResearch = (asResearch+i); pPlayerRes = asPlayerResList[player]+ i; psResFacilty->psSubject = (BASE_STATS*)pResearch; //set the subject up if (IsResearchCancelled(pPlayerRes)) { psResFacilty->powerAccrued = pResearch->researchPower;//set up as if all power available for cancelled topics } else { psResFacilty->powerAccrued = 0; } MakeResearchStarted(pPlayerRes); psResFacilty->timeStarted = ACTION_START_TIME; psResFacilty->timeStartHold = 0; psResFacilty->timeToResearch = pResearch->researchPoints / psResFacilty->researchPoints; if (psResFacilty->timeToResearch == 0) { psResFacilty->timeToResearch = 1; } sprintf(sTemp,"player:%d starts topic: %s",player, asResearch[i].pName ); NETlogEntry(sTemp,0,0); } return TRUE; /* // do it. if(i != numResearch) { researchResult(i,(UBYTE)player,FALSE); sprintf(sTemp,"player:%d did topic: %s",player, asResearch[i].pName ); NETlogEntry(sTemp,0,0); SendResearch((UBYTE)player,i ); } // set delay for next topic. timeToResearch = (asResearch+i)->researchPoints / ((RESEARCH_FACILITY*)psResearch->pFunctionality)->researchPoints;; if (!stackPushResult(VAL_INT, timeToResearch)) // return time to do it.. { return FALSE; } */ // UDWORD count; }