void CExplosiveProjectile::Update() { // if (!luaMoveCtrl) { // pos += speed; // speed.y += mygravity; // } CProjectile::Update(); if (--ttl == 0) { Collision(); } else { if (ttl > 0) { gCEG->Explosion(cegID, pos, ttl, areaOfEffect, NULL, 0.0f, NULL, speed); } } if (weaponDef->noExplode) { if (TraveledRange()) { CProjectile::Collision(); } } curTime += invttl; if (curTime > 1) { curTime = 1; } UpdateGroundBounce(); }
void CFlameProjectile::Update() { if (!luaMoveCtrl) { SetPosition(pos + speed); UpdateGroundBounce(); SetVelocityAndSpeed(speed + spread); } UpdateInterception(); radius = radius + weaponDef->sizeGrowth; sqRadius = radius * radius; drawRadius = radius * weaponDef->collisionSize; curTime += invttl; if (curTime > physLife) { checkCol = false; } if (curTime > 1) { curTime = 1; deleteMe = true; } explGenHandler->GenExplosion(cegID, pos, speed, curTime, 0.0f, 0.0f, NULL, NULL); }
void CLaserProjectile::Update() { if (!luaMoveCtrl) { pos += speed; } if (checkCol) { // normal curLength += speedf; if (curLength > length) curLength = length; } else { // fading out after hit if (stayTime <= 0) curLength -= speedf; else stayTime--; if (curLength <= 0) { deleteMe = true; curLength = 0; } } if (--ttl > 0 && checkCol) { gCEG->Explosion(cegID, pos, ttl, intensity, NULL, 0.0f, NULL, speed); } if (weaponDef->visuals.hardStop) { if (ttl == 0 && checkCol) { checkCol = false; speed = ZeroVector; if (curLength < length) { // if the laser wasn't fully extended yet, // remember how long until it would have been // fully extended stayTime = int(1 + (length - curLength) / speedf); } } } else { if (ttl < 5 && checkCol) { intensity -= intensityFalloff * 0.2f; if (intensity <= 0) { deleteMe = true; intensity = 0; } } } if (!luaMoveCtrl) { float3 tempSpeed = speed; UpdateGroundBounce(); if (tempSpeed != speed) { dir = speed; dir.Normalize(); } } }
void CEmgProjectile::Update() { if (!luaMoveCtrl) { pos += speed; } if (--ttl < 0) { intensity -= 0.1f; if (intensity <= 0){ deleteMe = true; intensity = 0; } } else { gCEG->Explosion(cegID, pos, ttl, intensity, NULL, 0.0f, NULL, speed); } UpdateGroundBounce(); }
void CEmgProjectile::Update(void) { if (!luaMoveCtrl) { pos += speed; } if (--ttl < 0) { intensity -= 0.1f; if (intensity <= 0){ deleteMe = true; intensity = 0; } } else { if (!cegTag.empty()) { ceg.Explosion(pos, ttl, intensity, 0x0, 0.0f, 0x0, speed); } } UpdateGroundBounce(); }
void CEmgProjectile::Update(void) { pos += speed; ttl--; if (ttl < 0) { intensity -= 0.1f; if (intensity <= 0){ deleteMe = true; intensity = 0; } } else { if (cegTag.size() > 0) { ceg.Explosion(pos, ttl, intensity, 0x0, 0.0f, 0x0, speed); } } UpdateGroundBounce(); }
void CWeaponProjectile::Update() { //pos+=speed; //if(weaponDef->gravityAffected) // speed.y+=mapInfo->map.gravity; //if(weaponDef->noExplode) //{ // if(TraveledRange()) // CProjectile::Collision(); //} //if(speed.Length()<weaponDef->maxvelocity) // speed += dir*weaponDef->weaponacceleration CProjectile::Update(); UpdateGroundBounce(); }
void CFlameProjectile::Update() { if (!luaMoveCtrl) { SetPosition(pos + speed); UpdateGroundBounce(); SetVelocityAndSpeed(speed + spread); } UpdateInterception(); radius = radius + weaponDef->sizeGrowth; sqRadius = radius * radius; drawRadius = radius * weaponDef->collisionSize; curTime += invttl; checkCol &= (curTime <= physLife); curTime = std::min(curTime, 1.0f); deleteMe |= (curTime >= 1.0f); explGenHandler->GenExplosion(cegID, pos, speed, curTime, 0.0f, 0.0f, nullptr, nullptr); }
void CFlameProjectile::Update(void) { pos += speed; UpdateGroundBounce(); speed += spread; radius = radius + weaponDef->sizeGrowth; sqRadius = radius * radius; drawRadius = radius * weaponDef->collisionSize; curTime += invttl; if (curTime > physLife) checkCol = false; if (curTime > 1) { curTime = 1; deleteMe = true; } if (cegTag.size() > 0) { ceg.Explosion(pos, curTime, intensity, 0x0, 0.0f, 0x0, speed); } }
void CFireBallProjectile::Update() { if (checkCol) { pos += speed; if (weaponDef->gravityAffected) speed.y += mapInfo->map.gravity; // g�ra om till ttl sedan kanske if (weaponDef->noExplode) { if (TraveledRange()) checkCol = false; } EmitSpark(); } else { if (sparks.size() == 0) deleteMe = true; } for (unsigned int i = 0; i < sparks.size(); i++) { sparks[i].ttl--; if (sparks[i].ttl == 0) { sparks.pop_back(); break; } if (checkCol) sparks[i].pos += sparks[i].speed; sparks[i].speed *= 0.95f; } if (cegTag.size() > 0) { ceg.Explosion(pos, ttl, (sparks.size() > 0)? sparks[0].size: 0.0f, 0x0, 0.0f, 0x0, speed); } UpdateGroundBounce(); }
void CFireBallProjectile::Update() { if (checkCol) { if (!luaMoveCtrl) { pos += speed; if (weaponDef->gravityAffected) { speed.y += mygravity; } } if (weaponDef->noExplode && TraveledRange()) { checkCol = false; } EmitSpark(); } else { if (sparks.empty()) { deleteMe = true; } } for (unsigned int i = 0; i < sparks.size(); i++) { sparks[i].ttl--; if (sparks[i].ttl == 0) { sparks.pop_back(); break; } if (checkCol) { sparks[i].pos += sparks[i].speed; } sparks[i].speed *= 0.95f; } gCEG->Explosion(cegID, pos, ttl, !sparks.empty() ? sparks[0].size : 0.0f, NULL, 0.0f, NULL, speed); UpdateGroundBounce(); UpdateInterception(); }
void CExplosiveProjectile::Update() { CProjectile::Update(); if (--ttl == 0) { Collision(); } else { if (ttl > 0) { explGenHandler->GenExplosion(cegID, pos, speed, ttl, damages->damageAreaOfEffect, 0.0f, NULL, NULL); } } curTime += invttl; curTime = std::min(curTime, 1.0f); if (weaponDef->noExplode && TraveledRange()) { CProjectile::Collision(); return; } UpdateGroundBounce(); UpdateInterception(); }
void CFlameProjectile::Update() { if (!luaMoveCtrl) { pos += speed; UpdateGroundBounce(); speed += spread; } UpdateInterception(); radius = radius + weaponDef->sizeGrowth; sqRadius = radius * radius; drawRadius = radius * weaponDef->collisionSize; curTime += invttl; if (curTime > physLife) { checkCol = false; } if (curTime > 1) { curTime = 1; deleteMe = true; } gCEG->Explosion(cegID, pos, curTime, 0.0f, NULL, 0.0f, NULL, speed); }
void CEmgProjectile::Update() { // disable collisions when ttl reaches 0 since the // projectile will travel far past its range while // fading out checkCol &= (ttl >= 0); deleteMe |= (intensity <= 0.0f); if (!luaMoveCtrl) { pos += speed; } if (ttl <= 0) { // fade out over the next 10 frames at most intensity -= 0.1f; intensity = std::max(intensity, 0.0f); } else { explGenHandler->GenExplosion(cegID, pos, speed, ttl, intensity, 0.0f, NULL, NULL); } UpdateGroundBounce(); UpdateInterception(); --ttl; }
void CMissileProjectile::Update() { if (--ttl > 0) { if (!luaMoveCtrl) { if (curSpeed < maxSpeed) { curSpeed += weaponDef->weaponacceleration; } float3 targSpeed(ZeroVector); if (weaponDef->tracks && target) { CSolidObject* so = dynamic_cast<CSolidObject*>(target); CWeaponProjectile* po = dynamic_cast<CWeaponProjectile*>(target); targetPos = target->pos; if (so) { targetPos = so->aimPos; targSpeed = so->speed; if (owner()) { CUnit* u = dynamic_cast<CUnit*>(so); if (u) { targetPos = CGameHelper::GetUnitErrorPos(u, owner()->allyteam, true); } } } if (po) { targSpeed = po->speed; } } if (isWobbling) { --wobbleTime; if (wobbleTime == 0) { float3 newWob = gs->randVector(); wobbleDif = (newWob - wobbleDir) * (1.0f / 16); wobbleTime = 16; } wobbleDir += wobbleDif; dir += wobbleDir * weaponDef->wobble * (owner()? (1.0f - owner()->limExperience * 0.5f): 1); dir.Normalize(); } if (isDancing) { --danceTime; if (danceTime <= 0) { danceMove = gs->randVector() * weaponDef->dance - danceCenter; danceCenter += danceMove; danceTime = 8; } pos += danceMove; } const float3 orgTargPos = targetPos; const float3 targetDir = (targetPos - pos).SafeNormalize(); const float dist = pos.distance(targetPos) + 0.1f; if (extraHeightTime > 0) { extraHeight -= extraHeightDecay; --extraHeightTime; targetPos.y += extraHeight; if (dir.y <= 0.0f) { // missile has reached apex, smoothly transition // to targetDir (can still overshoot when target // is too close or height difference too large) const float horDiff = (targetPos - pos).Length2D() + 0.01f; const float verDiff = (targetPos.y - pos.y) + 0.01f; const float dirDiff = math::fabs(targetDir.y - dir.y); const float ratio = math::fabs(verDiff / horDiff); dir.y -= (dirDiff * ratio); } else { // missile is still ascending dir.y -= (extraHeightDecay / dist); } } float3 dif = (targetPos + targSpeed * (dist / maxSpeed) * 0.7f - pos).SafeNormalize(); float3 dif2 = dif - dir; if (dif2.SqLength() < Square(weaponDef->turnrate)) { dir = dif; } else { dif2 -= (dir * (dif2.dot(dir))); dif2.SafeNormalize(); dir += (dif2 * weaponDef->turnrate); dir.SafeNormalize(); } targetPos = orgTargPos; speed = dir * curSpeed; } gCEG->Explosion(cegID, pos, ttl, areaOfEffect, NULL, 0.0f, NULL, dir); } else { if (weaponDef->selfExplode) { Collision(); } else { // only when TTL <= 0 do we (missiles) // get influenced by gravity and drag if (!luaMoveCtrl) { speed *= 0.98f; speed.y += mygravity; dir = speed; dir.SafeNormalize(); } } } if (!luaMoveCtrl) { pos += speed; } age++; numParts++; if (weaponDef->visuals.smokeTrail && !(age & 7)) { CSmokeTrailProjectile* tp = new CSmokeTrailProjectile( pos, oldSmoke, dir, oldDir, owner(), age == 8, false, 7, SMOKE_TIME, 0.6f, drawTrail, 0, weaponDef->visuals.texture2 ); oldSmoke = pos; oldDir = dir; numParts = 0; useAirLos = tp->useAirLos; if (!drawTrail) { const float3 camDir = (pos - camera->pos).ANormalize(); if ((camera->pos.distance(pos) * 0.2f + (1 - math::fabs(camDir.dot(dir))) * 3000) > 300) { drawTrail = true; } } } UpdateInterception(); UpdateGroundBounce(); }
void CTorpedoProjectile::Update() { if (!weaponDef->submissile && pos.y > -3.0f) { // tracking etc only works when we are underwater if (!luaMoveCtrl) { speed.y += mygravity; dir.y = std::min(dir.y, 0.0f); dir = speed; dir.Normalize(); } } else { if (!weaponDef->submissile && pos.y-speed.y > -3.0f) { // level out torpedo a bit when hitting water if (!luaMoveCtrl) { dir.y *= 0.5f; dir.Normalize(); } } if (--ttl > 0) { if (!luaMoveCtrl) { if (curSpeed < maxSpeed) { curSpeed += std::max(0.2f, tracking); } if (target) { float3 targPos; if ((target->midPos - pos).SqLength() < 150 * 150 || !owner()) { targPos = target->midPos; } else { targPos = helper->GetUnitErrorPos(target, owner()->allyteam); } if (!weaponDef->submissile && targPos.y > 0) { targPos.y = 0; } float dist = targPos.distance(pos); float3 dif = (targPos + target->speed * (dist / maxSpeed) * 0.7f - pos).Normalize(); float3 dif2 = dif - dir; if (dif2.Length() < tracking) { dir = dif; } else { dif2 -= dir * (dif2.dot(dir)); dif2.SafeNormalize(); dir += dif2 * tracking; dir.SafeNormalize(); } } speed = dir * curSpeed; } gCEG->Explosion(cegID, pos, ttl, areaOfEffect, NULL, 0.0f, NULL, speed); } else { if (!luaMoveCtrl) { speed *= 0.98f; speed.y += mygravity; dir = speed; dir.SafeNormalize(); } } } if (!luaMoveCtrl) { pos += speed; } if (pos.y < -2.0f) { --nextBubble; if (nextBubble == 0) { nextBubble = 1 + (int) (gs->randFloat() * 1.5f); const float3 pspeed = (gs->randVector() * 0.1f) + float3(0.0f, 0.2f, 0.0f); new CBubbleProjectile( pos + gs->randVector(), pspeed, 40 + gs->randFloat() * 30, 1 + gs->randFloat() * 2, 0.01f, owner(), 0.3f + gs->randFloat() * 0.3f ); } } UpdateGroundBounce(); }
void CWeaponProjectile::Update() { CProjectile::Update(); UpdateGroundBounce(); UpdateInterception(); }
void CTorpedoProjectile::Update() { // tracking only works when we are underwater if (!weaponDef->submissile && pos.y > 0.0f) { if (!luaMoveCtrl) { // must update dir and speed.w here SetVelocityAndSpeed(speed + (UpVector * mygravity)); } } else { if (--ttl > 0) { if (!luaMoveCtrl) { float3 targetVel; if (speed.w < maxSpeed) speed.w += std::max(0.2f, tracking); if (target != NULL) { const CSolidObject* so = dynamic_cast<const CSolidObject*>(target); const CWeaponProjectile* po = dynamic_cast<const CWeaponProjectile*>(target); targetPos = target->pos; if (so != NULL) { targetPos = so->aimPos; targetVel = so->speed; if (allyteamID != -1 && pos.SqDistance(so->aimPos) > Square(150.0f)) { const CUnit* u = dynamic_cast<const CUnit*>(so); if (u != NULL) { targetPos = u->GetErrorPos(allyteamID, true); } } } if (po != NULL) { targetVel = po->speed; } } if (!weaponDef->submissile && targetPos.y > 0.0f) { targetPos.y = 0.0f; } const float3 targetLeadVec = targetVel * (pos.distance(targetPos) / maxSpeed) * 0.7f; const float3 targetLeadDir = (targetPos + targetLeadVec - pos).Normalize(); float3 targetDirDif = targetLeadDir - dir; if (targetDirDif.Length() < tracking) { dir = targetLeadDir; } else { // <tracking> is the projectile's turn-rate targetDirDif = (targetDirDif - (dir * targetDirDif.dot(dir))).SafeNormalize(); dir = (dir + (targetDirDif * tracking)).SafeNormalize(); } // do not need to update dir or speed.w here CWorldObject::SetVelocity(dir * speed.w); } explGenHandler->GenExplosion(cegID, pos, speed, ttl, areaOfEffect, 0.0f, NULL, NULL); } else { if (!luaMoveCtrl) { // must update dir and speed.w here SetVelocityAndSpeed((speed * 0.98f) + (UpVector * mygravity)); } } } if (!luaMoveCtrl) { SetPosition(pos + speed); } if (pos.y < -2.0f) { --nextBubble; if (nextBubble == 0) { nextBubble = 1 + (int) (gs->randFloat() * 1.5f); const float3 pspeed = (gs->randVector() * 0.1f) + float3(0.0f, 0.2f, 0.0f); new CBubbleProjectile( owner(), pos + gs->randVector(), pspeed, 40 + gs->randFloat() * GAME_SPEED, 1 + gs->randFloat() * 2, 0.01f, 0.3f + gs->randFloat() * 0.3f ); } } UpdateGroundBounce(); UpdateInterception(); }
void CWeaponProjectile::Update() { CProjectile::Update(); UpdateGroundBounce(); }
void CTorpedoProjectile::Update() { if (!weaponDef->submissile && pos.y > -3.0f) { // tracking etc only works when we are underwater if (!luaMoveCtrl) { speed.y += mygravity; dir = speed; dir.Normalize(); } } else { if (!weaponDef->submissile && pos.y-speed.y > -3.0f) { // level out torpedo a bit when hitting water if (!luaMoveCtrl) { dir.y *= 0.5f; dir.Normalize(); } } if (--ttl > 0) { if (!luaMoveCtrl) { if (curSpeed < maxSpeed) { curSpeed += std::max(0.2f, tracking); } if (target) { CSolidObject* so = dynamic_cast<CSolidObject*>(target); CWeaponProjectile* po = dynamic_cast<CWeaponProjectile*>(target); targetPos = target->pos; float3 targSpeed(ZeroVector); if (so) { targetPos = so->aimPos; targSpeed = so->speed; if (pos.SqDistance(so->aimPos) > 150 * 150 && owner()) { CUnit* u = dynamic_cast<CUnit*>(so); if (u) { targetPos = helper->GetUnitErrorPos(u, owner()->allyteam, true); } } } if (po) { targSpeed = po->speed; } if (!weaponDef->submissile && targetPos.y > 0) { targetPos.y = 0; } const float dist = pos.distance(targetPos); float3 dif = (targetPos + targSpeed * (dist / maxSpeed) * 0.7f - pos).Normalize(); float3 dif2 = dif - dir; if (dif2.Length() < tracking) { dir = dif; } else { dif2 -= dir * (dif2.dot(dir)); dif2.SafeNormalize(); dir += dif2 * tracking; dir.SafeNormalize(); } } speed = dir * curSpeed; } gCEG->Explosion(cegID, pos, ttl, areaOfEffect, NULL, 0.0f, NULL, speed); } else { if (!luaMoveCtrl) { speed *= 0.98f; speed.y += mygravity; dir = speed; dir.SafeNormalize(); } } } if (!luaMoveCtrl) { pos += speed; } if (pos.y < -2.0f) { --nextBubble; if (nextBubble == 0) { nextBubble = 1 + (int) (gs->randFloat() * 1.5f); const float3 pspeed = (gs->randVector() * 0.1f) + float3(0.0f, 0.2f, 0.0f); new CBubbleProjectile( pos + gs->randVector(), pspeed, 40 + gs->randFloat() * 30, 1 + gs->randFloat() * 2, 0.01f, owner(), 0.3f + gs->randFloat() * 0.3f ); } } UpdateGroundBounce(); UpdateInterception(); }