int _stdcall Logistics::beginMission(void*, int, void*[]) { if (MPlayer) MPlayer->setMode(MULTIPLAYER_MODE_LOADING); char commandersToLoad[MAX_MC_PLAYERS][3] = {{0, 0, 0}, {1, 1, 1}, {2, 2, 2}, {3, 3, 3}, {4, 4, 4}, {5, 5, 5}, {6, 6, 6}, {7, 7, 7}}; long missionLoadType = LogisticsData::instance->skipLogistics() ? MISSION_LOAD_SP_QUICKSTART : MISSION_LOAD_SP_LOGISTICS; if (MPlayer) { //--------------------------- // Calc valid commanderIDs... long curCommanderID = 0; for (long CID = 0; CID < MAX_MC_PLAYERS; CID++) { MPlayer->availableCIDs[CID] = true; if (MPlayer->playerInfo[CID].player && (MPlayer->playerInfo[CID].commanderID > -1)) { if (CID != curCommanderID) { long oldCommanderID = CID; MPlayer->playerInfo[CID].commanderID = curCommanderID; memcpy(&MPlayer->playerInfo[curCommanderID], &MPlayer->playerInfo[CID], sizeof(MC2Player)); MPlayer->playerInfo[CID].player = NULL; MPlayer->playerInfo[CID].commanderID = -1; for (long j = 0; j < MAX_MC_PLAYERS; j++) if (MPlayer->playerList[j].player == MPlayer->playerInfo[curCommanderID].player) MPlayer->playerList[j].commanderID = curCommanderID; if (oldCommanderID == MPlayer->commanderID) MPlayer->commanderID = curCommanderID; } MPlayer->availableCIDs[curCommanderID] = false; curCommanderID++;; } } //---------------------- // Calc valid teamIDs... long curTeamID = 0; for (long teamID = 0; teamID < MAX_MC_PLAYERS; teamID++) { bool teamFound = false; for (long i = 0; i < MAX_MC_PLAYERS; i++) if (MPlayer->playerInfo[i].player && (MPlayer->playerInfo[i].team == teamID)) { MPlayer->playerInfo[i].team = curTeamID; teamFound = true; } if (teamFound) curTeamID++; } if (MPlayer->isHost()) { // Determine drop zone order here... char dropZoneList[8]; char hqs[MAX_TEAMS]; if (MPlayer->missionSettings.missionType == MISSION_TYPE_OTHER) { bool goodToLoad = mission->calcComplexDropZones((char*)(const char*)LogisticsData::instance->getCurrentMission(), dropZoneList); if (!goodToLoad) STOP(("Logisitics.beginMission: teams do not match up for complex mission")); for (long i = 0; i < MAX_TEAMS; i++) hqs[i] = i; } else MPlayer->calcDropZones(dropZoneList, hqs); if (MPlayer->missionSettings.quickStart) for (long i = 0; i < MAX_MC_PLAYERS; i++) { MPlayer->commandersToLoad[i][0] = (long)dropZoneList[i]; //MPlayer->playerInfo[i].commanderID; MPlayer->commandersToLoad[i][1] = (long)(dropZoneList[i] > -1) ? MPlayer->playerInfo[dropZoneList[i]].team : 0; MPlayer->commandersToLoad[i][2] = hqs[i]; } else for (long i = 0; i < MAX_MC_PLAYERS; i++) { MPlayer->commandersToLoad[i][0] = dropZoneList[i]; //-1; MPlayer->commandersToLoad[i][1] = (dropZoneList[i] > -1) ? MPlayer->playerInfo[dropZoneList[i]].team : 0; //-1; MPlayer->commandersToLoad[i][2] = hqs[i]; } MPlayer->sendMissionSetup(0, 0, NULL); } if (!MPlayer->waitTillStartLoading()) { // SERVER DROPPED return(0); } if (MPlayer->commandersToLoad[0][0] < -1) PAUSE(("Logistics.beginMission: bad commandersToLoad")); for (long i = 0; i < MAX_MC_PLAYERS; i++) { commandersToLoad[i][0] = MPlayer->commandersToLoad[i][0]; commandersToLoad[i][1] = MPlayer->commandersToLoad[i][1]; commandersToLoad[i][2] = MPlayer->commandersToLoad[i][2]; } if (MPlayer->missionSettings.quickStart) { MultiPlayTeamId = MPlayer->playerInfo[MPlayer->commanderID].team; if (MultiPlayTeamId < 0) STOP(("Bad commanderID")); MultiPlayCommanderId = MPlayer->commanderID; if (MultiPlayCommanderId < 0) STOP(("Bad commanderID")); missionLoadType = MISSION_LOAD_MP_QUICKSTART; } else { MultiPlayTeamId = MPlayer->playerInfo[MPlayer->commanderID].team; MultiPlayCommanderId = MPlayer->commanderID; missionLoadType = MISSION_LOAD_MP_LOGISTICS; } long maxTeam = -1; for (i = 0; i < MAX_MC_PLAYERS; i++) if (MPlayer->playerInfo[i].team > maxTeam) maxTeam = MPlayer->playerInfo[i].team; MPlayer->numTeams = maxTeam + 1; } else if (missionLoadType == MISSION_LOAD_SP_LOGISTICS) { commandersToLoad[0][0] = -1; commandersToLoad[0][1] = -1; commandersToLoad[0][2] = -1; } else { commandersToLoad[0][0] = 0; commandersToLoad[0][1] = 0; commandersToLoad[0][2] = -1; } if (mission) mission->destroy(); long numPlayers = 1; if ( MPlayer ) MPlayer->getPlayers(numPlayers); long numMoversPerCommander[MAX_MC_PLAYERS] = {12, 12, 12, 9, 7, 6, 5, 4}; Stuff::Vector3D dropZoneList[255]; // ubsurdly large, but sometimes we overrun this. long dropZoneID = 0; if (MPlayer) { //dropZoneID = MPlayer->commanderID; for (long i = 0; i < MAX_MC_PLAYERS; i++) if (commandersToLoad[i][0] == MPlayer->commanderID) { dropZoneID = i; break; } useUnlimitedAmmo = MPlayer->missionSettings.unlimitedAmmo; } mission->init((char*)(const char*)LogisticsData::instance->getCurrentMission(), missionLoadType, dropZoneID, dropZoneList, commandersToLoad, numMoversPerCommander[numPlayers - 1]); LogisticsData::instance->rpJustAdded = 0; if (MPlayer) { if (missionLoadType == MISSION_LOAD_MP_LOGISTICS) { EList< LogisticsMech*, LogisticsMech* > list; LogisticsData::instance->getForceGroup(list); long dropZoneIndex = 0; long numMechs = 0; for (EList< LogisticsMech*, LogisticsMech* >::EIterator iter = list.Begin(); !iter.IsDone(); iter++) { numMechs++; if ( !(*iter)->getPilot() ) continue; CompressedMech mechData; mechData.lastMech = (list.Count() == numMechs); mechData.objNumber = (*iter)->getFitID(); mechData.commanderID = MPlayer->commanderID; mechData.baseColor = MPlayer->colors[MPlayer->playerInfo[MPlayer->commanderID].baseColor[BASECOLOR_TEAM]]; mechData.highlightColor1 = MPlayer->colors[MPlayer->playerInfo[MPlayer->commanderID].stripeColor]; mechData.highlightColor2 = MPlayer->colors[MPlayer->playerInfo[MPlayer->commanderID].stripeColor]; strcpy(mechData.pilotFile, (*iter)->getPilot()->getFileName()); strcpy(mechData.mechFile, (*iter)->getFileName()); strcpy(mechData.variantName, (*iter)->getName()); mechData.variantNum = (*iter)->getVariant()->getFileID(); mechData.cBills = (*iter)->getVariant()->getCost(); mechData.pos[0] = dropZoneList[dropZoneIndex].x; mechData.pos[1] = dropZoneList[dropZoneIndex++].y; mechData.designerMech = (*iter)->getVariant()->isDesignerMech(); mechData.numComponents = (*iter)->getComponentCount(); if (mechData.numComponents) { long* componentList = (long*)systemHeap->Malloc(sizeof(long) * mechData.numComponents); long otherCount = mechData.numComponents; (*iter)->getComponents(otherCount, componentList); if (otherCount != mechData.numComponents) STOP(("Heidi's getComponentCount does not agree with count returned from getComponents")); for (long i = 0; i < mechData.numComponents; i++) mechData.components[i] = (unsigned char)componentList[i]; } MPlayer->sendMissionSetup(0, 1, &mechData); } if (!MPlayer->waitTillMechDataReceived()) { // SERVER DROPPED mission->destroy(); return(0); } ObjectManager->numMechs = 0; ObjectManager->numVehicles = 0; for (long i = 0; i < MAX_MC_PLAYERS; i++) { if (MPlayer->mechDataReceived[i]) { for (long j = 0; j < 12; j++) { if (MPlayer->mechData[i][j].objNumber > -1) { MoverInitData data; memset(&data, 0, sizeof(MoverInitData)); data.objNumber = MPlayer->mechData[i][j].objNumber; data.rosterIndex = 255; data.controlType = 2; data.controlDataType = 1; data.position.x = MPlayer->mechData[i][j].pos[0]; data.position.y = MPlayer->mechData[i][j].pos[1]; data.position.z = 0.0; data.rotation = 0; data.teamID = MPlayer->playerInfo[MPlayer->mechData[i][j].commanderID].team; data.commanderID = MPlayer->mechData[i][j].commanderID; data.baseColor = MPlayer->mechData[i][j].baseColor; data.highlightColor1 = MPlayer->mechData[i][j].highlightColor1; data.highlightColor2 = MPlayer->mechData[i][j].highlightColor2; data.gestureID = 2; data.active = 1; data.exists = 1; data.capturable = 0; data.icon = 0; strcpy(data.pilotFileName, MPlayer->mechData[i][j].pilotFile); strcpy(data.brainFileName, "pbrain"); strcpy(data.csvFileName, MPlayer->mechData[i][j].mechFile); data.numComponents = MPlayer->mechData[i][j].numComponents; for (long k = 0; k < MPlayer->mechData[i][j].numComponents; k++) data.components[k] = MPlayer->mechData[i][j].components[k]; long moverHandle = mission->addMover(&data); if (moverHandle < 1) STOP(("Logistics.beginMission: unable to addMover")); MoverPtr mover = (MoverPtr)ObjectManager->get(moverHandle); if (!mover) STOP(("Logistics.beginMission: NULL mover")); if (mover->getObjectClass() != BATTLEMECH) STOP(("Logistics.beginMission: not a mech")); ((BattleMech*)mover)->cBills = MPlayer->mechData[i][j].cBills; strcpy(((BattleMech*)mover)->variantName, MPlayer->mechData[i][j].variantName); data.variant = MPlayer->mechData[i][j].variantNum; } } } } } else // gotta update pilot availability { long count = 256; LogisticsPilot* pilots[256]; LogisticsData::instance->getPilots( pilots, count ); for ( int i = 0; i < count; i++ ) { pilots[i]->setUsed(0); } Team* pTeam = Team::home; if ( pTeam ) { for ( i = pTeam->getRosterSize() - 1; i > -1; i-- ) { Mover* pMover = (Mover*)pTeam->getMover( i ); if ( pMover && pMover->getCommander()->getId() == Commander::home->getId() ) { LogisticsPilot* pPilot = LogisticsData::instance->getPilot( pMover->getPilot()->getName() ); if ( pPilot ) pPilot->setUsed( true ); } } } } CompressedMech mechData; mechData.commanderID = MPlayer->commanderID; MPlayer->sendMissionSetup(0, 2, &mechData); if (!MPlayer->waitTillMissionLoaded()) { // SERVER DROPPED mission->destroy(); return(0); } } else if (missionLoadType == MISSION_LOAD_SP_LOGISTICS) { EList< LogisticsMech*, LogisticsMech* > list; LogisticsData::instance->getForceGroup( list ); float rotation = list.Count() ? 360.f/list.Count() : 0.f; MoverInitData data; memset( &data, 0, sizeof( data ) ); data.rosterIndex = 255; data.controlType = 2; data.controlDataType = 1; data.position.Zero(); // need to get the drop zone location data.rotation = 0; data.teamID = Team::home->getId(); data.commanderID = Team::home->getId(); data.active = 1; data.exists = 1; data.capturable = 0; data.baseColor = prefs.baseColor; data.highlightColor1 = prefs.highlightColor; data.highlightColor2 = prefs.highlightColor; strcpy( data.pilotFileName, "pmw00031" ); strcpy( data.brainFileName, "pbrain" ); Stuff::Vector3D vector; vector.x = 0.f; vector.y = 1.f; vector.z = 0.f; Stuff::Vector3D scaled; for ( EList< LogisticsMech*, LogisticsMech* >::EIterator iter = list.Begin(); !iter.IsDone(); iter++) { scaled = vector; scaled *= 128.; data.position.Add(dropZoneList[0], scaled); //data.position = dropZoneList[dropZoneIndex++]; data.objNumber = (*iter)->getFitID(); strcpy( data.csvFileName, (*iter)->getFileName() ); if ( !(*iter)->getPilot() ) continue; strcpy( data.pilotFileName, (*iter)->getPilot()->getFileName() ); data.overrideLoadedPilot = true; data.gunnerySkill = (*iter)->getPilot()->getGunnery(); data.pilotingSkill = (*iter)->getPilot()->getPiloting(); memcpy(data.specialtySkills,(*iter)->getPilot()->getSpecialtySkills(),sizeof(bool) * NUM_SPECIALTY_SKILLS); if ( !(*iter)->getVariant()->isDesignerMech()) { data.variant = 0; mission->addMover( &data, (*iter)); } else { data.variant = (*iter)->getVariant()->getFileID(); mission->addMover( &data ); } Rotate( vector, rotation ); } } /* if (MPlayer) { if (MPlayer->isHost()) MPlayer->serverCID = MPlayer->commanderID; else { for (long i = 0; i < MAX_MC_PLAYERS; i++) if (MPlayer->serverPlayer && (MPlayer->playerList[i].player == MPlayer->serverPlayer)) MPlayer->serverCID = MPlayer->playerList[i].commanderID; if (MPlayer->serverCID == -1) STOP(("Logistics.beginMission: bad serverCID")); } } */ mission->missionInterface->initMechs(); eye->activate(); eye->update(); mission->start(); mission->update(); // force this, so we don't render first if (MPlayer) { CompressedMech mechData; mechData.commanderID = MPlayer->commanderID; MPlayer->sendMissionSetup(0, 4, &mechData); if (!MPlayer->waitTillMissionSetup()) { // SERVER DROPPED mission->destroy(); return(0); } MPlayer->setMode(MULTIPLAYER_MODE_MISSION); } if (MPlayer && MPlayer->hostLeft) { mission->destroy(); return(0); } return(1); }
void MechBayScreen::reinitMechs() { int count = 0; int maxUnits = 12; if ( MPlayer ) { long playerCount; MPlayer->getPlayers( playerCount ); if ( playerCount ) maxUnits = MAX_MULTIPLAYER_MECHS_IN_LOGISTICS/playerCount; if ( maxUnits > 12 ) maxUnits = 12; } for ( int j = 0; j < ICON_COUNT_Y; j++ ) { for ( int i = 0; i < ICON_COUNT_X; i++ ) { pIcons[count].setMech( 0 ); if ( count >= maxUnits ) pIcons[count].disable( true ); else pIcons[count].disable( 0 ); count++; } } forceGroupCount = 0; // initialize both the inventory and icon lists EList< LogisticsMech*, LogisticsMech* > mechList; LogisticsData::instance->getInventory( mechList ); for ( EList< LogisticsMech*, LogisticsMech* >::EIterator iter = mechList.Begin(); !iter.IsDone(); iter++ ) { if ( (*iter)->getForceGroup() ) { long FG = (*iter)->getForceGroup(); if ( FG <= maxUnits ) { pIcons[FG-1].setMech( (*iter) ); pIcons[FG-1].setPilot( (*iter)->getPilot() ); forceGroupCount++; } else (*iter)->setForceGroup( 0 ); } } }
void MechPurchaseScreen::begin() { variantListBox.removeAllItems(true); inventoryListBox.removeAllItems(true); // initialize both the inventory and icon lists EList< LogisticsMech*, LogisticsMech* > mechList; LogisticsData::instance->getInventory(mechList); prevInventory.Clear(); LogisticsMech* pSelMech = 0; oldCBillsAmount = LogisticsData::instance->getCBills(); for(EList< LogisticsMech*, LogisticsMech* >::EIterator iter = mechList.Begin(); !iter.IsDone(); iter++) { if((*iter)->getForceGroup()) continue; prevInventory.Append(*(*iter)); bool bFound = 0; for(size_t i = 0; i < inventoryListBox.GetItemCount(); i++) { if(((MechListBoxItem*)inventoryListBox.GetItem(i))->getMech()->getVariant() == (*iter)->getVariant()) bFound = true; } if(!bFound) { MechListBoxItem* item = new MechListBoxItem((*iter), 1); inventoryListBox.AddItem(item); } } MechListBoxItem* item = (MechListBoxItem*)inventoryListBox.GetItem(0); if(item) { inventoryListBox.SelectItem(0); pSelMech = item->getMech(); } LogisticsVariant* pVariants[256]; int32_t count = 256; LogisticsData::instance->getPurchasableMechs(pVariants, count); for(size_t i = 0; i < count; i++) { if(!MPlayer || MPlayer->missionSettings.variants || pVariants[i]->isDesignerMech()) { LogisticsMech* pMech = new LogisticsMech(pVariants[i], -1); MechListBoxItem* item = new MechListBoxItem(pMech, 1); variantListBox.AddItem(item); } } if(!pSelMech) { MechListBoxItem* item = (MechListBoxItem*)variantListBox.GetItem(0); if(item) { variantListBox.SelectItem(0); pSelMech = item->getMech(); } } status = RUNNING; acceptPressed = 0; inventoryListBox.drawCBills(1); variantListBox.drawCBills(1); variantListBox.setOrange(0); inventoryListBox.setOrange(1); setMech(pSelMech); pDragMech = nullptr; }
void MechBayScreen::begin() { status = RUNNING; pDragMech = NULL; mechListBox.removeAllItems( true ); reinitMechs(); int mechCount[256]; memset( mechCount, 0, sizeof ( int ) * 256 ); bool bCurMechIsValid = 0; // initialize both the inventory and icon lists EList< LogisticsMech*, LogisticsMech* > mechList; LogisticsData::instance->getInventory( mechList ); for ( EList< LogisticsMech*, LogisticsMech* >::EIterator iter = mechList.Begin(); !iter.IsDone(); iter++ ) { if ( *iter == pCurMech ) bCurMechIsValid = true; if ( !(*iter)->getForceGroup() ) { bool bFound = 0; for ( int i = 0; i < mechListBox.GetItemCount(); i++ ) { if ( ((MechListBoxItem*)mechListBox.GetItem(i))->getMech()->getVariant() == (*iter)->getVariant() ) bFound = true; } if ( !bFound ) { MechListBoxItem* item = new MechListBoxItem( (*iter), 1 ); mechListBox.AddItem( item ); } } } // reset the old mech to NULL to make sure everything gets set mechListBox.drawCBills( 0 ); mechListBox.setOrange( true ); if ( !pCurMech || !bCurMechIsValid ) { if ( !selectFirstFGItem() ) { if ( !selectFirstViableLBMech() ) setMech( NULL ); } } else { LogisticsMech* pMech = pCurMech; setMech( NULL ); // need to make sure the guy is still running setMech( pMech ); bool bFound = 0; for ( int i = 0; i < mechListBox.GetItemCount(); i++ ) { MechListBoxItem* pItem = (MechListBoxItem*)mechListBox.GetItem( i ); if ( pItem && pItem->getMech() == pCurMech ) { mechListBox.SelectItem( i ); bFound = true; } } if ( !bFound ) { for ( int i = 0; i < ICON_COUNT; i++ ) { if ( pIcons[i].getMech() == pMech ) { pIcons[i].select( true ); break; } } } } }
void PilotReadyScreen::begin() { getButton( MB_MSG_PREV )->disable( false ); getButton( MB_MSG_MAINMENU )->disable( false ); launchFadeTime = 0; // initialize both the inventory and icon lists EList< LogisticsMech*, LogisticsMech* > mechList; LogisticsData::instance->getInventory( mechList ); // reset force group forceGroupCount = 0; int maxUnits = 12; if ( MPlayer ) { long playerCount; MPlayer->getPlayers( playerCount ); if ( playerCount ) maxUnits = MAX_MULTIPLAYER_MECHS_IN_LOGISTICS/playerCount; if ( maxUnits > 12 ) maxUnits = 12; } for ( int i = 0; i < 12; i++ ) { pIcons[i].setMech( 0 ); pIcons[i].select( 0 ); if ( i >= maxUnits ) pIcons[i].disable( 1 ); else pIcons[i].disable( 0 ); } if ( getButton( MB_MSG_MAINMENU ) ) getButton( MB_MSG_MAINMENU )->setPressFX( -1 ); int bHasPilot = -1; // update pilot use here... things can get screwed up. pilotListBox.removeAllItems( true ); long count = 256; LogisticsPilot* pilots[256]; LogisticsData::instance->getPilots( pilots, count ); for ( i = 0; i < count; i++ ) { pilots[i]->setUsed(0); } for ( EList< LogisticsMech*, LogisticsMech* >::EIterator iter = mechList.Begin(); !iter.IsDone(); iter++ ) { if ( (*iter)->getForceGroup() ) { long FG = (*iter)->getForceGroup(); pIcons[FG-1].setMech( (*iter) ); if ( (*iter)->getPilot() ) { (*iter)->getPilot()->setUsed( true ); pIcons[FG-1].setPilot( (*iter)->getPilot() ); bHasPilot = FG - 1; } forceGroupCount++; } } for ( i = 0; i < count; i++ ) { if ( !pilots[i]->isUsed() && pilots[i]->isAvailable() ) { pilotListBox.AddItem( new LogisticsPilotListBoxItem( pilots[i] ) ); } } status = RUNNING; if ( bHasPilot != -1 ) { pIcons[bHasPilot].select( true ); setPilot( pIcons[bHasPilot].getPilot() ); } else { LogisticsPilotListBoxItem* pItem = ( LogisticsPilotListBoxItem*)pilotListBox.GetItem( 0 ); if ( pItem ) { pilotListBox.SelectItem( 0 ); setPilot( pItem->getPilot() ); } pIcons[0].select( true ); } }