sources » TechnoClass » Ammo
// part of TechnoClass::Update():
// called every frame to update the state of this object
void TechnoClass::Update() {
// irrelevant code skipped
this->Reload(); // calls either UnitClass::Reload or TechnoClass::Reload :
//VehicleTypes get UnitClass::Reload, others get TechnoClass::Reload
}
// irrelevant code skipped
}
// part of TechnoClass::ReceiveDamage():
eDamageState TechnoClass::ReceiveDamage(int Damage) {
// irrelevant code skipped
if( this->GetType()->DamageReducesReadiness ) {
float ratio = Damage / this->GetType()->Strength;
ratio *= this->GetType()->ReadinessReductionMultiplier;
curAmmo = this->currentAmmo;
this->currentAmmo = int (curAmmo - this->GetType()->Ammo * ratio);
TechnoClass::Update_Reloading(this);
}
// irrelevant code skipped
}
void TechnoClass::Update_Reloading() {
MaxAmmo = this->GetType()->Ammo;
curAmmo = this->currentAmmo;
if ( curAmmo < MaxAmmo ) {
if ( curAmmo || this->GetType()->EmptyReload == -1 ) {
if ( this->GetType()->PipWrap )
v4 = this->currentAmmo / this->GetType()->PipWrap;// "/" in this case is an integer divisor, so 5/2 = 2 , not 2.5
else
v4 = 1;
v6 = v4 * v4 * this->GetType()->ReloadIncrement;
reloadDuration = v6 + this->GetType()->Reload;
this->ReloadTimer.StartingFrame = CurrentFrame;
this->ReloadTimer.Duration = reloadDuration;
} else {
reloadDuration = this->GetType()->EmptyReload;
this->ReloadTimer.StartingFrame = CurrentFrame;
this->ReloadTimer.Duration = reloadDuration;
}
}
}
void TechnoClass::Reload() {
MaxAmmo = this->GetType()->Ammo;
if ( MaxAmmo != -1 ) {
curAmmo = this->currentAmmo;
if ( curAmmo < result ) {
reloadStart = this->ReloadTimer.StartingFrame;
reloadDuration = this->ReloadTimer.Duration;
if ( reloadStart != -1 ) {
if ( CurrentFrame - reloadStart >= reloadDuration ) {
this->currentAmmo = curAmmo + 1;
this->ForceLayer(LAYER_GROUND);
TechnoClass::Update_Reloading(this);
return;
}
reloadDuration -= CurrentFrame - reloadStart;
}
if ( reloadDuration != 0 )
return;
this->currentAmmo = curAmmo + 1;
this->ForceLayer(LAYER_GROUND);
TechnoClass::Update_Reloading(this);
}
}
}
void UnitClass::Reload() {
if ( !this->UnitType->MobileFire ) {
if ( this->Locomotion->IsMoving() ) {
reloadStartFrame = this->ReloadTimer.StartingFrame;
reloadDuration = this->ReloadTimer.Duration;
if ( reloadStartFrame != -1 ) {
if ( CurrentFrame - reloadStartFrame >= reloadDuration ) {
TechnoClass::Reload(this);
return;
}
reloadDuration -= CurrentFrame - reloadStartFrame;
}
if ( reloadDuration > 0 ) {
reloadStartFrame = this->ReloadTimer.StartingFrame;
reloadDuration = this->ReloadTimer.Duration;
if ( reloadStartFrame != -1 ) {
if ( CurrentFrame - reloadStartFrame >= reloadDuration )
reloadDuration = 0;
else
reloadDuration -= CurrentFrame - reloadStartFrame;
}
this->ReloadTimer.StartingFrame = CurrentFrame;
this->ReloadTimer.Duration = reloadDuration + 1;
}
}
}
TechnoClass::Reload(this);
}