Exemplo n.º 1
0
void NounShip::updateGadgets( dword nTick )
{
	PROFILE_FUNCTION();

	// check gadgets list, initialize internal gadget queues if needed
	if ( m_Gadgets.size() == 0 )
		initializeGadgets();

	// update energy, signature, and visibility of this ship
	int energy = m_Energy;
	float visibility = 1.0f;

	for(int i=0;i<m_Gadgets.size();i++)
	{
		NounGadget * pGadget = m_Gadgets[i];

		// use energy
		energy	= pGadget->useEnergy( nTick, energy );
		// update signature of this ship
		addSignature( nTick, pGadget->addSignature() );
		// update visibility
		visibility += pGadget->addVisibility();
	}

	m_Energy = Clamp( energy, 0, maxEnergy() );
	m_Visibility = Clamp( visibility, 0.0f, 1.0f );

	// use gadgets that are in the queue
	if ( m_UseGadgets.size() > 0 )
		if ( --m_UseGadgetTick <= 0 )
			useGadgets();
}
Exemplo n.º 2
0
CharString GadgetDrive::useTip( Noun * pTarget, bool shift ) const
{
	CharString tip;
	
	// usage information
	int generate = 0;
	if ( active() )
	{
		generate = damageRatioInv() * this->energy();
		// reduce energy based on velocity
		NounShip * pShip = WidgetCast<NounShip>( parent() );
		if ( pShip != NULL )
		{
			if ( energyFalloff() > 0 && pShip->maxVelocity() > 0.0f && pShip->velocity() > pShip->baseVelocity() )
			{
				float scale = ( pShip->velocity() - pShip->baseVelocity() ) / pShip->velocityRange();
				generate -= ( energyFalloff() * scale) ;
			}
		}
	}
	
	tip += CharString().format("\nEnergy p/s:<X;100>%.1f", ( generate * TICKS_PER_SECOND ) / 1000.0f );
	tip += CharString().format("\nEnergy Stored:<X;100>%.0f", maxEnergy() / 1000.0f );	
	
	return tip;
}
Exemplo n.º 3
0
//Constructor
Organism::Organism()
{
	//Keep track of id numbers
	static unsigned long int next_id = 0;
	id = next_id;
	++next_id;

	//First and Last name lengths
	int fNameLen = GetDistribution(std::uniform_int_distribution<int>(3, 8));
	int lNameLen = GetDistribution(std::uniform_int_distribution<int>(4, 12));

	//Generate name
	for (int i = 0; i < fNameLen; ++i) {
		fName += static_cast<char>(GetDistribution( std::uniform_int_distribution<int>(65, 90) ));
	}

	for (int i = 0; i < lNameLen; ++i) {
		lName += static_cast<char>(GetDistribution( std::uniform_int_distribution<int>(65, 90) ));
	}

	//Organism is not asleep at creation
	asleep = false;
	asleepSince = -1.0;

	//Organisms begin with energy normally distributed around 50% of their maximum
	energy = std::max(unsigned int(GetDistribution(std::normal_distribution<float>(maxEnergy() / 2, maxEnergy() / 10))), maxEnergy());

	//In case above energy distribution does not work out
	//energy = GetDistribution(std::uniform_int_distribution<int>(0, maxEnergy() ));

	age = 0.0;
}
Exemplo n.º 4
0
//Attempt to Awaken from Sleep
bool Organism::wakeUp(float curTime) {
	//Organism is Already Awake
	if (!asleep) return false;

	//Organism has not yet rested enough
	if (energy < 9 * maxEnergy() / 10) return false;

	//Note: Tweak Sleep Energy Gain multiplier
	energy += (curTime - asleepSince) * 0.05;

	//Adjust energy to maximum energy for Organism
	energy = std::max(energy, maxEnergy());

	asleep = false;
	asleepSince = -1.0;

	return true;
}
Exemplo n.º 5
0
//Attempt to Sleep
bool Organism::sleep(float curTime) {
	//Organism is already asleep
	if (asleep) return false;
	
	//Organism is well rested, so sleep is unnecessary
	if (energy > maxEnergy() / 2) return false;

	asleepSince = curTime;
	asleep = true;

	return true;
}
Exemplo n.º 6
0
void NounShip::setup()
{
	NounBody::setup();

	// clear all flags
	clearFlags( FLAG_ALL );
	// remove all damage
	m_Damage = 0;

	initializeGadgets();
	initializeEnhancements();
	initializeUnits();

	// update the characteristics of this ship
	updateCharacter();
	// fill energy
	m_Energy = maxEnergy();
}
Exemplo n.º 7
0
int GadgetDrive::addMaxEnergy() const
{
	return( maxEnergy() );
}