The Glory(ish) of Success(ish)

This week has been a good week! 😀

Firstly, the Jenkins CI issues are sorted – all of them were infrastructure related (to do with paths, permissions and post-build steps), so now Jenkins is building 666 on two platforms, and also then triggering builds of Dom itself – along with some of the 666 tools. CI wise, we’re now tickety-boo!

Dom wise – I’ve begun the behaviour work as promised in the previous post. I already have a very basic ‘ship which docks/undocks/pootles about a bit’ behaviour, and I wanted something a little more challenging to relight the coding boiler, as it were.

So – attacking behaviour! I set about updating the existing flocking behaviour first – refactoring a bit, and then reworked the target acquisition code. It’s now less ‘rigged’ and more flexible, and works rather well if I do say so myself. (It was rigged for all the video/promo work for the Kickstarters.) I then finally put in the object avoidance code I’ve been procrastinating on for some time, and now ships no longer fly through each other.

So, I can now create a ‘flock’ of fighters, that can either intelligently defend an object, or attack it.

For now – “Defending” means they fly around/near their assigned object and then attack anything that comes near that’s not a member of their flock. At the moment targeting is shared – so if one fighter spots you, the entire flock attacks its target. I’ll make this configurable so I can build varied flocking behaviours.

Attacking flocks will fly at their target, blasting away – and then evade when they get too close and fly off to get a new attack vector allowing them to blast away again.

Because all the complex code (querying the game state, etc) is abstracted away from the code that drives the behaviours – writing the behaviours is proving quite straightforward (so far!). Here’s an example of the code at the heart of ‘Attacking’ at the moment ;

void CGVessel::OnUpdateNPCAttackFSM()
{
  float fElapsed = GetClock().GetElapsed() ;
  OnUpdateAllStates(fElapsed) ;
  DEVAcquireNearestTargets() ;
  // Presumes targets are sorted by proximity nearest
  const CGSceneObject* pSO = m_pTargetting ? m_pTargetting->GetFirstTarget() : NULL ;
  if(pSO)
  {
    HeadForSceneObject(pSO) ;
    C3DEVector vPos = pSO->GetActiveScenePosition() ;
    float fProximity = GetActiveScenePosition().GetDistance(&vPos) ;
    float fSafeDistance = (GetSceneStateRadius(GetActiveScene()) + pSO->GetSceneStateRadius(GetActiveScene())) * 1.5f ; // TODO : Make configurable
    if(fProximity <= fSafeDistance)
    {
      PushNextVesselFSM(eFSMNPCFlee) ;
    }
    if(IsTargetInFiringSolution(pSO))
    {
      CMSGServer::Get().Send(eMSGDEVFireWeapons, CMSGMessage2::eDelay, GetID(), GetID()) ;
    }
  }
  else
  {
    PopState() ; // return to whatever we were doing before attacking!
  }
  AvoidSceneObjectCollisions(eSceneLocalSpace) ;
  m_scnModifier.OrientToVelocity() ;
  SetSceneStatePosition(eSceneLocalSpace, GetSceneNode(eSceneLocalSpace)->GetPosition()) ;
}

That single function controls the attacking behaviour – attacking nearest targets, evading them if it gets to close, avoiding nearby scene objects and also return to whatever it was doing beforehand if there are no more targets.

So far it all works rather well – and I’ve now got a little test scenario set up where I assign a flock of pirates to attack a station, so when you drop into local space you can sit and watch, or take action and either start defending the station or join in the attack!

By swapping a few lines of code – I can then have the flock defending the station, and then either attack you on sight, or only attack if you attack them or the station.

The goal is to create some straightforward behaviours, and then emergent scenarios can be built up. From the above – with very little coding – you could drop into a defended stations local space, and begin docking – then another flock appears and attacks the station… what do you do? Dock and hope? Run? Defend the station? Join the attack? You decide 🙂

Eventually – when all these behaviours are set up, these scenario’s will be generated and just ‘evolve’ as you play.

At least, that’s the plan 😉

PS. Oh, and I’m 2/3 the way through the final (I promise!) edits on Book one… I’m going to need a cover doing fairly shortly!

SHARE THIS POST

  • Facebook
  • Twitter
  • Myspace
  • Google Buzz
  • Reddit
  • Stumnleupon
  • Delicious
  • Digg
  • Technorati
Author: Mak View all posts by

Comments are closed.

Subscribe to The Dominium Observer Newsletter!
Subscribe