bool CUnit::AddBuildPower(float amount,CUnit* builder) { if(amount>0) { //build/repair if(!beingBuilt && health>=maxHealth) return false; lastNanoAdd=gs->frameNum; float part=amount/buildTime; if(beingBuilt) { float metalUse=metalCost*part; float energyUse=energyCost*part; if (gs->Team(builder->team)->metal >= metalUse && gs->Team(builder->team)->energy >= energyUse) { builder->UseMetal(metalUse); builder->UseEnergy(energyUse); health+=maxHealth*part; buildProgress+=part; if(buildProgress>=1) { if(health>maxHealth) health=maxHealth; FinishedBuilding(); } return true; } return false; } else { if(health<maxHealth) { health+=maxHealth*part; if(health>maxHealth) health=maxHealth; return true; } return false; } } else { //reclaim if(health<0) return false; restTime=0; float part=amount/buildTime; health+=maxHealth*part; if(beingBuilt) { builder->AddMetal(metalCost*-part); buildProgress+=part; if(buildProgress<0 || health<0) { KillUnit(false,true,0); return false; } } else { if(health<0) { builder->AddMetal(metalCost); KillUnit(false,true,0); return false; } } return true; } return false; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void C_BaseObject::OnDataChanged( DataUpdateType_t updateType ) { if (updateType == DATA_UPDATE_CREATED) { CreateBuildPoints(); } BaseClass::OnDataChanged( updateType ); // Did we just finish building? if ( m_bWasBuilding && !m_bBuilding ) { FinishedBuilding(); } // Did we just go active? bool bShouldBeActive = ShouldBeActive(); if ( !m_bWasActive && bShouldBeActive ) { OnGoActive(); } else if ( m_bWasActive && !bShouldBeActive ) { OnGoInactive(); } if ( m_bDisabled != m_bOldDisabled ) { if ( m_bDisabled ) { OnStartDisabled(); } else { OnEndDisabled(); } } if ( ( !IsBuilding() && m_iHealth != m_iOldHealth ) ) { // recalc our damage particle state BuildingDamageLevel_t damageLevel = CalculateDamageLevel(); if ( damageLevel != m_damageLevel ) { UpdateDamageEffects( damageLevel ); m_damageLevel = damageLevel; } } if ( m_bWasBuilding && !m_bBuilding ) { // Force update damage effect when finishing construction. BuildingDamageLevel_t damageLevel = CalculateDamageLevel(); UpdateDamageEffects( damageLevel ); m_damageLevel = damageLevel; } // Kill all particles when getting picked up. if ( !m_bWasCarried && m_bCarried ) { ParticleProp()->StopParticlesInvolving( this ); } if ( m_iHealth > m_iOldHealth && m_iHealth == m_iMaxHealth ) { // If we were just fully healed, remove all decals RemoveAllDecals(); } if ( GetOwner() == C_TFPlayer::GetLocalTFPlayer() ) { IGameEvent *event = gameeventmanager->CreateEvent( "building_info_changed" ); if ( event ) { event->SetInt( "building_type", GetType() ); event->SetInt( "object_mode", GetObjectMode() ); gameeventmanager->FireEventClientSide( event ); } } if ( IsPlacing() && GetSequence() != m_nObjectOldSequence ) { // Ignore server sequences while placing OnPlacementStateChanged( m_iLastPlacementPosValid > 0 ); } }
bool CUnit::AddBuildPower(float amount, CUnit* builder) { if (amount > 0.0f) { // build / repair if (!beingBuilt && (health >= maxHealth)) { return false; } lastNanoAdd = gs->frameNum; const float part = amount / buildTime; if (beingBuilt) { const float metalUse = (metalCost * part); const float energyUse = (energyCost * part); if ((gs->Team(builder->team)->metal >= metalUse) && (gs->Team(builder->team)->energy >= energyUse)) { builder->UseMetal(metalUse); builder->UseEnergy(energyUse); health += (maxHealth * part); buildProgress += part; if (buildProgress >= 1.0f) { if (health > maxHealth) { health = maxHealth; } FinishedBuilding(); } return true; } else { // update the energy and metal required counts gs->Team(builder->team)->metalPull += metalUse; gs->Team(builder->team)->energyPull += energyUse; } return false; } else { if (health < maxHealth) { health += maxHealth * part; if (health > maxHealth) { health = maxHealth; } return true; } return false; } } else { // reclaim if(isDead) return false; restTime=0; float part=amount/buildTime; health+=maxHealth*part; if(beingBuilt){ builder->AddMetal(metalCost*-part); buildProgress+=part; if(buildProgress<0 || health<0){ KillUnit(false,true,0); return false; } } else { if(health<0){ builder->AddMetal(metalCost); KillUnit(false,true,0); return false; } } return true; } return false; }