// // ResourceObj::GiveResource // // Give resource // U32 ResourceObj::GiveResource(U32 amount) { // How much space is left ASSERT(resource <= ResourceType()->GetResourceMax()) U32 left = ResourceType()->GetResourceMax() - resource; if (amount > left) { amount = left; } // Is this object in a cluster if (currentCluster) { currentCluster->ai.AddResource(amount); } // Add to the resource resource += amount; AdjustResource(); // Return the amount actually added return (amount); }
// // ResourceObj::TakeResource // // Take some resource // U32 ResourceObj::TakeResource(U32 want) { if (want > resource) { want = resource; // If this resource doesn't regenerate then mark it for deletion if (!ResourceType()->resourceRate) { GameObjCtrl::MarkForDeletion(this); } } // Is this object in a cluster if (currentCluster) { currentCluster->ai.RemoveResource(want); } // Remove from the resource resource -= want; AdjustResource(); // Return the amount that was available return (want); }
// // ResourceObj::LoadState // // Load a state configuration scope // void ResourceObj::LoadState(FScope *fScope) { // Call parent scope first MapObj::LoadState(fScope); if ((fScope = fScope->GetFunction(SCOPE_CONFIG, FALSE)) != NULL) { FScope *sScope; while ((sScope = fScope->NextFunction()) != NULL) { switch (sScope->NameCrc()) { case 0x5457F5AB: // "TeamHaveSeen" teamsHaveSeen = Game::TeamBitfield(StdLoad::TypeU32(sScope)); break; case 0x7C8A86BB: // "ResourcePercent" resource = StdLoad::TypePercentage(sScope, ResourceType()->GetResourceMax()); AdjustResource(); break; } } } }
// // ResourceObj::Equip // // Equip the object // void ResourceObj::Equip() { // Default the amount of resource to the maximum resource = ResourceType()->GetResourceMax(); AdjustResource(); // Call parent scope first MapObj::Equip(); }
void City::FinishProduction( const HashedString& hProduction, int iAmount ) { AdjustResource( hProduction, iAmount ); m_Faction->AdjustProduction( hProduction, iAmount ); const Engine::Entity* pData = FindProducible( hProduction ); if ( pData ) { Engine::Entity* pEntity = Engine::Entity::Instantiate( pData ); pEntity->SetTransform( m_pOwner->GetTransform() ); } else { throw "Missing data"; } }
// // ResourceObj::SetResource // // Set resource // void ResourceObj::SetResource(F32 percentage) { // Is this object in a cluster if (currentCluster) { currentCluster->ai.RemoveResource(resource); } resource = U32(percentage * F32(ResourceType()->GetResourceMax())); AdjustResource(); // Is this object in a cluster if (currentCluster) { currentCluster->ai.AddResource(resource); } }