/*============================================================================= Name : Alliance.c Purpose : This file handles all of the logic for forming and breaking alliances Created 7/31/1998 by ddunlop Copyright Relic Entertainment, Inc. All rights reserved. =============================================================================*/ #include #include "Alliance.h" #include "gamechat.h" #include "chatting.h" #include "utility.h" #include "universe.h" #include "commandnetwork.h" #include "commandlayer.h" #include "commandwrap.h" #include "strings.h" #include "soundevent.h" /*============================================================================= Data: =============================================================================*/ color allianceMessageColor = colRGB(255,255,255); /*============================================================================= Function prototypes for some private functions: =============================================================================*/ //void alliancePrintNamesNice(char *dest, uword alliance); void allianceRemovePlayerShipsFromAttackList(SelectAnyCommand *list,uword playerindex,CommandToDo *todo); void allianceCancelAttackOrders(uword playerone, uword playertwo); /*============================================================================= Function logic for Alliances: =============================================================================*/ /*----------------------------------------------------------------------------- Name : allianceFormWith Description : sends a request to form an alliance with a player. Inputs : Outputs : Return : void ----------------------------------------------------------------------------*/ void allianceFormWith(udword playerindex) { char temp[256]; // Just request to ally with the person you requested. sprintf(temp, "%s %s", strGetString(strAllianceRequest), playerNames[playerindex]); // alliancePrintNamesNice(temp, (uword)PLAYER_MASK(playerindex)); gcProcessGameTextMessage(temp,allianceMessageColor); sendAllianceRequest(PLAYER_MASK(playerindex),(uword)sigsPlayerIndex,ALLIANCE_PACKET, 0); bitSet(universe.players[sigsPlayerIndex].AllianceProposals, PLAYER_MASK(playerindex)); universe.players[sigsPlayerIndex].AllianceProposalsTimeout = universe.univUpdateCounter + UNIVERSE_UPDATE_RATE * 90; /* // are we in an alliance now ?? if ((universe.players[sigsPlayerIndex].Allies&ALL_PLAYER_MASK)==0) { // no we are not in an alliance // straigtforward request to ally sprintf(temp, "%s ", strGetString(strAllianceRequest)); alliancePrintNamesNice(temp, (uword)PLAYER_MASK(playerindex)); gcProcessGameTextMessage(temp,allianceMessageColor); sendAllianceRequest(PLAYER_MASK(playerindex),(uword)sigsPlayerIndex,ALLIANCE_PACKET, 0); universe.players[sigsPlayerIndex].AllianceProposals=PLAYER_MASK(playerindex); } // do i accept the proposed new ally in our alliance else if (playerindex == universe.players[sigsPlayerIndex].AllianceRequestToConfirm) { // yes i accept him into our allience // send a message to the request initiator telling him of my acceptance. sprintf(temp, "%s ", strGetString(strAllianceConfirm)); alliancePrintNamesNice(temp, (uword)PLAYER_MASK(playerindex)); gcProcessGameTextMessage(temp,allianceMessageColor); sendAllianceRequest(PLAYER_MASK(universe.players[sigsPlayerIndex].AllianceRequestInitiator),(uword)sigsPlayerIndex,ALLIANCE_GRANTED, 0); universe.players[sigsPlayerIndex].AllianceRequestToConfirm = -1; } else { // otherwise i want a new person to join our allience // must ask all of my allies if he can join or not. sprintf(temp, "%s ", strGetString(strAskForPermision)); alliancePrintNamesNice(temp, (uword)PLAYER_MASK(playerindex)); gcProcessGameTextMessage(temp,allianceMessageColor); sendAllianceRequest(universe.players[sigsPlayerIndex].Allies, (uword)sigsPlayerIndex, ALLIANCE_NEWJOIN, (ubyte)playerindex); // save all of the people that must confirm this alliance request. universe.players[sigsPlayerIndex].AllianceConfirms = universe.players[sigsPlayerIndex].Allies; universe.players[sigsPlayerIndex].AllianceRequestToConfirm = (ubyte)playerindex; }*/ } /*----------------------------------------------------------------------------- Name : allianceBreakWith Description : breaks an alliance with a player. Inputs : player to break alliance with Outputs : none Return : void ----------------------------------------------------------------------------*/ void allianceBreakWith(udword playerindex) { if (bitTest(universe.players[sigsPlayerIndex].Allies,PLAYER_MASK(playerindex))) { clWrapSetAlliance(ALLIANCE_BREAKALLIANCE, (uword)sigsPlayerIndex, (uword)playerindex); } } /*----------------------------------------------------------------------------- Name : allianceFormRequestRecievedCB Description : called when a request to from an alliance is recieved. Inputs : alliance packet Outputs : nont Return : void ----------------------------------------------------------------------------*/ void allianceFormRequestRecievedCB(ChatPacket *packet) { char temp[128]; switch (packet->messageType) { case ALLIANCE_PACKET: { if (bitTest(universe.players[sigsPlayerIndex].AllianceProposals, PLAYER_MASK(packet->packetheader.frame))) { bitClear(universe.players[sigsPlayerIndex].AllianceProposals, PLAYER_MASK(packet->packetheader.frame)); clWrapSetAlliance(ALLIANCE_FORMNEWALLIANCE, (uword)sigsPlayerIndex, (uword)packet->packetheader.frame); } else { sprintf(temp,"%s %s",playerNames[packet->packetheader.frame], strGetString(strAsksToFormAlliance)); gcProcessGameTextMessage(temp, allianceMessageColor); } } break; /* OBSOLETE case ALLIANCE_NEWJOIN: { sprintf(temp, "%s %s %s %s",playerNames[packet->packetheader.frame], strGetString(strWants), playerNames[packet->message[0]], strGetString(strToJoin)); gcProcessGameTextMessage(temp,allianceMessageColor); universe.players[sigsPlayerIndex].AllianceRequestToConfirm = (uword)packet->message[0]; universe.players[sigsPlayerIndex].AllianceRequestInitiator = (uword)packet->packetheader.frame; } break; case ALLIANCE_GRANTED: { if (bitTest(universe.players[sigsPlayerIndex].AllianceConfirms,PLAYER_MASK(packet->packetheader.frame))) { bitClear(universe.players[sigsPlayerIndex].AllianceConfirms,PLAYER_MASK(packet->packetheader.frame)); if (universe.players[sigsPlayerIndex].AllianceConfirms==0) { sendAllianceRequest(PLAYER_MASK(universe.players[sigsPlayerIndex].AllianceRequestToConfirm),(uword)sigsPlayerIndex,ALLIANCE_PACKET, 0); universe.players[sigsPlayerIndex].AllianceProposals=PLAYER_MASK(universe.players[sigsPlayerIndex].AllianceRequestToConfirm); universe.players[sigsPlayerIndex].AllianceRequestToConfirm = -1; } } } break; /* //obsolete Now case ALLIANCE_RUTRANSFER: universe.players[sigsPlayerIndex].resourceUnits += packet->data; break; */ } } /*----------------------------------------------------------------------------- Name : alliancePrintNamesNice Description : returns a string witht the player names printed nicely. Inputs : The string to print to, and the alliance.s Outputs : Return : void ----------------------------------------------------------------------------*/ void alliancePrintNamesNice(char *dest, uword alliance) { udword i,j,index,numallies=0; for (i=0;i= 2) { for (j=0,index=0;jnumTargets;index++) { if ((list->TargetPtr[index]->objtype == OBJ_ShipType) && ( ((Ship *)list->TargetPtr[index])->playerowner->playerIndex == playerindex ) ) { RemoveAttackTargetFromExtraAttackInfo(list->TargetPtr[index],todo); list->numTargets--; list->TargetPtr[index] = list->TargetPtr[list->numTargets]; } } } void allianceCancelAttackOrders(uword playerone, uword playertwo) { Node *search; CommandToDo *todo; search = universe.mainCommandLayer.todolist.head; while (search != NULL) { todo = (CommandToDo *)listGetStructOfNode(search); if ( (todo->ordertype.order == COMMAND_ATTACK) || (todo->ordertype.attributes & COMMAND_IS_PASSIVEATTACKING) ) { dbgAssert(todo->selection->ShipPtr[0] != NULL); //if attack command contains player one ships if (todo->selection->ShipPtr[0]->playerowner->playerIndex == playerone) { allianceRemovePlayerShipsFromAttackList(todo->attack,playertwo,todo); } else if (todo->selection->ShipPtr[0]->playerowner->playerIndex == playertwo) { allianceRemovePlayerShipsFromAttackList(todo->attack,playerone,todo); } } search = search->next; } } /*----------------------------------------------------------------------- Name : allianceBreakAll Description : This function will break all aliances that this player has. Inputs : none Outputs : none Parameters : none Return : void -----------------------------------------------------------------------*/ void allianceBreakAll(void) { udword i; for (i=0;iplayerowner == player) || (bitTest(ship->attributes, ATTRIBUTES_Defector))) { return TRUE; // always considered ally with yourself } return(bitTest(player->Allies, PLAYER_MASK(ship->playerowner->playerIndex))); } /*----------------------------------------------------------------------------- Name : allianceArePlayersAllied Description : Returns true if these two players are alied. Inputs : ship, playerptr Outputs : true, false Return : bool ----------------------------------------------------------------------------*/ bool allianceArePlayersAllied(Player *playerone, Player *playertwo) { if (playerone == playertwo) { return TRUE; // always considered ally with yourself } return(bitTest(playerone->Allies, PLAYER_MASK(playertwo->playerIndex))); }