Morale Simulation

Discussion in 'Modding' started by Ftoomsh, Feb 4, 2020.

  1. Ftoomsh

    Ftoomsh Well-Known Member

    I have started work on a simple morale simulation. These are only early tests so far.

    (1) I keep the standard function _unit_DoRunAway. This makes shooting units without melee weapons behave in the normal vanilla way.

    (2) I add a new function _unit_DoRunAway_Further. It has the same code as _unit_DoRunAway except I make these changes;

    procedure _unit_DoRunAway_Further(const goHnd : Integer; const tx, tz : Float); // Ftoomsh
    begin
    var pobj : Pointer = _unit_GetTObj(goHnd);
    if (pobj<>nil) then
    begin
    var minsearchdist : Float = gObjProp[TObj(pobj).cid][TObj(pobj).id].minattackradius;
    var maximumlife : Float = gPlayer[TObj(pobj).pl].objbase[TObj(pobj).cid][TObj(pobj).id].maxhp;
    var lifeleft : Float = TObj(pobj).hp;
    var deltadst : Float;
    if (lifeleft<(maximumlife/2)) then
    deltadst := 20*gc_unit_runawaydist

    else
    begin
    var dst : Float = VectorDistance(GetGameObjectPositionXByHandle(goHnd), 0, GetGameObjectPositionZByHandle(goHnd), tx, 0, tz);
    deltadst := Clamp((minsearchdist-dst), gc_objectEpsilonDist*3, gc_unit_runawaydist);
    end;

    ... and the rest of the code is the same as the standard runaway code.


    This is a simple test for % lifeleft and the unit runs away 20 times further when its life goes under a 50% of maxhp AND it is attacked or even closely approached by a cold steel unit. Really, you would want it to try to run out of the range of any musket unit too. Also, you would only want it to runaway as above if it was not in a formation (never in a formation or its formation has broken). The formation break percentage would need to be lifted from its current 25% to say 50% to support this model (with a small plus or minus random and/or more adjustments after tests for the formation being threatened in other ways or being supported by its own friendly formations. Such refinements would be necessary to make this morale model work in full.

    (3) Everywhere there is a _unit_DoRunAway procedure in the code below, I add a _unit_DoRunAway_Further procedure as well.

    More work is needed like;

    Runaway from muskets,
    Something to make runaways run all the way to home base,
    Remove player control while they are running,
    Healing at home base.

    I admit I very much doubt that I can figure out all this on my own. For example, how would I bring in a boolean indicator that the shows the unit is part of a formation or not part of a formation? I can't even solve this one yet. :confused:
     
    Last edited: Feb 6, 2020
    Johny likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice