void FireworkEffect::Start() { if (!m_pBatch) { return; } int numArms = GenerateRandomInt(1) + 3; //3 or 4 arms int numParticlesPerArm = NUM_PARTICLES_PER_BATCH / numArms; int dwCurrentParticle = 0; for (int dwArm = 1; dwArm <= numArms; dwArm++) { float fAngle = GenerateRandomFloat(2.0f * PI); float fXMod = m_fScale * cos(fAngle) * 0.35f; float fYMod = m_fScale * sin(fAngle) * 0.35f; int dwNumToLeave = 0; int k = 1; if (dwArm != numArms) { // not the last one, so leave some particles dwNumToLeave = NUM_PARTICLES_PER_BATCH - (numParticlesPerArm * dwArm); } for (; dwCurrentParticle < NUM_PARTICLES_PER_BATCH - dwNumToLeave; dwCurrentParticle++) { particle &part = m_pBatch->parts[dwCurrentParticle]; part.pq.pos = m_vSource; part.pq.pos.x += fXMod * (float)k; part.pq.pos.y += fYMod * (float)k; part.fScale = 1.0f - GenerateRandomFloat(0.40f); part.fMaxEnergy = 1.75f; part.fEnergy = part.fMaxEnergy + part.fMaxEnergy * 0.1f * (float)k / (float)numParticlesPerArm; part.fSecondsPerRot = GenerateRandomFloat(7.0f) + 3.0f; if (GenerateRandomInt(1)) { part.fSecondsPerRot = -part.fSecondsPerRot; } part.vAcceleration = m_vWind; k++; } } }
void CommandSegment::Generate(int dwLevel) { int randomNum = GenerateRandomInt(TOTAL_COMMAND_ODDS - 1); ShipModifier *pModifier = new ShipModifier(); if (randomNum < AIMED_ODDS) { m_Type = eTYPE_AIMED; } else if (randomNum < (AIMED_ODDS + BLIND_ODDS)) { m_Type = eTYPE_BLIND; } else if (randomNum < (AIMED_ODDS + BLIND_ODDS + KAMIKAZE_ODDS)) { m_Type = eTYPE_KAMIKAZE; } else { m_Type = eTYPE_NO_TYPE; //something is messed up } MovementPlugin *pPlugin = 0; switch (m_Type) { case eTYPE_AIMED: pModifier->m_fProjectileSpeed = (float)dwLevel * 0.03f; //3% increase per ship level SetFiringPlugin(AimedFiringPlugin::GetPlugin()); break; case eTYPE_BLIND: pModifier->m_fProjectileSplitting = (float)dwLevel * 0.03f; //3% increase per ship level SetFiringPlugin(BlindFiringPlugin::GetPlugin()); break; case eTYPE_KAMIKAZE: pModifier->m_fMovement = (float)dwLevel * 0.03f; //3% increase per ship level break; default: break; } SetShipModifier(pModifier); pModifier->Release(); }
void EngineeringSegment::Generate(int dwLevel) { int randomNum = GenerateRandomInt(TOTAL_ENGINEERING_ODDS - 1); ShipModifier *pModifier = new ShipModifier(); if (randomNum < FORTIFIED_ODDS) { m_Type = eTYPE_FORTIFIED; } else if (randomNum < (FORTIFIED_ODDS + BOOSTED_ODDS)) { m_Type = eTYPE_BOOSTED; } else if (randomNum < (FORTIFIED_ODDS + BOOSTED_ODDS + CLONING_ODDS)) { m_Type = eTYPE_CLONING; } else { m_Type = eTYPE_NO_TYPE; //something is messed up } switch (m_Type) { case eTYPE_FORTIFIED: pModifier->m_fArmor = (float)dwLevel; //1 armor increase per level pModifier->m_fPhysicalDamageReduction = (float)dwLevel; break; case eTYPE_BOOSTED: pModifier->m_fShields = (float)dwLevel * 3.0f; //3 bonus shields per level pModifier->m_fShieldEfficiency = (float)dwLevel * 0.03f; //3% bonus to shields efficiency/level pModifier->m_fEnergyDamageReduction = (float)dwLevel; break; case eTYPE_CLONING: pModifier->m_fCloningChance = (float)dwLevel * 0.01f; //1% chance a level break; default: break; } SetShipModifier(pModifier); pModifier->Release(); }
void Weapon::Init() { m_fAcceleration = 0.0f; float fCooldown = 45.0f / 1000.0f; SetCooldown(fCooldown); m_fSpeed = 17.0f; m_fFiringSpread = PI / 16.0f; m_Damage.m_fEnergyDamage = 0.0f; m_Damage.m_fPhysicalDamage = 1.0f; Node *pNode = new Node(); switch (GenerateRandomInt(3)) { case 0: pNode->SetVisual("data\\visuals\\p_blue.3ds"); pNode->m_vScale.x = 0.20f; pNode->m_vScale.y = 0.20f; pNode->m_vScale.z = 0.20f; break; case 1: pNode->SetVisual("data\\visuals\\p_green.3ds"); pNode->m_vScale.x = 0.25f; pNode->m_vScale.y = 0.25f; pNode->m_vScale.z = 0.25f; break; case 2: pNode->SetVisual("data\\visuals\\p_orng.3ds"); pNode->m_vScale.x = 0.30f; pNode->m_vScale.y = 0.30f; pNode->m_vScale.z = 0.30f; break; case 3: pNode->SetVisual("data\\visuals\\p_red.3ds"); pNode->m_vScale.x = 0.15f; pNode->m_vScale.y = 0.15f; pNode->m_vScale.z = 0.15f; break; } SetNode(pNode); pNode->Release(); }
void SparkEffect::Start() { if (!m_pBatch) { return; } for (int i = 0; i < NUM_PARTICLES_ACTUALLY_USED; i++) { particle &part = m_pBatch->parts[i]; part.pq.pos = m_vSource; part.fMaxEnergy = GenerateRandomFloat(0.3f) + 0.2f; part.fEnergy = part.fMaxEnergy; part.vColor.x = 1.0f; part.vColor.y = GenerateRandomFloat(1.0f); if (GenerateRandomInt(1)) { part.vColor.z = part.vColor.y; } else { part.vColor.z = 0.0f; } float fRot = GenerateRandomFloat(PI / 4.0f) - PI / 8.0f; //random direction fRot += atan(m_vDir.y / m_vDir.x); if (m_vDir.x < 0.0f) { fRot += PI; } float fPrecalc = m_fScale * 10.0f * part.fMaxEnergy / 0.5f; part.vVelocity.x = cos(fRot) * fPrecalc; part.vVelocity.y = sin(fRot) * fPrecalc; } }
long int random(void) { return GenerateRandomInt(curctx->glue); }
void Weapon::Fire() { if (m_fCurrentCooldown <= 0.0f) { m_fCurrentCooldown = m_fCooldown; PhysicalObject *pOwner = GetOwner(); if (pOwner) { Node *pSourceNode = pOwner->GetNode(); if (pSourceNode) { Projectile *pNewProjectile = new Projectile(GetNode()); VECTOR3 vDirection; Matrix44 mat = pSourceNode->m_PosQuat.quat.ToMatrix(); float yDisp = -(pSourceNode->m_vScale.y / 2.0f + pNewProjectile->GetNode()->m_vScale.y / 2.0f); if (pSourceNode->GetNodeFlags() & NODE_RENDER_UPSIDEDOWN) { yDisp *= -1.0f; } pNewProjectile->GetNode()->m_PosQuat.pos.x = mat.m[4] * yDisp + pSourceNode->m_PosQuat.pos.x; pNewProjectile->GetNode()->m_PosQuat.pos.y = mat.m[5] * yDisp + pSourceNode->m_PosQuat.pos.y; pNewProjectile->GetNode()->m_PosQuat.pos.z = mat.m[6] * yDisp + pSourceNode->m_PosQuat.pos.z; //calculate actual firing direction based on aim, and weapon spread int dwRandom = GenerateRandomInt(9); float fSpread = 0.0f; if (dwRandom < 7) { fSpread = GenerateRandomFloat(0.05f); } else if (dwRandom < 9) { fSpread = GenerateRandomFloat(0.15f) + 0.05f; } else { fSpread = GenerateRandomFloat(0.30f) + 0.2f; } if (GenerateRandomInt(1)) { fSpread = -fSpread; } fSpread = fSpread * m_fFiringSpread; float fCos = cos(fSpread); float fSin = sin(fSpread); //vDirection.x = fCos * m_vAim.x + fSin * m_vAim.x; //vDirection.y = fCos * m_vAim.y - fSin * m_vAim.y; vDirection.x = fCos * m_vAim.x - fSin * m_vAim.y; vDirection.y = fSin * m_vAim.x + fCos * m_vAim.y; vDirection.z = 0.0f; NormalizeVECTOR3(vDirection); pNewProjectile->GetNode()->m_PosQuat.pos.z = pSourceNode->m_PosQuat.pos.z; pNewProjectile->SetMaxSpeed(m_fSpeed); pNewProjectile->SetVelocity(VECTOR3(m_fSpeed * vDirection.x, m_fSpeed * vDirection.y, m_fSpeed * vDirection.z)); pNewProjectile->SetCreator(pOwner); pNewProjectile->SetWeapon(this); Quat *quat = &(pNewProjectile->GetNode()->m_PosQuat.quat); Quat rotation; rotation.CreateFromRotationRADIANS(fSpread, 0.0f, 0.0f, 1.0f); *quat = rotation * *quat; TestFireEvent *pTestFireEvent = new TestFireEvent(); pTestFireEvent->SetProjectile(pNewProjectile); gEventManager()->AddEvent(pTestFireEvent); pTestFireEvent->Release(); pNewProjectile->Release(); } } } }