static void Standardize(int cf) { int k, m; Matrix_t *sb; IntMatrix_t *script = NULL; Matrix_t *std[MAXGEN]; /* Make the spin-up script for the standard basis and transform the generators. -------------------------------------------------- */ MESSAGE(0,(" Transforming to standard basis\n")); sb = SpinUp(CfList[cf].PWNullSpace,CfList[cf].Gen, SF_FIRST|SF_CYCLIC|SF_STD,&script,NULL); ChangeBasisOLD(sb,CfList[cf].Gen->NGen, (const Matrix_t **)CfList[cf].Gen->Gen,std); MatFree(sb); /* Write the transformed generators and the spin-up script. -------------------------------------------------------- */ for (m = 0; m < CfList[cf].Mult; ++m) { char fn[200]; Lat_Info *li = &ModList[CfList[cf].CfMap[m][0]].Info; int i = CfList[cf].CfMap[m][1]; sprintf(fn,"%s%s.op",li->BaseName,Lat_CfName(li,i)); MESSAGE(2,("Write operations to %s\n",fn)); if (ImatSave(script,fn) != 0) MTX_ERROR("Cannot write .op file"); for (k = 0; k < li->NGen; ++k) { sprintf(fn,"%s%s.std.%d",li->BaseName,Lat_CfName(li,i),k+1); MESSAGE(2,(" %s",fn)); MatSave(std[k],fn); } } for (k = 0; k < ModList[0].Info.NGen; ++k) MatFree(std[k]); ImatFree(script); }
int main(int argc, const char **argv) { IntMatrix_t **optab = NULL; int flags; SpinUpInfo_t SpInfo; if (Init(argc,argv) != 0) { MTX_ERROR("Initialization failed"); return 1; } if (OpName != NULL) optab = &OpTable; SpinUpInfoInit(&SpInfo); if (MaxDim > 0) SpInfo.MaxSubspaceDimension = MaxDim; if (MaxTries > 0) SpInfo.MaxTries = MaxTries; flags = 0; /* Seed mode: SF_MAKE, SF_EACH, or SF_FIRST. ----------------------------------------- */ if (TryOneVector) flags |= SF_FIRST; else if (TryLinearCombinations) flags |= SF_MAKE; else flags |= SF_EACH; /* Search mode: SF_CYCLIC, SF_SUB, or SF_COMBINE. ---------------------------------------------- */ if (FindCyclicVector) flags |= SF_CYCLIC; else if (FindClosure) flags |= SF_COMBINE; else flags |= SF_SUB; /* Spin-up mode: SF_STD or nothing. -------------------------------- */ if (Standard) flags |= SF_STD; if (!Permutations) Span = SpinUp(Seed,Rep,flags,optab,&SpInfo); else Span = SpinUpWithPermutations(Seed,ngen,Perm,flags,optab,&SpInfo); if (Span == NULL) { MTX_ERROR("Spin-up failed"); return -1; } if (WriteResult() != 0) return 1; Cleanup(); return 0; }
//----------------------------------------------------------------------------- // Purpose: Target doesn't exist or has eluded us, so search for one //----------------------------------------------------------------------------- void CNPC_Portal_FloorTurret::SearchThink( void ) { //Allow descended classes a chance to do something before the think function if ( PreThink( TURRET_SEARCHING ) ) return; SetNextThink( gpGlobals->curtime + 0.05f ); SetActivity( (Activity) ACT_FLOOR_TURRET_OPEN_IDLE ); //If our enemy has died, pick a new enemy if ( ( GetEnemy() != NULL ) && ( GetEnemy()->IsAlive() == false ) ) { SetEnemy( NULL ); } //Acquire the target if ( GetEnemy() == NULL ) { HackFindEnemy(); } LaserOn(); CBaseEntity *pEnemy = GetEnemy(); //If we've found a target, spin up the barrel and start to attack if ( pEnemy != NULL ) { //Get our shot positions Vector vecMid = EyePosition(); Vector vecMidEnemy = pEnemy->BodyTarget( vecMid ); //Look for our current enemy bool bEnemyInFOV = FInViewCone( pEnemy ); bool bEnemyVisible = FVisible( pEnemy ); //Calculate dir and dist to enemy Vector vecDirToEnemy = vecMidEnemy - vecMid; m_flDistToEnemy = VectorNormalize( vecDirToEnemy ); // If the enemy isn't in the normal fov, check the fov through portals CProp_Portal *pPortal = NULL; pPortal = FInViewConeThroughPortal( pEnemy ); if ( pPortal && FVisibleThroughPortal( pPortal, pEnemy ) ) { // Translate our target across the portal Vector vecMidEnemyTransformed; UTIL_Portal_PointTransform( pPortal->m_hLinkedPortal->MatrixThisToLinked(), vecMidEnemy, vecMidEnemyTransformed ); //Calculate dir and dist to enemy Vector vecDirToEnemyTransformed = vecMidEnemyTransformed - vecMid; float flDistToEnemyTransformed = VectorNormalize( vecDirToEnemyTransformed ); // If it's not visible through normal means or the enemy is closer through the portal, use the translated info if ( !bEnemyInFOV || !bEnemyVisible || flDistToEnemyTransformed < m_flDistToEnemy ) { bEnemyInFOV = true; bEnemyVisible = true; vecMidEnemy = vecMidEnemyTransformed; vecDirToEnemy = vecDirToEnemyTransformed; m_flDistToEnemy = flDistToEnemyTransformed; } } // Give enemies that are farther away a longer grace period float fDistanceRatio = m_flDistToEnemy / PORTAL_FLOOR_TURRET_RANGE; m_flShotTime = gpGlobals->curtime + fDistanceRatio * fDistanceRatio * PORTAL_FLOOR_TURRET_MAX_SHOT_DELAY; m_flLastSight = 0; SetThink( &CNPC_FloorTurret::ActiveThink ); SetEyeState( TURRET_EYE_SEE_TARGET ); SpinUp(); if ( gpGlobals->curtime > m_flNextActivateSoundTime ) { EmitSound( "NPC_FloorTurret.Activate" ); m_flNextActivateSoundTime = gpGlobals->curtime + 3.0; } return; } //Are we out of time and need to retract? if ( gpGlobals->curtime > m_flLastSight ) { //Before we retrace, make sure that we are spun down. m_flLastSight = 0; SetThink( &CNPC_FloorTurret::Retire ); return; } //Display that we're scanning m_vecGoalAngles.x = GetAbsAngles().x + ( sin( ( m_flLastSight + gpGlobals->curtime * m_fSearchSpeed ) * 1.5f ) * 20.0f ); m_vecGoalAngles.y = GetAbsAngles().y + ( sin( ( m_flLastSight + gpGlobals->curtime * m_fSearchSpeed ) * 2.5f ) * 20.0f ); //Turn and ping UpdateFacing(); Ping(); // Update rope positions for ( int iRope = 0; iRope < PORTAL_FLOOR_TURRET_NUM_ROPES; ++iRope ) { if ( m_hRopes[ iRope ] ) { m_hRopes[ iRope ]->EndpointsChanged(); } } }
void FGTurbine::Calculate(void) { double thrust; RunPreFunctions(); ThrottlePos = in.ThrottlePos[EngineNumber]; if (ThrottlePos > 1.0) { AugmentCmd = ThrottlePos - 1.0; ThrottlePos -= AugmentCmd; } else { AugmentCmd = 0.0; } // When trimming is finished check if user wants engine OFF or RUNNING if ((phase == tpTrim) && (in.TotalDeltaT > 0)) { if (Running && !Starved) { phase = tpRun; N1_factor = MaxN1 - IdleN1; N2_factor = MaxN2 - IdleN2; N2 = IdleN2 + ThrottlePos * N2_factor; N1 = IdleN1 + ThrottlePos * N1_factor; OilTemp_degK = 366.0; Cutoff = false; } else { phase = tpOff; Cutoff = true; EGT_degC = in.TAT_c; } } if (!Running && Cutoff && Starter) { if (phase == tpOff) phase = tpSpinUp; } // start if ((Starter == true) || (in.qbar > 30.0)) { if (!Running && !Cutoff && (N2 > 15.0)) phase = tpStart; } if (Cutoff && (phase != tpSpinUp)) phase = tpOff; if (in.TotalDeltaT == 0) phase = tpTrim; if (Starved) phase = tpOff; if (Stalled) phase = tpStall; if (Seized) phase = tpSeize; switch (phase) { case tpOff: thrust = Off(); break; case tpRun: thrust = Run(); break; case tpSpinUp: thrust = SpinUp(); break; case tpStart: thrust = Start(); break; case tpStall: thrust = Stall(); break; case tpSeize: thrust = Seize(); break; case tpTrim: thrust = Trim(); break; default: thrust = Off(); } Thruster->Calculate(thrust); // allow thruster to modify thrust (i.e. reversing) RunPostFunctions(); }
static void kond(int mod, int cf) { const Lat_Info *li = &ModList[mod].Info; char fn[LAT_MAXBASENAME+10]; Matrix_t *peakword, *kern, *m, *k, *pw; int j, pwr; /* Make the peak word, find its stable power, and calculate both kernel and image. ------------------------------------------ */ peakword = WgMakeWord(ModList[mod].Wg,li->Cf[cf].peakword); MatInsert_(peakword,li->Cf[cf].peakpol); pw = MatDup(peakword); StablePower_(peakword,&pwr,&kern); MESSAGE(0,("pwr=%d, nul=%d, ",pwr,kern->Nor)); if (kern->Nor != li->Cf[cf].mult * li->Cf[cf].spl) MTX_ERROR("Something is wrong here!"); MatEchelonize(peakword); /* Write out the image ------------------- */ if (!opt_n) { sprintf(fn,"%s%s.im",li->BaseName,Lat_CfName(li,cf)); MatSave(peakword,fn); } /* Write out the `uncondense matrix' --------------------------------- */ m = QProjection(peakword,kern); k = MatInverse(m); MatFree(m); MatMul(k,kern); sprintf(fn,"%s%s.k",li->BaseName,Lat_CfName(li,cf)); MatSave(k,fn); /* Condense all generators ----------------------- */ MESSAGE(1,("(")); for (j = 0; j < li->NGen; ++j) { sprintf(fn,"%dk",j+1); gkond(li,cf,peakword,k,ModList[mod].Rep->Gen[j],fn); MESSAGE(1,("%d",j+1)); } MESSAGE(1,(")")); /* Condense the peak word ---------------------- */ gkond(li,cf,peakword,k,pw,"np"); /* Calculate the semisimplicity basis. ----------------------------------- */ if (opt_b) { Matrix_t *seed, *partbas; int pos = CfPosition(li,cf); seed = MatNullSpace_(pw,0); partbas = SpinUp(seed,ModList[mod].Rep,SF_EACH|SF_COMBINE|SF_STD,NULL,NULL); MatFree(seed); MESSAGE(0,(", %d basis vectors",partbas->Nor)); if (MatCopyRegion(ModList[mod].SsBasis,pos,0,partbas,0,0,-1,-1) != 0) { MTX_ERROR1("Error making basis - '%s' is possibly not semisimple", li->BaseName); } MatFree(partbas); } MatFree(pw); MESSAGE(0,("\n")); MatFree(k); MatFree(kern); MatFree(peakword); }
void FGTurboProp::Calculate(void) { RunPreFunctions(); TAT = in.TAT_c; ThrottlePos = in.ThrottlePos[EngineNumber]; /* The thruster controls the engine RPM because it encapsulates the gear ratio and other transmission variables */ RPM = Thruster->GetEngineRPM(); if (thrusterType == FGThruster::ttPropeller) { ((FGPropeller*)Thruster)->SetAdvance(in.PropAdvance[EngineNumber]); ((FGPropeller*)Thruster)->SetFeather(in.PropFeather[EngineNumber]); ((FGPropeller*)Thruster)->SetReverse(Reversed); if (Reversed) { ((FGPropeller*)Thruster)->SetReverseCoef(ThrottlePos); } else { ((FGPropeller*)Thruster)->SetReverseCoef(0.0); } if (Reversed) { if (ThrottlePos < BetaRangeThrottleEnd) { ThrottlePos = 0.0; // idle when in Beta-range } else { // when reversed: ThrottlePos = (ThrottlePos-BetaRangeThrottleEnd)/(1-BetaRangeThrottleEnd) * ReverseMaxPower; } } } // When trimming is finished check if user wants engine OFF or RUNNING if ((phase == tpTrim) && (in.TotalDeltaT > 0)) { if (Running && !Starved) { phase = tpRun; N2 = IdleN2; N1 = IdleN1; OilTemp_degK = 366.0; Cutoff = false; } else { phase = tpOff; Cutoff = true; Eng_ITT_degC = TAT; Eng_Temperature = TAT; OilTemp_degK = TAT+273.15; } } if (!Running && Starter) { if (phase == tpOff) { phase = tpSpinUp; if (StartTime < 0) StartTime=0; } } if (!Running && !Cutoff && (N1 > 15.0)) { phase = tpStart; StartTime = -1; } if (Cutoff && (phase != tpSpinUp)) phase = tpOff; if (in.TotalDeltaT == 0) phase = tpTrim; if (Starved) phase = tpOff; if (Condition >= 10) { phase = tpOff; StartTime=-1; } // limiter intervention wanted? if (Ielu_max_torque > 0.0) { double torque = 0.0; if (thrusterType == FGThruster::ttPropeller) { torque = ((FGPropeller*)(Thruster))->GetTorque(); } else if (thrusterType == FGThruster::ttRotor) { torque = ((FGRotor*)(Thruster))->GetTorque(); } if (Condition < 1) { if ( abs(torque) > Ielu_max_torque && ThrottlePos >= OldThrottle ) { ThrottlePos = OldThrottle - 0.1 * in.TotalDeltaT; //IELU down Ielu_intervent = true; } else if ( Ielu_intervent && ThrottlePos >= OldThrottle) { ThrottlePos = OldThrottle + 0.05 * in.TotalDeltaT; //IELU up Ielu_intervent = true; } else { Ielu_intervent = false; } } else { Ielu_intervent = false; } OldThrottle = ThrottlePos; } switch (phase) { case tpOff: HP = Off(); break; case tpRun: HP = Run(); break; case tpSpinUp: HP = SpinUp(); break; case tpStart: HP = Start(); break; default: HP = 0; } LoadThrusterInputs(); Thruster->Calculate(HP * hptoftlbssec); RunPostFunctions(); }
//----------------------------------------------------------------------------- // Purpose: Target doesn't exist or has eluded us, so search for one //----------------------------------------------------------------------------- void CNPC_CeilingTurret::SearchThink( void ) { //Allow descended classes a chance to do something before the think function if ( PreThink( TURRET_SEARCHING ) ) return; SetNextThink( gpGlobals->curtime + 0.05f ); SetActivity( (Activity) ACT_CEILING_TURRET_OPEN_IDLE ); //If our enemy has died, pick a new enemy if ( ( GetEnemy() != NULL ) && ( GetEnemy()->IsAlive() == false ) ) { SetEnemy( NULL ); } //Acquire the target if ( GetEnemy() == NULL ) { GetSenses()->Look( CEILING_TURRET_RANGE ); CBaseEntity *pEnemy = BestEnemy(); if ( pEnemy ) { SetEnemy( pEnemy ); } } //If we've found a target, spin up the barrel and start to attack if ( GetEnemy() != NULL ) { //Give players a grace period if ( GetEnemy()->IsPlayer() ) { m_flShotTime = gpGlobals->curtime + 0.5f; } else { m_flShotTime = gpGlobals->curtime + 0.1f; } m_flLastSight = 0; SetThink( &CNPC_CeilingTurret::ActiveThink ); SetEyeState( TURRET_EYE_SEE_TARGET ); SpinUp(); EmitSound( "NPC_CeilingTurret.Active" ); return; } //Are we out of time and need to retract? if ( gpGlobals->curtime > m_flLastSight ) { //Before we retrace, make sure that we are spun down. m_flLastSight = 0; SetThink( &CNPC_CeilingTurret::Retire ); return; } //Display that we're scanning m_vecGoalAngles.x = 15.0f; m_vecGoalAngles.y = GetAbsAngles().y + ( sin( gpGlobals->curtime * 2.0f ) * 45.0f ); //Turn and ping UpdateFacing(); Ping(); }