Announcement

Collapse
No announcement yet.

(how) Does mod_UnitAttack work? (Continued)

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • (how) Does mod_UnitAttack work? (Continued)

    Continuing from here.
    another url http://apolyton.net/showthread.php/1...d_functions?s=

    I hope to make a multi-dimensional array that gives specific unit's a buff in attack/defensive/and-or ranged attack values based on whether they have a magical item or not.

    The function seems to be pretty undocumented, but from the thread, it looks like the function had some marginal success in reducing attack values after the initial round (maybe they needed to move the function into an event handler that started at the beginning of combat).

    Here's from the sourcecode
    UnitData.cpp

    sint32 intDef = (sint32)base;
    sint32 modDef = g_slicEngine->CallMod(mod_UnitDefense, intDef, m_id, attacker.m_id, intDef);
    if(modDef != intDef)

    Here's it in action

    SlicEngine.cpp
    SMF_3A(mod_UnitAttack, ST_UNIT, ST_UNIT, ST_INT);
    SMF_3A(mod_UnitRangedAttack, ST_UNIT, ST_UNIT, ST_INT);
    SMF_3A(mod_UnitDefense, ST_UNIT, ST_UNIT, ST_INT);

    base = modDef;

    Header file declaration
    SlicModFuncEnum.h
    mod_UnitDefense,

    Note:
    I'm worried this might adjust all unit's of a specific type vs individual... I might be able to just simply check (using a multi-dimensional array) to modify the value dynamically. It would require a lot of calculation. But each unit could be checked if it has the item, and if it does, adjust all the unit types attack value, then undo it after the attack is over before the next unit attacks.

    Update:
    Just read that that's not even used (the in action part), the commented notes in the source say use GetOffense

    Update2:
    It does appear mod_UnitAttack is used, just the function of it in action isn't, however it's used in UniteData::GetOffense. It's weird tho, mod_UnitAttack is being used as a variable vs a function)
    Last edited by thistleknot; May 8, 2013, 22:42.

  • #2
    Here's some code i've been working on to test the mod function (which I have no idea how to implement, I don't see why I'm supposed to redefine the function, but following this tutorial by the immortal wombat (see chapter 7), it seems I'm supposed to with the mod_ functions

    //global variables

    int_t SKF_tmpGold;

    void_f AddAttack (unit_t theUnit) {
    unit_t tmpUnit;
    //unitrecord_t tmpUnitRecord;

    tmpUnit = theUnit;
    }

    int_f mod_UnitAttack(unit_t theAttacker, unit_t theDefender, int_t normalAttackValue)
    {
    return UnitDB(UNIT_TANK).Attack;
    //return modifiedAttackValue;
    }

    int_f mod_UnitDefense(unit_t theDefender, unit_t theAttacker, int_t normalDefenseValue)
    {
    return UnitDB(UNIT_TANK).Defense;
    //return modifiedDefenseValue;
    }

    HandleEvent (CreateCity) 'test1' post {
    int_t tmpPlayer;
    unit_t tmpUnit;
    location_t tmpLoc;

    city_t tmpCity;

    //owner?
    //location based on city?
    //CHECK MORALE TUTORIAL FOR how to give units an attribute
    // tankAttack = UnitDB(UNIT_TANK).Attack;
    //so UnitDB is a unitrecord?
    //see pg 121 of slic kungfu
    //slic_locutus.shtml shows how to get a UnitDB into tmpUnit and use CreateUnit to do so
    //mod reference http://www.ctp2.info/database/slic/functions/units/
    //mod attack? http://www.ctp2.info/database/slic/f...s/units/setup/
    //mod_UnitAttack (int_t, int_t theUnit)
    //info http://apolyton.net/showthread.php/5...nitAttack-work

    tmpPlayer = g.player;
    tmpCity = city[0];
    tmpLoc = tmpCity.location;
    //tmpUnit = UnitDB(UNIT_CAVALRY);
    //tmpUnit = unit[7];

    SKF_tmpGold = 2400;

    If(IsHumanPlayer(tmpPlayer)){
    CreateUnit(tmpPlayer, UnitDB(UNIT_CAVALRY), tmpLoc, 0);
    //CreateUnit(tmpPlayer, tmpUnit, tmpLoc, 0);

    AddGold(tmpPlayer, SKF_tmpGold);
    }
    }

    HandleEvent(CreateUnit) 'kill_the_unit' pre {
    unit_t tmpUnit;
    tmpUnit = unit[0];
    player[0] = unit[0].owner;

    int_t tempInt;
    mod_UnitAttack(tmpUnit, tmpUnit, 1);
    //tmpUnit.mod_UnitDefense = tmpUnit.mod_UnitDefense + 1;
    //tmpUnit.mod_UnitAttack = tmpUnit.mod_UnitAttack + 2;

    }

    Comment


    • #3
      Originally posted by thistleknot View Post
      Here's some code i've been working on to test the mod function (which I have no idea how to implement, I don't see why I'm supposed to redefine the function, but following this tutorial by the immortal wombat (see chapter 7), it seems I'm supposed to with the mod_ functions
      You don't redefine the mod functions you overwrite them. What I remember is that these functions are called by the game, and the return value is the final attack or defense value. Of course you don't get these actual values by looking up the default value in the database. So in your example all units have the attack and defense values of the Tank. You should see that on the user interface.

      -Martin
      Civ2 military advisor: "No complaints, Sir!"

      Comment

      Working...
      X