Skip to content

Instantly share code, notes, and snippets.

@dhh1128
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhh1128/ce0cd3fdbd390e6f2417 to your computer and use it in GitHub Desktop.
Save dhh1128/ce0cd3fdbd390e6f2417 to your computer and use it in GitHub Desktop.
evasive action snippet
void spaceship::take_evasive_action(list<threat> threats_by_proximity) {
course escape_vector = nullptr;
list<threat> weighted_threats = order_by_evasion_priority(
threats_by_proximity, multiply_by_threat_severity);
if (this->has_warp()) {
bool warp_is_practical = true;
double max_safe_warp = 1.0;
// do a bunch of calculations about whether warp is
// practical, based on current fuel, gravitational
// fields, battle damage, etc. Also, figure out what
// speed we can achieve.
// ... 50 lines omitted ...
if (warp_is_practical) {
escape_vector = select_safest_course(max_safe_warp,
weighted_threats, bias::away);
}
} else {
switch (this->conventional_propulsion_type) {
case propulsion_type::impulse:
// ... 5 lines omitted ...
case propulsion_type::thrusters:
// ... 4 lines omitted ...
case propulsion_type::ion:
// ... 12 lines omitted ...
default:
if (this->has_countermeasures())
deploy_decoys();
break;
}
}
if (escape_vector) {
engage(escape_vector);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment