/*----------------------------------------------------------------------------- Name : aihHarassTeamDiedHandler Description : Restarts the harass team Inputs : team - the team that died Outputs : Deletes all the previous moves and creates new ones Return : void ----------------------------------------------------------------------------*/ void aihHarassTeamDiedHandler(struct AITeam *team) { if (!bitTest(team->teamFlags, AIT_Reissue01)) { bitSet(team->teamFlags, AIT_Reissue01); } else { if (!bitTest(team->teamFlags, AIT_Reissue10)) { bitSet(team->teamFlags, AIT_Reissue10); } else { // if we've tried harass teams twice, destroy the team bitClear(team->teamFlags, AIT_Reissue10|AIT_Reissue01); bitSet(team->teamFlags, AIT_DestroyTeam); return; } } if (randyrandom(RAN_AIPlayer, 4)) { // retry this puppy aitDeleteAllTeamMoves(team); aioCreateHarass(team); } else { bitSet(team->teamFlags, AIT_DestroyTeam); } }
/*----------------------------------------------------------------------------- Name : rmTechRequiredForShip Description : This function returns the number of research topics required to build the ship specified Inputs : player and shiptype Outputs : number of research topics required Return : sdword ----------------------------------------------------------------------------*/ sdword rmTechRequiredForShip(Player *player, ShipType type) { sdword i, numtech=0; udword techneeded, temp; temp = player->researchinfo.techstat->TechNeededToBuildShip[type]; techneeded = temp; for (i=0; i<NumTechnologies; i++) { if (bitTest(temp, TechToBit(i))) { techneeded |= rmAllTechRequiredforTech(player, i); } } techneeded &= (~player->researchinfo.HasTechnology); for (i=0; i<NumTechnologies; i++) { if (bitTest(techneeded, TechToBit(i))) { numtech++; } } return (numtech); }
/*----------------------------------------------------------------------------- Name : allianceIsShipAlly Description : Returns true if you are allied with a ship. Inputs : ship, playerptr Outputs : true, false Return : bool ----------------------------------------------------------------------------*/ bool allianceIsShipAlly(Ship *ship, Player *player) { if ((ship->playerowner == player) || (bitTest(ship->attributes, ATTRIBUTES_Defector))) { return TRUE; // always considered ally with yourself } return(bitTest(player->Allies, PLAYER_MASK(ship->playerowner->playerIndex))); }
void CloakAddObjectsInProximity(Ship *cloakship) { Player *playerowner = cloakship->playerowner; Node *objnode = universe.ShipList.head; udword num = universe.ShipList.num; CloakGeneratorStatics *cloakgeneratorstatics; CloakGeneratorSpec *spec = (CloakGeneratorSpec *)cloakship->ShipSpecifics; //maybe don't need Ship *spaceobj; real32 distanceSqr; vector diff; cloakgeneratorstatics = (CloakGeneratorStatics *) ((ShipStaticInfo *)(cloakship->staticinfo))->custstatinfo; while (objnode != NULL) { spaceobj = (Ship *)listGetStructOfNode(objnode); //Rejections... dbgAssert(spaceobj->objtype == OBJ_ShipType); if (spaceobj->playerowner != playerowner) { goto nextnode; // must be players ship inorder to cloak } if( spaceobj->shiptype == SalCapCorvette) { if(((SalCapCorvetteSpec *)spaceobj->ShipSpecifics)->tractorBeam) { goto nextnode; } } if (bitTest(spaceobj->flags,SOF_Cloaked)) { goto nextnode; // if object is cloaked } if(bitTest(spaceobj->flags,SOF_Dead)) { goto nextnode; } if(spaceobj->shiptype == Mothership || spaceobj->shiptype == Carrier) { goto nextnode; } //add more rejections...like collision model. vecSub(diff,spaceobj->posinfo.position,cloakship->posinfo.position); distanceSqr = diff.x*diff.x + diff.y*diff.y + diff.z*diff.z; if(distanceSqr <= cloakgeneratorstatics->CloakingRadiusSqr) { CloakGeneratorAddObj(cloakship, (SpaceObj *) spaceobj); } nextnode: objnode = objnode->next; } }
/*----------------------------------------------------------------------------- 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<universe.numPlayers;i++) { if (bitTest(alliance,PLAYER_MASK(i))) { if (i!=sigsPlayerIndex) { numallies++; } } } if (numallies >= 2) { for (j=0,index=0;j<universe.numPlayers;j++) { if ( (bitTest(alliance, PLAYER_MASK(j))) && (j != sigsPlayerIndex) ) { strcat(dest,playerNames[j]); index++; if (index<numallies-1) { strcat(dest, ", "); } else if (index==numallies-1) { strcat(dest, " "); strcat(dest,strGetString(strAnd)); strcat(dest, " "); } } } } else { for (j=0,index=0;j<universe.numPlayers;j++) { if ( (bitTest(alliance, PLAYER_MASK(j))) && (j != sigsPlayerIndex) ) { strcat(dest,playerNames[j]); break; } } } }
static void primSolidTexture3_multi(vector* p1, real32 size, color c, trhandle tex) { real32 halfsize; texreg* reg; extern udword gDevcaps; halfsize = 0.5f * size; rndTextureEnable(TRUE); trMakeCurrent(tex); reg = trStructureGet(tex); if (bitTest(reg->flags, TRF_Alpha)) { glEnable(GL_BLEND); glDisable(GL_ALPHA_TEST); rndAdditiveBlends(TRUE); } glBegin(GL_QUADS); glColor3ub(colRed(c), colGreen(c), colBlue(c)); glTexCoord2f(0.0f, 0.0f); glVertex3f(p1->x-halfsize, p1->y-halfsize, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(p1->x+halfsize, p1->y-halfsize, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(p1->x+halfsize, p1->y+halfsize, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(p1->x-halfsize, p1->y+halfsize, 0.0f); if (!bitTest(gDevcaps, DEVSTAT_NO_GETTEXIMAGE)) { glColor3ub(172, 172, 172); glTexCoord2f(0.0f, 0.0f); glVertex3f(p1->x-halfsize, p1->y-halfsize, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(p1->x+halfsize, p1->y-halfsize, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(p1->x+halfsize, p1->y+halfsize, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(p1->x-halfsize, p1->y+halfsize, 0.0f); } glEnd(); glDisable(GL_BLEND); rndAdditiveBlends(FALSE); }
/*----------------------------------------------------------------------------- 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); } }
void CloakGeneratorDied(Ship *ship) { CloakGeneratorSpec *spec = (CloakGeneratorSpec *)ship->ShipSpecifics; Node *cloaknode; CloakStruct *cloakstruct; cloaknode = spec->CloakList.head; while(cloaknode != NULL) { cloakstruct = (CloakStruct *)listGetStructOfNode(cloaknode); if(bitTest(cloakstruct->spaceobj->flags,SOF_Cloaked)) { bitClear(cloakstruct->spaceobj->flags,SOF_Cloaked); //Force instant decloaking if(cloakstruct->spaceobj->objtype == OBJ_ShipType) { //if object was a ship set objects decloaking time for cloak advagtage effect SpawnCloakingEffect((Ship *)cloakstruct->spaceobj, etgSpecialPurposeEffectTable[EGT_CLOAK_OFF]); ((Ship *) (cloakstruct->spaceobj))->shipDeCloakTime = universe.totaltimeelapsed; } } bitClear(cloakstruct->spaceobj->flags,SOF_Cloaking); bitClear(cloakstruct->spaceobj->flags,SOF_DeCloaking); bitClear(cloakstruct->spaceobj->flags,SOF_CloakGenField); cloaknode = cloaknode->next; } listDeleteAll(&spec->CloakList); //delete the list }
/*----------------------------------------------------------------------------- Name : dbwAllPanesRepaint Description : Repaints all panes. Inputs : hDC - device context (should be same as hDebugDC) Outputs : .. Return : .. ----------------------------------------------------------------------------*/ void dbwAllPanesRepaint(HDC hDC) { sdword pane; sdword line; char *source; sdword oldCursorX, oldCursorY; for (pane =0; pane < DBW_NumberPanes; pane++) //for all panes { if (!bitTest(dbwPane[pane].flags, DPF_Enabled)) //don't process disabled ones continue; oldCursorX = dbwPane[pane].cursorX; //save current cursor settings oldCursorY = dbwPane[pane].cursorY; dbwPane[pane].cursorX = 0; dbwPane[pane].cursorY = dbwPane[pane].viewTop; for (line = dbwPane[pane].viewTop; line < dbwPane[pane].viewTop + dbwPane[pane].height; line++) //for each line of this pane { source = dbwPane[pane].buffer + dbwPane[pane].width * line; dbwCharsPrint(pane, source, dbwPane[pane].width, FALSE); dbwPane[pane].cursorY++; } dbwPane[pane].cursorX = oldCursorX; //restore old cursor settings dbwPane[pane].cursorY = oldCursorY; } }
sdword memLargestBlockGet(void) { memcookie *thisCookie, *nextCookie; sdword largestSize = 0; thisCookie = memFirst; //start walk from very start of heap while (thisCookie < memLast) //scan for free cookies in heap { memCookieVerify(thisCookie); //verify this cookie if (!bitTest(thisCookie->flags, MBF_AllocatedNext)) { largestSize = max(largestSize, memBlocksToBytes(thisCookie->blocksNext)); } nextCookie = (memcookie *)((ubyte *)thisCookie + //next cookie sizeof(memcookie) + memBlocksToBytes(thisCookie->blocksNext)); if (nextCookie >= memLast) //if cookie pointed past end of heap { goto noMoreFree; //no more free structures } thisCookie = nextCookie; //next update } noMoreFree:; return largestSize; }
/*----------------------------------------------------------------------------- Name : pingBattleBlobCriteria Description : sub-blob creation callback to see if an object is a ship in a battle Inputs : superBlob - what blob we're searching through obj - what object we're currently processing Outputs : Return : TRUE if it's a player ship in a battle ----------------------------------------------------------------------------*/ bool pingBattleBlobCriteria(blob *superBlob, SpaceObj *obj) { if (obj->objtype != OBJ_ShipType) { return(FALSE); //not a ship - no good } // if (!allianceIsShipAlly((Ship *)obj, universe.curPlayerPtr)) // { //!!! should we consider alliances here? // return(FALSE); //does not belong to the player // } if (obj->flags & (SOF_Dead|SOF_Hide|SOF_Crazy|SOF_Disabled)) { return(FALSE); } if ((((Ship *)obj)->recentlyAttacked && ((Ship *)obj)->recentAttacker->playerowner != universe.curPlayerPtr) || (((Ship *)obj)->shipisattacking)) { if (!bitTest(smShipTypeRenderFlags[((Ship *)obj)->shiptype], SM_Exclude)) { //if we should include in battle blobs return(TRUE); //it's a player ship in a battle - good! } } return(FALSE); }
/*----------------------------------------------------------------------------- Name : liLayerColorAverage Description : Returns the average color of a layer Inputs : layer - layer to find average color of Outputs : Return : average color ----------------------------------------------------------------------------*/ color liLayerColorAverage(lilayer *layer) { udword red = 0, green = 0, blue = 0, alpha = 0, count, totalPixels; color *pColor; dbgAssert(layer->decompressed != NULL); dbgAssert(!bitTest(layer->flags, LFF_Channeled)); totalPixels = count = (layer->bounds.x1 - layer->bounds.x0) * (layer->bounds.y1 - layer->bounds.y0); pColor = layer->decompressed; while (count > 0) { red += colRed(*pColor); green += colGreen(*pColor); blue += colBlue(*pColor); alpha += colAlpha(*pColor); count--; pColor++; } red /= totalPixels; green /= totalPixels; blue /= totalPixels; alpha /= totalPixels; return(colRGBA(red, green, blue, alpha)); }
/*----------------------------------------------------------------------------- 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))); }
/*----------------------------------------------------------------------------- Name : rmCanBuildShip Description : returns true if player has tech needed to build that ship. Inputs : player Outputs : true/false Return : bool ----------------------------------------------------------------------------*/ bool rmCanBuildShip(Player *player, ShipType type) { if (bitTest(player->researchinfo.techstat->TechNeededToBuildShip[type], RM_Disabled)) { return(FALSE); } return ( (player->researchinfo.techstat->TechNeededToBuildShip[type]& player->researchinfo.HasTechnology) == player->researchinfo.techstat->TechNeededToBuildShip[type]); }
/*----------------------------------------------------------------------------- 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; */ } }
long hrShipsToLoadForRace(ShipRace shiprace) { long ShipsToLoad = 0; ShipType shiptype; ShipType firstshiptype; ShipType lastshiptype; ShipStaticInfo *shipstaticinfo; firstshiptype = FirstShipTypeOfRace[shiprace]; lastshiptype = LastShipTypeOfRace[shiprace]; for (shiptype=firstshiptype;shiptype<=lastshiptype;shiptype++) { shipstaticinfo = GetShipStaticInfo(shiptype,shiprace); if( bitTest(shipstaticinfo->staticheader.infoFlags, IF_InfoNeeded) && !bitTest(shipstaticinfo->staticheader.infoFlags, IF_InfoLoaded) ) ShipsToLoad++; } return ShipsToLoad; }
/*----------------------------------------------------------------------------- Name : madAnimationStart Description : Start an animation playing for a given ship Inputs : ship - ship to play the animation for animNumber - index of the animation rate - rate of the animation 1.0 is normal animation speed. -1 plays animation in reverse. Outputs : sets time, rate and splinecurves up for an animation. Return : void ----------------------------------------------------------------------------*/ void madAnimationStart(Ship *ship, sdword animNumber) { madanim *anim = ship->madBindings; madheader *header = anim->header; shipbindings *bindings = &anim->bindings; sdword index, j, startPoint; splinecurve *curve; madanimation *animation; udword animBit = (1 << animNumber); //if the ship has gun bindings, swap the animation bindings with the gun bindings anim->saveBindings = ship->bindings; ship->bindings = bindings; dbgAssertOrIgnore(animNumber < header->nAnimations); anim->nCurrentAnim = animNumber; animation = &header->anim[animNumber]; anim->startTime = anim->time = animation->startTime; anim->timeElapsed = 0.0f; //start all the b-splines. They've already been set up, //we just need to initialize the time and current point. curve = anim->curves; for (index = 0; index < header->nObjects; index++) { if (!bitTest(header->objPath[index].animationBits, animBit)) { //if this object doesn't need to participate in the animation curve->currentPoint = BS_NoPoint; //set the curves to not update curve += 6; continue; } for (startPoint = 0; startPoint < curve->nPoints; startPoint++) { if (curve->times[startPoint] == anim->time) { goto foundTime; } } #if MAD_ERROR_CHECKING dbgFatalf(DBG_Loc, "madAnimationStart: Object #%d ('%s') has no keyframe at frame %.0f", index, header->objPath[index].name, anim->time / header->framesPerSecond); #endif foundTime: for (j = 0; j < 6; j++, curve++) { curve->timeElapsed = anim->time; curve->currentPoint = startPoint; } } #if MAD_VERBOSE_LEVEL >= 2 dbgMessagef("madAnimationStart: started animation #%d('%s') on ship 0x%x", animNumber, animation->name, ship); #endif }
/*----------------------------------------------------------------------------- Name : aiuCanBuildShipType Description : Returns TRUE if current AI player can build ships of shiptype Inputs : shiptype Outputs : Return : Returns TRUE if current AI player can build ships of shiptype ----------------------------------------------------------------------------*/ bool aiuCanBuildShipType(ShipType shiptype,bool scriptteam) { Ship *playerMothership = aiCurrentAIPlayer->player->PlayerMothership; ShipStaticInfo *teststatic; ShipRace race; if (playerMothership == NULL) { return FALSE; } race = playerMothership->shiprace; if ((RacesAllowedForGivenShip[shiptype] & RaceToRaceBits(race)) == 0) { // Can't build this shiptype for this race return FALSE; } teststatic = GetShipStaticInfo(shiptype,race); if (!bitTest(teststatic->staticheader.infoFlags, IF_InfoLoaded)) { return FALSE; // this ship static info not loaded, so can't build } if ((shiptype == ResourceCollector) && (!singlePlayerGame) && (!bitTest(tpGameCreated.flag,MG_HarvestinEnabled))) { return FALSE; } if (scriptteam) { return TRUE; } else { return cmCanBuildShipType(playerMothership,shiptype,FALSE); // later set to TRUE to take into account research } }
/*----------------------------------------------------------------------- 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;i<universe.numPlayers;i++) { if ( bitTest(universe.players[sigsPlayerIndex].Allies, PLAYER_MASK(i)) ) { clWrapSetAlliance(ALLIANCE_BREAKALLIANCE, (uword)sigsPlayerIndex, (uword)i); } } }
/*----------------------------------------------------------------------------- Name : liImageDelete Description : Deletes a layered image and all data associated therewith. Inputs : image - layered image to delete Outputs : Frees all memory, including the image itself (which must therefore have been independently allocated). Return : void ----------------------------------------------------------------------------*/ void liImageDelete(layerimage *image) { sdword index, j; #if LI_VERBOSE_LEVEL >= 1 dbgMessagef("\nliImageDelete: deleting image 0x%x, filename '%s'", image, #if LI_RETAIN_NAME image->fileName); #else "<no name available>"); #endif //LI_RETAIN_NAME #endif //LI_VERBOSE_LEVEL for (index = 0; index < image->nLayers; index++) { //for each layer if (bitTest(image->layers[index].flags, LFF_Deleted)) { continue; } if (image->layers[index].flags & LFF_Channeled) { //if layer is channeled for (j = 0; j < image->layers[index].nChannels; j++) { //for each channel of each layer if (image->layers[index].channels[j].scanLength != NULL) { //if a RLE encoded channel memFree(image->layers[index].channels[j].scanLength);//free the channel image data } else { //else a RAW channel memFree(image->layers[index].channels[j].scanData);//free the channel image data } } if (image->layers[index].channels) { memFree(image->layers[index].channels); //free the channel list } } else { if (image->layers[index].decompressed) { //if decompressed, free decompressed buffer memFree(image->layers[index].decompressed); } } if (image->layers[index].name) { memFree(image->layers[index].name); //free the name } } #if LI_RETAIN_NAME memFree(image->fileName); //free image file name #endif memFree(image); //free the actual image }
void CloakGeneratorRemoveShipReferences(Ship *ship,Ship *shiptoremove) { CloakGeneratorSpec *spec = (CloakGeneratorSpec *)ship->ShipSpecifics; Node *cloaknode; CloakStruct *cloakstruct; SpaceObj *objtoremove = (SpaceObj *)shiptoremove; cloaknode = spec->CloakList.head; if (bitTest(objtoremove->flags,SOF_Cloaked) || //if object inquestion isn't cloaked, cloaking bitTest(objtoremove->flags,SOF_Cloaking) || //or decloaking, then we don't walk this list bitTest(objtoremove->flags,SOF_DeCloaking)) //If a cloaked fighter is passed, and it isn't in the list, it will waste time, but this is good enough :) { while(cloaknode != NULL) { cloakstruct = (CloakStruct *)listGetStructOfNode(cloaknode); if (cloakstruct->spaceobj == objtoremove) { listDeleteNode(cloaknode); //delete nodes memory...may not work as I think...ask gary.. break; //done so break and return } cloaknode = cloaknode->next; } if(bitTest(objtoremove->flags, SOF_Cloaked)) { bitClear(objtoremove->flags,SOF_Cloaked); if(objtoremove->objtype == OBJ_ShipType) { //if object was a ship set objects decloaking time for cloak advagtage effect SpawnCloakingEffect((Ship *)objtoremove, etgSpecialPurposeEffectTable[EGT_CLOAK_OFF]); ((Ship *) (objtoremove))->shipDeCloakTime = universe.totaltimeelapsed; } } bitClear(objtoremove->flags,SOF_Cloaking); bitClear(objtoremove->flags,SOF_DeCloaking); bitClear(objtoremove->flags,SOF_CloakGenField); } }
/*----------------------------------------------------------------------------- Name : dbwAllPanesFree Description : Frees memory of all panes and disables them. Inputs : void Outputs : void Return : void ----------------------------------------------------------------------------*/ void dbwAllPanesFree(void) { sdword index; for (index = 0; index < DBW_NumberPanes; index++) { if (bitTest(dbwPane[index].flags, DPF_Enabled)) { free(dbwPane[index].buffer); //!!! use proper free call bitClear(dbwPane[index].flags, DPF_Enabled); } } }
int main(void) { int bitTest(unsigned int value, int n); printf("bitTest: %i\n", bitTest(4, 28)); int bitSet(unsigned int value, int n); printf("bitSet: %i\n", bitSet(4, 32)); return 0; }
/*----------------------------------------------------------------------------- Name : rmRemoveUnneededTech Description : Removes any technology that when researched gives nothing! Inputs : Pointer to the TechStatics to be modified. Outputs : void Return : none ----------------------------------------------------------------------------*/ void rmRemoveUnneededTech(TechStatics *techstat) { udword i,j,k, tech, techtmp; bool notneeded; // for (i=0; i < STD_LAST_SHIP; i++) // for all ships { tech = techstat->TechNeededToBuildShip[i]; if (bitTest(tech,RM_Disabled)) // is ship disabled ? { for (j=0; j < NumTechnologies; j++) // for all technologies needed to build this ship. { notneeded = TRUE; if (bitTest(tech,TechToBit(j))) { for (k=0; k < STD_LAST_SHIP; k ++) { techtmp = techstat->TechNeededToBuildShip[k]; if ((!(bitTest(techtmp,RM_Disabled))) &&(k != i)) { if (bitTest(techtmp,TechToBit(j))) { notneeded = FALSE; } } } if (notneeded) { techstat->TechNeededToResearch[j] |= RM_Disabled; } } } } } }
void primSolidTexture3Fade(vector *p1, real32 size, color c, trhandle tex, real32 fade) { real32 halfsize = size / 2; real32 biasRed, biasGreen, biasBlue; texreg* reg; rndTextureEnable(TRUE); trMakeCurrent(tex); reg = trStructureGet(tex); if (bitTest(reg->flags, TRF_Alpha)) { glEnable(GL_BLEND); glDisable(GL_ALPHA_TEST); rndAdditiveBlends(TRUE); } biasRed = colReal32(colRed(c)); biasGreen = colReal32(colGreen(c)); biasBlue = colReal32(colBlue(c)); if (RGL) { glPixelTransferf(GL_RED_BIAS, biasRed); glPixelTransferf(GL_GREEN_BIAS, biasGreen); glPixelTransferf(GL_BLUE_BIAS, biasBlue); } glColor4f(biasRed, biasGreen, biasBlue, fade); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(p1->x-halfsize, p1->y-halfsize, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(p1->x+halfsize, p1->y-halfsize, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(p1->x+halfsize, p1->y+halfsize, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(p1->x-halfsize, p1->y+halfsize, 0.0f); glEnd(); if (RGL) { glPixelTransferf(GL_RED_BIAS, 0.0f); glPixelTransferf(GL_GREEN_BIAS, 0.0f); glPixelTransferf(GL_BLUE_BIAS, 0.0f); } glDisable(GL_BLEND); rndAdditiveBlends(FALSE); }
/*----------------------------------------------------------------------------- Name : memDefragment Description : Defragments the heap by combining adjacent free blocks. Inputs : void Outputs : Adjacent free blocks combined. Resets value of memFreeFirst Return : OKAY ----------------------------------------------------------------------------*/ sdword memDefragment(void) { memcookie *thisCookie, *nextCookie; thisCookie = memFirst; //start walk from very start of heap while (thisCookie < memLast) //scan for free cookies in heap { memCookieVerify(thisCookie); //verify this cookie nextCookie = (memcookie *)((ubyte *)thisCookie + //next cookie sizeof(memcookie) + memBlocksToBytes(thisCookie->blocksNext)); if (nextCookie >= memLast) //if cookie pointed past end of heap { goto noMoreFree; //no more free structures } while ((!bitTest(thisCookie->flags, MBF_AllocatedNext)) && (!bitTest(nextCookie->flags, MBF_AllocatedNext)))//while these 2 blocks are both free { #if MEM_VERBOSE_LEVEL >= 3 dbgMessagef("\nmemDefragment: combined blocks 0x%x(%d) and 0x%x(%d) into one.", thisCookie, memBlocksToBytes(thisCookie->blocksNext), nextCookie, memBlocksToBytes(nextCookie->blocksNext)); #endif thisCookie->blocksNext += nextCookie->blocksNext + MEM_BlocksPerCookie; nextCookie = (memcookie *)((ubyte *)thisCookie +//next cookie sizeof(memcookie) + memBlocksToBytes(thisCookie->blocksNext)); if (nextCookie >= memLast) //if cookie pointed past end of heap { goto noMoreFree; //no more free structures } memCookieVerify(nextCookie); //verify next cookie } thisCookie = nextCookie; //next update } noMoreFree:; return(OKAY); }
/*----------------------------------------------------------------------------- Name : dbwWriteOptions Description : write the debug window's options to the configuration file Inputs : Outputs : Return : ----------------------------------------------------------------------------*/ void dbwWriteOptions(void) { sdword index; ubyte *data; FILE *f; if (!dbwEnabled) { return; } f = fopen(DIS_FileName, "at"); if (f != NULL) { //save location to .INI file fprintf(f, "%s %d, %d\n", DIS_Location, dbwWindowX, dbwWindowY); // WritePrivateProfileString(DIS_SectionName, DIS_Location, // string, DIS_FileName); //save size to .INI file fprintf(f, "%s %d, %d\n", DIS_Size, dbwWindowWidth, dbwWindowHeight); // WritePrivateProfileString(DIS_SectionName, DIS_Size, // string, DIS_FileName); //save the font to .INI file fprintf(f, "%s ", DIS_Font); // WritePrivateProfileStruct(DIS_SectionName, DIS_Font, // &dbwLogicalFont, sizeof(LOGFONT), DIS_FileName); data = (ubyte *)&dbwLogicalFont; for (index = 0; index < sizeof(LOGFONT); index++, data++) { fprintf(f, "%c%c", "0123456789ABCDEF"[((*data) & 0xf0) >> 4], "0123456789ABCDEF"[(*data) & 0x0f]); } fprintf(f, "\n"); //save the pane information to the .INI file for (index = 0; index < DBW_NumberPanes; index++) { if (bitTest(dbwPane[index].flags, DPF_Enabled)) { // sprintf(key, "%s%d", DIS_PaneBase, index); fprintf(f, "%s%d %d, %d, %d, %d, %d\n\n", DIS_PaneBase, index, dbwPane[index].x, dbwPane[index].y, dbwPane[index].width, dbwPane[index].height, dbwPane[index].bufferHeight); // WritePrivateProfileString(DIS_SectionName, key, string, DIS_FileName); } } fclose(f); }
void CloakGeneratorAddObj(Ship *ship, SpaceObj *objtoadd) { //Adds shiptoadd to 'ship's cloaklist CloakGeneratorSpec *spec = (CloakGeneratorSpec *)ship->ShipSpecifics; CloakStruct *newcloakstruct; if (bitTest(objtoadd->flags,SOF_Cloaked) || bitTest(objtoadd->flags, SOF_Cloaking) || bitTest(objtoadd->flags, SOF_DeCloaking)) { //if object is cloaked, don't add it...don't even think about it. return; } newcloakstruct = memAlloc(sizeof(CloakStruct),"CloakStruct",0); newcloakstruct->CloakStatus = 0.0f; newcloakstruct->spaceobj = objtoadd; listAddNode(&spec->CloakList,&newcloakstruct->cloaknode,newcloakstruct); //temporary...later make 'cloaking' bitSet(objtoadd->flags, SOF_Cloaking); bitSet(objtoadd->flags, SOF_CloakGenField); //indicate object is in cloak field //should not have to clear the cloaked flag bitClear(objtoadd->flags, SOF_Cloaked); // bitClear(objtoadd->flags, SOF_DeCloaking); }
void CBTGView::btgvPDraw(CDC *pDC) { CBTGDoc *pDocument; BTGVertex *pVertex; CPoint p; pDocument = GetDocument(); pVertex = pDocument->GetFirstBTGVertex(); while(pVertex) { if(pVertex->bVisible == FALSE) { pVertex = pVertex->GetNext(); continue; } // Get this vertex's colors. CPen standardPen(PS_SOLID, 1, RGB(0xFF, 0xFF, 0xFF)); CPen selectedPen(PS_SOLID, 2, RGB(0, 0xFF, 0xFF)); CBrush interiorBrush(RGB(pVertex->red, pVertex->green, pVertex->blue)); pDC->SelectObject(&interiorBrush); // Get this vertex's screen coords. p.x = (long)pVertex->x; p.y = (long)pVertex->y; pDocument->CalculateScreenCoordinates(&p); // Is this vertex selected? if(bitTest(pVertex->flags, BTGVertex::btgvFlags_Selected)) { pDC->SelectObject(&selectedPen); } else { pDC->SelectObject(&standardPen); } // Draw a rectangle around the vertex. pDC->Rectangle(p.x - BTGV_SIZE2, p.y - BTGV_SIZE2, p.x + BTGV_SIZE2, p.y + BTGV_SIZE2); pVertex = pVertex->GetNext(); } }
/*----------------------------------------------------------------------- Name : rmAllTechRequiredforTech Description : Returns all of the technology needed to research a tech Inputs : player techtype Outputs : technology bitmask Parameters : Player *player, TechnologyType type Return : udword -----------------------------------------------------------------------*/ udword rmAllTechRequiredforTech(Player *player, TechnologyType type) { udword i, numtech=0; udword techdepend,temp; techdepend = temp = player->researchinfo.techstat->TechNeededToResearch[type]; for (i=0; i<NumTechnologies; i--) { if (bitTest(temp, TechToBit(i))) { techdepend |= rmAllTechRequiredforTech(player, i); } } return (techdepend); }