diff options
author | Stijn Buys <ingar@osirion.org> | 2013-11-09 00:29:58 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2013-11-09 00:29:58 +0000 |
commit | 41fcb9f3915db02c9255dc62f03d6b4a55e5b6d3 (patch) | |
tree | fd7953b9a59cc3a9c5aa3a70522bf46b787cfb16 /src/core/entity.cc | |
parent | cf4deaa44bebafc829e21704f186e01faa2f940d (diff) |
Nudge ships on launch and cargopods on creation to prevent them from spawning inside other objects.
Diffstat (limited to 'src/core/entity.cc')
-rw-r--r-- | src/core/entity.cc | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/core/entity.cc b/src/core/entity.cc index 89e494a..4c4c35b 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -757,6 +757,33 @@ void EntityDynamic::set_state(int state) } } +void EntityDynamic::nudge() +{ + if (!zone()) { + return; + } + + for (Zone::Content::const_iterator it = zone()->content().begin(); it != zone()->content().end(); it++) { + const Entity *other = (*it); + if ((other->type() != Projectile) && (other != this)) { + // check distance + const float d = math::distance(location(), other->location()); + const float r = radius() + other->radius(); + + if ( d < r ) { + // nudge into randomize direction + math::Axis nudge_axis(axis()); + nudge_axis.change_direction(math::randomf(60.0f) - 30.0f); + nudge_axis.change_pitch(math::randomf(60.0f) - 30.0f); + set_location(location() + nudge_axis.forward() * (r - d + 0.001f)); + + // restart search + it = zone()->content().begin(); + } + } + } +} + void EntityDynamic::reset() { // no bullet physics on NonSolid entities |