void RegAlloc::addActive(Register r, LIns* v) { // Count++; NanoAssert(v && r != UnknownReg && active[r] == NULL ); active[r] = v; useActive(r); }
bool GadgetELF::updateLogic() { NounShip * pShip = WidgetCast<NounShip>( parent() ); if (! pShip ) return false; if (! useActive() ) pShip->useGadget( this, NULL, false ); return true; }
bool GadgetScanner::updateLogic() { if ( WidgetCast<NounShip>( parent() ) ) { NounShip * pShip = (NounShip *)parent(); if (! useActive() ) pShip->useGadget( this, NULL, false ); return true; } return true; }
void GadgetBeamWeapon::render( RenderContext &context, const Matrix33 & frame, const Vector3 & position ) { NounGadget::render( context, frame, position ); // render the beam if ( useActive() && m_Target.valid() && m_Duration > 0 ) { Vector3 positionVS( context.worldToView( position ) ); float fLength = length() * calculateModifier( MT_BEAM_RANGE ); if (! context.sphereVisible( positionVS, fLength ) ) return; Noun * pTarget = m_Target; Vector3 position2( pTarget->worldPosition() ); if ( ( ( position2 - worldPosition() ).magnitude() - pTarget->radius() ) > fLength ) return; if ( !checkFacing( position2 ) ) return; int tailAlpha = 32; if ( m_Hit.valid() ) tailAlpha = 128; Vector3 direction( pTarget->worldPosition() - position ); Vector3 head( position ); Vector3 tail( head + direction ); // calculate the material wrap float h = 0.05f; float w = 10.0f; Material * pTracerMaterial = tracerMaterial(); if ( pTracerMaterial != NULL ) { h = pTracerMaterial->height(); w = pTracerMaterial->width(); Material::push( context, pTracerMaterial ); } else Material::push( context, Color(255,0,0), true, PrimitiveMaterial::ADDITIVE ); float u = (head - tail).magnitude() / w; const Vector3 N( 0,0, 0); const Vector3 Y( 0, h, 0 ); const Vector3 X( h, 0, 0 ); const Color HC( 255,255,255,255 ); const Color TC( 255,255,255,tailAlpha ); VertexL beamY[4] = { VertexL( head + Y, N, HC, u, 0.0f ), VertexL( tail + Y, N, TC, 0.0f, 0.0f ), VertexL( tail - Y, N, TC, 0.0f, 1.0f ), VertexL( head - Y, N, HC, u, 1.0f ), }; VertexL beamX[4] = { VertexL( head + X, N, HC, u, 0.0f ), VertexL( tail + X, N, TC, 0.0f, 0.0f ), VertexL( tail - X, N, TC, 0.0f, 1.0f ), VertexL( head - X, N, HC, u, 1.0f ), }; DisplayDevice * pDisplay = context.device(); ASSERT( pDisplay ); context.pushIdentity(); PrimitiveTriangleFanDL::push( pDisplay, 4, beamY ); PrimitiveTriangleFanDL::push( pDisplay, 4, beamX ); } }
bool GadgetBeamWeapon::updateLogic() { if ( useActive() || usableWhen() > 0 ) return true; // early out if not ready to fire or currently in use... if ( WidgetCast<NounShip>( parent() ) ) { NounShip * pShip = (NounShip *)parent(); // turn on point defense if not on already... if ( !pointDefense() && type() != WEAPON_BOMB && allowPointDefense() ) setPointDefense( true ); NounGame * pTarget = WidgetCast<NounGame>( pShip->commandTarget() ); if (! pTarget ) return true; // no current target if ( pTarget != pShip->lastFireTarget() || !pShip->isWeaponsFree() ) return true; // can't hit target if ( isFriend( pTarget ) ) return true; // don't attack friendly targets if( WidgetCast<NounJumpGate>( pTarget ) || WidgetCast<CargoResource>( pTarget ) ) return true; // don't attack jump gates or resources if (! pTarget->canDamage( damageType() ) ) return true; // can't damage this target, so don't use this weapon if ( type() == WEAPON_BOMB && WidgetCast<NounPlanet>( pTarget ) == NULL ) return true; // only use bomb weapons on planets.. if ( usable( pTarget, false ) ) pShip->useGadget( this, pTarget, false ); } else if ( WidgetCast<StructureDefense>( parent() ) ) { StructureDefense * pStructure = (StructureDefense *)parent(); if (! pStructure->active() ) return true; NounPlanet * pPlanet = pStructure->planet(); if (! pPlanet ) return false; Noun * pBestTarget = NULL; float fBestRange = 0.0f;; // look for incoming enemy projectiles, pick the best target for(int j=0;j<pPlanet->contactCount();j++) { NounGame * pContact = WidgetCast<NounGame>( pPlanet->contact( j ) ); if ( pContact != NULL && pContact->enablePD() && !pPlanet->isFriend( pContact ) ) { float fRange = (worldPosition() - pContact->worldPosition()).magnitude(); if ( (!pBestTarget || fRange < fBestRange) && usable( pContact, false ) && !StructureDefense::isTargeted( pPlanet, pContact) ) { pBestTarget = pContact; fBestRange = fRange; } } } if ( pBestTarget ) { // set the target now, so no other beam weapon tries to destroy the projectile setTarget( pBestTarget ); // use the beam weapon on the projectile pStructure->useGadget( pBestTarget, this ); return true; } for(int j=0;j<pPlanet->contactCount();j++) { NounShip * pShip = WidgetCast<NounShip>( pPlanet->contact( j ) ); if ( pShip != NULL && pPlanet->isEnemy( pShip ) ) { float fRange = (worldPosition() - pShip->worldPosition()).magnitude(); if ( (!pBestTarget || fRange < fBestRange) && usable( pShip, false ) ) { pBestTarget = pShip; fBestRange = fRange; } } } if ( pBestTarget != NULL ) pStructure->useGadget( pBestTarget, this ); return true; } return false; }