void AClashOfBallsBall::NotifyHit(class UPrimitiveComponent* MyComp, class AActor* Other, class UPrimitiveComponent* OtherComp, bool bSelfMoved, FVector HitLocation, FVector HitNormal, FVector NormalImpulse, const FHitResult& Hit) { Super::NotifyHit(MyComp, Other, OtherComp, bSelfMoved, HitLocation, HitNormal, NormalImpulse, Hit); bCanJump = true; DoDamage(Other); }
void AWeapon::FireProjectile() { FHitResult ObjectHit(EForceInit::ForceInit); FVector CameraLocation; FRotator CameraRotation; WeaponOwner->Controller->GetPlayerViewPoint(CameraLocation, CameraRotation); const FVector TraceStart = CameraLocation; const FVector TraceDirection = CameraRotation.Vector(); FRandomStream WeaponRandomStream(FMath::Rand()); const float SpreadCone = FMath::DegreesToRadians(Config.Spread * 0.5); const FVector ShotDirection = WeaponRandomStream.VRandCone(TraceDirection, SpreadCone, SpreadCone); const FVector TraceEnd = TraceStart + ShotDirection * Config.Range; FCollisionQueryParams TraceParams(FName(TEXT("TraceShot")), true, this); TraceParams.AddIgnoredActor(WeaponOwner); //Weapon Recoil Calculation WeaponOwner->AddControllerPitchInput(-(Config.Recoil)); if (FMath::FRand() >= 0.65f) { WeaponOwner->AddControllerYawInput(Config.Recoil); } else { WeaponOwner->AddControllerYawInput(-(Config.Recoil)); } const UWorld* World = GetWorld(); //debug code start////////////////////////////////// if (GEngine) { //GEngine->AddOnScreenDebugMessage(0, 5.f, FColor::Yellow, ShotDirection.ToString()); } DrawDebugLine( World, TraceStart, TraceEnd, FColor(255, 0, 0), false, 3, 0, 3.0 ); //debug code end//////////////////////////////////// bool HitDetected = false; if (World) { HitDetected = World->LineTraceSingle(ObjectHit, TraceStart, TraceEnd, ECollisionChannel::ECC_WorldDynamic, TraceParams); if (HitDetected) { DoDamage(ObjectHit); } } }
global func DoDmg(int iDmg, int iType, object pTarget, int iPrecision, int dmgplayer) { if(!pTarget) if(!(pTarget = this())) return(0); if(!iPrecision) iPrecision = 10; var dmg; var dmgdealer = dmgplayer-1; if(dmgdealer < 0) dmgdealer = GetController(pTarget); var red = pTarget->~OnDmg(iDmg, iType); //reduction // reduction dmg = iDmg*(100-red)*iPrecision; // Killer setzen if(this() && pTarget->GetOCF() & OCF_CrewMember || dmgplayer) { SetKiller(dmgdealer, pTarget); } //Schaden machen var pFrom; //if(pTarget != this()) pFrom = this; pTarget->~LastDamageType(iType); pTarget->~OnHit(dmg/1000, iType, pFrom,dmg); // testweise: Schadensdings //var rgb = RGB(255,0,0); //if(dmg/1000 != 0){ // if(dmg < 0) rgb = RGB(0,255,0); // CreateObject(CMBT,AbsX(GetX(pTarget)),AbsY(GetY(pTarget)),-1) -> Set(0, Format("%d",dmg/1000), rgb); //} if(GetCategory(pTarget) & C4D_Living) return(DoEnergy(-dmg,pTarget, true)); return(DoDamage(dmg/1000,pTarget)); }
void Player::CheckEnemyDamageRadius(Enemy* pEnemy) { if (IsDead()) { return; } if (pEnemy->GetAttackEnabled() == false) { // If attack is not enabled, just return return; } vec3 distance = GetCenter() - pEnemy->GetCenter(); float lengthToEnemy = length(distance); if (lengthToEnemy <= m_radius + pEnemy->GetAttackRadius()) { vec3 distance_minus_y = distance; distance_minus_y.y = 0.0f; vec3 direction = normalize(distance_minus_y); // Figure out the attack vector, based on the attack rotation float enemyRotation = pEnemy->GetRotation(); float attackRotation = pEnemy->GetAttackRotation(); float angle = DegToRad(enemyRotation + attackRotation); vec3 attackDirection = vec3(sin(angle), 0.0f, cos(angle)); float dotProduct = dot(direction, attackDirection); if (dotProduct > pEnemy->GetAttackSegmentAngle()) // Check if we are within the attack segment { vec3 knockbackDirection = (direction*2.0f) + vec3(0.0f, 1.0f, 0.0f); knockbackDirection = normalize(knockbackDirection); Colour damageColour = Colour(1.0f, 1.0f, 1.0f); float knockbackAmount = 16.0f; DoDamage(5.0f, damageColour, knockbackDirection, knockbackAmount, true); } } }
void Player::CheckProjectileDamageRadius(Projectile* pProjectile) { if (IsDead()) { return; } if (pProjectile->CanAttackPlayer() == false && pProjectile->IsReturnToPlayer() == false) { return; } vec3 projectileHitboxCenter = GetProjectileHitboxCenter(); vec3 toProjectile = projectileHitboxCenter - pProjectile->GetCenter(); bool hitByProjectile = false; if (m_eProjectileHitboxType == eProjectileHitboxType_Sphere) { if (length(toProjectile) < GetRadius() + pProjectile->GetRadius()) { hitByProjectile = true; } } else if (m_eProjectileHitboxType == eProjectileHitboxType_Cube) { Plane3D planes[6]; Matrix4x4 rotationMatrix; rotationMatrix.SetYRotation(DegToRad(GetRotation())); planes[0] = Plane3D(rotationMatrix * vec3(-1.0f, 0.0f, 0.0f), projectileHitboxCenter + (rotationMatrix * vec3(m_projectileHitboxXLength, 0.0f, 0.0f))); planes[1] = Plane3D(rotationMatrix * vec3(1.0f, 0.0f, 0.0f), projectileHitboxCenter + (rotationMatrix * vec3(-m_projectileHitboxXLength, 0.0f, 0.0f))); planes[2] = Plane3D(rotationMatrix * vec3(0.0f, -1.0f, 0.0f), projectileHitboxCenter + (rotationMatrix * vec3(0.0f, m_projectileHitboxYLength, 0.0f))); planes[3] = Plane3D(rotationMatrix * vec3(0.0f, 1.0f, 0.0f), projectileHitboxCenter + (rotationMatrix * vec3(0.0f, -m_projectileHitboxYLength, 0.0f))); planes[4] = Plane3D(rotationMatrix * vec3(0.0f, 0.0f, -1.0f), projectileHitboxCenter + (rotationMatrix * vec3(0.0f, 0.0f, m_projectileHitboxZLength))); planes[5] = Plane3D(rotationMatrix * vec3(0.0f, 0.0f, 1.0f), projectileHitboxCenter + (rotationMatrix * vec3(0.0f, 0.0f, -m_projectileHitboxZLength))); float distance; int inside = 0; vec3 normal; for (int i = 0; i < 6; i++) { distance = planes[i].GetPointDistance(pProjectile->GetCenter()); if (distance < -pProjectile->GetRadius()) { // Outside... } else if (distance < pProjectile->GetRadius()) { // Intersecting.. inside++; } else { // Inside... inside++; } } if (inside == 6) { hitByProjectile = true; } } if (hitByProjectile) { if (pProjectile->IsReturnToPlayer()) { if (pProjectile->CanCatch()) { pProjectile->PlayerCatch(); m_bCanThrowWeapon = true; if (IsBoomerang()) { m_pVoxelCharacter->SetRenderRightWeapon(true); m_pVoxelCharacter->BlendIntoAnimation(AnimationSections_FullBody, true, AnimationSections_FullBody, "SwordAttack1", 0.01f); m_pVoxelCharacter->BlendIntoAnimation(AnimationSections_Right_Arm_Hand, false, AnimationSections_Right_Arm_Hand, "SwordAttack1", 0.01f); // Start weapon trails if (m_pVoxelCharacter->GetRightWeapon()) { if (m_pVoxelCharacter->IsRightWeaponLoaded()) { m_pVoxelCharacter->GetRightWeapon()->StartWeaponTrails(); } } } } } else { vec3 knockbackDirection = (normalize(pProjectile->GetVelocity())*2.0f) + vec3(0.0f, 1.0f, 0.0f); knockbackDirection = normalize(knockbackDirection); Colour damageColour = Colour(1.0f, 1.0f, 1.0f); float knockbackAmount = 16.0f; DoDamage(15.0f, damageColour, knockbackDirection, knockbackAmount, false); pProjectile->Explode(); } } }
void CFeature::Kill(float3& impulse) { DamageArray damage; DoDamage(damage*(health+1), 0, impulse); }
global func DoDmg(int iDmg, int iType, object pTarget, int iPrecision, int dmgplayer, id idKillIcon, int iKillAttachment) { //Existenz bestätigen if(!pTarget) if(!(pTarget = this)) return; if(!iPrecision) iPrecision = 10; var dmg, dmgdealer = dmgplayer-1; if(dmgdealer < 0) dmgdealer = GetController(pTarget); var red = pTarget->~OnDmg(iDmg, iType); dmg = iDmg*(100-red)*iPrecision; if(!dmg || red == 100) return; //Killer setzen if(this && pTarget->GetOCF() & OCF_CrewMember || dmgplayer) SetKiller(dmgdealer, pTarget); if(GetOCF(pTarget) & OCF_CrewMember) { if(!idKillIcon && this)//Kein Killicon? { idKillIcon = this->~GetKillIcon(); if(!idKillIcon) idKillIcon = GetID(this); if(idKillIcon->~IsClonk()) idKillIcon = 0; } if(!idKillIcon) { if(iType) { if(iType == DMG_Fire) idKillIcon = GSAM; else if(iType == DMG_Explosion) idKillIcon = BOOM; else if(iType == DMG_Energy) idKillIcon = ENAM; else if(iType == DMG_Bio) idKillIcon = GLOB; else if(iType == DMG_Projectile) idKillIcon = STAM; } else idKillIcon = KAMB; } pTarget->~KillIcon(idKillIcon); pTarget->~KillAttachment(iKillAttachment, true); } //Schaden machen var pFrom; if(pTarget != this) pFrom = this; if(!pFrom) pFrom = GetCrew(dmgdealer); //Wird gerade eingeblendet: Entfernen if(GetEffect("FadeIn4K", this)) { EffectVar(0, this, GetEffect("FadeIn4K", this)) = 0; SetClrModulation(RGBa(255, 255, 255, 0), this); } pTarget->~LastDamageType(iType); pTarget->~OnHit(dmg/1000, iType, pFrom); if(GetCategory(pTarget) & C4D_Living) return DoEnergy(-dmg, pTarget, true, 0, dmgplayer); return DoDamage(dmg/1000, pTarget, 0, dmgplayer); }
void CUnit::Kill(float3& impulse) { DamageArray da; DoDamage(da*(health/da[armorType]), 0, impulse); }
void CUnit::SlowUpdate() { --nextPosErrorUpdate; if(nextPosErrorUpdate==0) { float3 newPosError(gs->randVector()); newPosError.y*=0.2; if(posErrorVector.dot(newPosError)<0) newPosError=-newPosError; posErrorDelta=(newPosError-posErrorVector)*(1.0/256); nextPosErrorUpdate=16; } for(int a=0; a<gs->activeAllyTeams; ++a) { if(losStatus[a] & LOS_INTEAM) { } else if(loshandler->InLos(this,a)) { if(!(losStatus[a]&LOS_INLOS)) { int prevLosStatus = losStatus[a]; if(mobility || beingBuilt) { losStatus[a]|=(LOS_INLOS | LOS_INRADAR); } else { losStatus[a]|=(LOS_INLOS | LOS_INRADAR | LOS_PREVLOS | LOS_CONTRADAR); } if(!(prevLosStatus&LOS_INRADAR)) { globalAI->UnitEnteredRadar(this,a); } globalAI->UnitEnteredLos(this,a); } } else if(radarhandler->InRadar(this,a)) { if((losStatus[a] & LOS_INLOS)) { globalAI->UnitLeftLos(this,a); losStatus[a]&= ~LOS_INLOS; } else if(!(losStatus[a] & LOS_INRADAR)) { losStatus[a]|= LOS_INRADAR; globalAI->UnitEnteredRadar(this,a); } } else { if((losStatus[a]&LOS_INRADAR)) { if((losStatus[a]&LOS_INLOS)) { globalAI->UnitLeftLos(this,a); globalAI->UnitLeftRadar(this,a); } else { globalAI->UnitLeftRadar(this,a); } losStatus[a]&= ~(LOS_INLOS | LOS_INRADAR | LOS_CONTRADAR); } } } if(paralyzeDamage>0) { paralyzeDamage-=maxHealth*(16.f/30.f/40.f); if(paralyzeDamage<0) paralyzeDamage=0; if(paralyzeDamage<health) stunned=false; } if(stunned) { isCloaked=false; return; } if(selfDCountdown && !stunned) { selfDCountdown--; if(selfDCountdown<=1) { if(!beingBuilt) KillUnit(true,false,0); else KillUnit(false,true,0); //avoid unfinished buildings making an explosion selfDCountdown=0; return; } ENTER_MIXED; if(selfDCountdown&1 && team==gu->myTeam) info->AddLine("%s: Self destruct in %i s",unitDef->humanName.c_str(),selfDCountdown/2); ENTER_SYNCED; } if(beingBuilt) { if(lastNanoAdd<gs->frameNum-200) { health-=maxHealth/(buildTime*0.03); buildProgress-=1/(buildTime*0.03); AddMetal(metalCost/(buildTime*0.03)); if(health<0) KillUnit(false,true,0); } return; } //below is stuff that shouldnt be run while being built lastSlowUpdate=gs->frameNum; commandAI->SlowUpdate(); moveType->SlowUpdate(); metalMake = metalMakeI + metalMakeold; metalUse = metalUseI+ metalUseold; energyMake = energyMakeI + energyMakeold; energyUse = energyUseI + energyUseold; metalMakeold = metalMakeI; metalUseold = metalUseI; energyMakeold = energyMakeI; energyUseold = energyUseI; metalMakeI=metalUseI=energyMakeI=energyUseI=0; AddMetal(unitDef->metalMake*0.5f); if(activated) { if(UseEnergy(unitDef->energyUpkeep*0.5f)) { if(unitDef->isMetalMaker) { AddMetal(unitDef->makesMetal*0.5f*uh->metalMakerEfficiency); uh->metalMakerIncome+=unitDef->makesMetal; } else { AddMetal(unitDef->makesMetal*0.5f); } if(unitDef->extractsMetal>0) AddMetal(metalExtract * 0.5f); } UseMetal(unitDef->metalUpkeep*0.5f); if(unitDef->windGenerator>0) { if(wind.curStrength > unitDef->windGenerator) { AddEnergy(unitDef->windGenerator*0.5f); } else { AddEnergy(wind.curStrength*0.5f); } } } AddEnergy(energyTickMake*0.5f); if(health<maxHealth) { health += unitDef->autoHeal; if(restTime > unitDef->idleTime) { health += unitDef->idleAutoHeal; } if(health>maxHealth) health=maxHealth; } bonusShieldSaved+=0.05f; residualImpulse*=0.6; if(wantCloak) { if(helper->GetClosestEnemyUnitNoLosTest(pos,unitDef->decloakDistance,allyteam)) { curCloakTimeout=gs->frameNum+cloakTimeout; isCloaked=false; } if(isCloaked || gs->frameNum>=curCloakTimeout) { float cloakCost=unitDef->cloakCost; if(speed.SqLength()>0.2) cloakCost=unitDef->cloakCostMoving; if(UseEnergy(cloakCost * 0.5f)) { isCloaked=true; } else { isCloaked=false; } } else { isCloaked=false; } } else { isCloaked=false; } if(uh->waterDamage && (physicalState==CSolidObject::Floating || (physicalState==CSolidObject::OnGround && pos.y<=-3 && readmap->mipHeightmap[1][int((pos.z/(SQUARE_SIZE*2))*gs->hmapx+(pos.x/(SQUARE_SIZE*2)))]<-1))) { DoDamage(DamageArray()*uh->waterDamage,0,ZeroVector); } if(unitDef->canKamikaze) { if(fireState==2) { CUnit* u=helper->GetClosestEnemyUnitNoLosTest(pos,unitDef->kamikazeDist,allyteam); if(u && u->physicalState!=CSolidObject::Flying && u->speed.dot(pos - u->pos)<=0) //self destruct when unit start moving away from mine, should maximize damage KillUnit(true,false,0); } if(userTarget && userTarget->pos.distance(pos)<unitDef->kamikazeDist) KillUnit(true,false,0); if(userAttackGround && userAttackPos.distance(pos)<unitDef->kamikazeDist) KillUnit(true,false,0); } if(!weapons.empty()) { haveTarget=false; haveUserTarget=false; //aircraft does not want this if (moveType->useHeading) { frontdir=GetVectorFromHeading(heading); if(upright || !unitDef->canmove) { updir=UpVector; rightdir=frontdir.cross(updir); } else { updir=ground->GetNormal(pos.x,pos.z); rightdir=frontdir.cross(updir); rightdir.Normalize(); frontdir=updir.cross(rightdir); } } if(!dontFire) { for(vector<CWeapon*>::iterator wi=weapons.begin(); wi!=weapons.end(); ++wi) { CWeapon* w=*wi; if(userTarget && !w->haveUserTarget && (haveDGunRequest || !unitDef->canDGun || !w->weaponDef->manualfire)) w->AttackUnit(userTarget,true); else if(userAttackGround && !w->haveUserTarget && (haveDGunRequest || !unitDef->canDGun || !w->weaponDef->manualfire)) w->AttackGround(userAttackPos,true); w->SlowUpdate(); if(w->targetType==Target_None && fireState>0 && lastAttacker && lastAttack+200>gs->frameNum) w->AttackUnit(lastAttacker,false); } } } if(moveType->progressState == CMoveType::Active) { if(/*physicalState == OnGround*/seismicSignature && !(losStatus[gu->myAllyTeam] & LOS_INLOS) && radarhandler->InSeismicDistance(this, gu->myAllyTeam)) new CSimpleGroundFlash(pos + float3(radarhandler->radarErrorSize[gu->myAllyTeam]*(0.5f-gu->usRandFloat()),0,radarhandler->radarErrorSize[gu->myAllyTeam]*(0.5f-gu->usRandFloat())), ph->seismictex, 30, 15, 0, seismicSignature, 1, float3(0.8,0.0,0.0)); } CalculateTerrainType(); UpdateTerrainType(); }
void CFeature::Kill(const float3& impulse, bool crushKill) { crushKilled = crushKill; DamageArray damage; DoDamage(damage * (health + 1.0f), impulse); }