void ippEmitter::ParticleExplosion() { for( int i = 0; i < maxParticles; i++ ) { ListOfQuad.at( i )->SetActive( true ); ListOfQuad.at( i )->SetDirection( RandomDirection() ); ListOfQuad.at( i )->SetPosition( pos ); } hasExploded = true; }
//粒子添加器 void tEmitter::addParticle() { tParticle *particle; mVector4d startColor, endColor; double voy, vox, speed; if (ptcPool != NULL && curPtc < totalPtc) { //从粒子库中取出一个粒子链入当前活跃粒子链表中 particle = ptcPool;//池中的一个元素 ptcPool = ptcPool->next; if (ptc != NULL) ptc->prev = particle; particle->next = ptc; particle->prev = NULL; ptc = particle; //在一个半径为0.01的球面内的某片曲面中随机取一个位置给粒子作初始点 double degreeY = DEGTORAD(120.0 + 60.0 * Random());//begtorad double degreeXZ = DEGTORAD(360.0 * Random()); particle->pos = mVector3d(0.001 * sin(degreeY) * cos(degreeXZ), 0.001 * (1 - cos(degreeY)), 0.001 * sin(degreeY) * sin(degreeXZ)); particle->prevPos = particle->pos; // 用于线段模式 // 随机产生初始速度向量 voy = (voy_max - voy_min) * Random(); vox = (vox_max - vox_min) * Random();; RandomDirection(vox,voy,&particle->direction); speed = speed_min + (speed_max - speed_min) * Random(); particle->direction = particle->direction * speed; // 随机产生粒子初始颜色及终止颜色 startColor = startColor_min + (startColor_max - startColor_min) * Random(); endColor = endColor_min + (endColor_max - endColor_min) * Random(); particle->currentColor = startColor; // 随机产生粒子生命值,数值表示粒子存活帧数 particle->restLife = life_min + (life_max - life_min) * Random(); // 计算粒子颜色变化率 particle->deltaColor= (endColor - startColor) *(1.0 / (double)particle->restLife); curPtc++; //发射器当前粒子数加1 } }
void CampaignPlanMovement::MoveUnit(CombatUnit* u) { if (u) { // starship repair: double damage = u->GetSustainedDamage(); if (damage > 0 && u->GetDesign()) { int percent = (int) (100 * damage / u->GetDesign()->integrity); if (percent > 50) { u->SetSustainedDamage(0.90 * damage); } } Point loc = u->Location(); Point dir = loc; double dist = dir.Normalize(); const double MAX_RAD = 320e3; const double MIN_DIST = 150e3; if (dist < MAX_RAD) { double scale = 1 - dist/MAX_RAD; loc += dir * (Random(30e3, 90e3) * scale) + RandomDirection() * 10e3; if (fabs(loc.z) > 20e3) loc.z *= 0.1; u->MoveTo(loc); CombatGroup* g = u->GetCombatGroup(); if (g && g->Type() > CombatGroup::FLEET && g->GetFirstUnit() == u) { g->MoveTo(loc); if (g->IntelLevel() > Intel::KNOWN) g->SetIntelLevel(Intel::KNOWN); } } else if (dist > 1.25 * MAX_RAD) { double scale = 1 - dist/MAX_RAD; loc += dir * (Random(80e3, 120e3) * scale) + RandomDirection() * 3e3; if (fabs(loc.z) > 20e3) loc.z *= 0.1; u->MoveTo(loc); CombatGroup* g = u->GetCombatGroup(); if (g && g->Type() > CombatGroup::FLEET && g->GetFirstUnit() == u) { g->MoveTo(loc); if (g->IntelLevel() > Intel::KNOWN) g->SetIntelLevel(Intel::KNOWN); } } else { loc += RandomDirection() * 30e3; if (fabs(loc.z) > 20e3) loc.z *= 0.1; u->MoveTo(loc); CombatGroup* g = u->GetCombatGroup(); if (g && g->Type() > CombatGroup::FLEET && g->GetFirstUnit() == u) { g->MoveTo(loc); if (g->IntelLevel() > Intel::KNOWN) g->SetIntelLevel(Intel::KNOWN); } } CombatUnit* closest_unit = 0; double closest_dist = 1e6; ListIter<CombatUnit> iter = all_units; while (++iter) { CombatUnit* unit = iter.value(); if (unit->GetCombatGroup() != u->GetCombatGroup() && unit->GetRegion() == u->GetRegion() && !unit->IsDropship()) { Point delta = loc - unit->Location(); dist = delta.Normalize(); if (dist < closest_dist) { closest_unit = unit; closest_dist = dist; } } } if (closest_unit && closest_dist < MIN_DIST) { Point delta = loc - closest_unit->Location(); dist = delta.Normalize(); loc += delta * 1.1 * (MIN_DIST - closest_dist); if (fabs(loc.z) > 20e3) loc.z *= 0.1; u->MoveTo(loc); CombatGroup* g = u->GetCombatGroup(); if (g && g->Type() > CombatGroup::FLEET && g->GetFirstUnit() == u) { g->MoveTo(loc); if (g->IntelLevel() > Intel::KNOWN) g->SetIntelLevel(Intel::KNOWN); } } } }
StarshipAI::StarshipAI(SimObject* s) : ShipAI(s), sub_select_time(0), subtarget(0), tgt_point_defense(false) { ai_type = STARSHIP; // signifies this ship is a dead hulk: if (ship && ship->Design()->auto_roll < 0) { Point torque(rand()-16000, rand()-16000, rand()-16000); torque.Normalize(); torque *= ship->Mass() / 10; ship->SetFLCSMode(0); if (ship->GetFLCS()) ship->GetFLCS()->PowerOff(); ship->ApplyTorque(torque); ship->SetVelocity(RandomDirection() * Random(20, 50)); for (int i = 0; i < 64; i++) { Weapon* w = ship->GetWeaponByIndex(i+1); if (w) w->DrainPower(0); else break; } } else { tactical = new(__FILE__,__LINE__) StarshipTacticalAI(this); } sub_select_time = Game::GameTime() + (DWORD) Random(0, 2000); point_defense_time = sub_select_time; }