Announcement

Collapse
No announcement yet.

(how) Does mod_UnitAttack work?

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

  • (how) Does mod_UnitAttack work?

    I did a quick search of the forums and found no answers so here goes:

    I was toying around with a random idea to do with modifying a units attack when a given tech is has been researched. This example would increase the attack of a bronze age unit after iron working has been researched to simulate weapons upgrading (don't know how realistic that is, but hey). Do any of you know if the following code outline would work in principle. I'm concerned mainly about the function's arguments, return type and return value.

    Code:
    int_f mod_UnitAttack(unit_t localunit, int_t localattack)
    {
    	int_t alittlebit;
    	alittlebit = 2;
    
    	//insert proper 'if' code
    	if((localunit is a bronze age unit) && (localunit.owner has adv_iron_working))
    	{
    		//beef up my attack
    		return localattack + alittlebit; 
    	}
    	else
    	{
    		return localattack;
    	}
    }
    And do you guys know when the function is called. Is it only when a unit attacks (move into an enemy unit) or all battles that the unit fights?

    Any ideas? If not I'll try and mess around with it myself, but I'd rather someone else already has!

    Thanks in advance, MATT:-)

  • #2
    mod_* functions are called at all times, basically. There is no need to call them them from anywhere - as soon as the issue becomes needed, the mod_* function springs into action.

    However, the "last 3" mod functions, i.e. the ones not used in the Activision scenarios - mod_UnitAttack, mod_UnitDefense, and mod_UnitRangedAttack are not known to be functioning. Test it with some extreme values first to see whether it does actually work. Personally, I doubt it does. MrOgre mentioned the function only once on the forum, as a function "he will include" - but as both the Alexander and Samurai scenarios find different ways to do the same thing, we remain in uncertainty as to whether the function was implemented, or included and left dead.

    Its a good idea though, and the code above would feasibly work with proper if() statements in.
    Concrete, Abstract, or Squoingy?
    "I don't believe in giving scripting languages because the only additional power they give users is the power to create bugs." - Mike Breitkreutz, Firaxis

    Comment


    • #3
      Thanks for the info. I've done some testing and here's what I found so far, which may be wrong:


      Code:
      int_f mod_UnitAttack(unit_t theAttacker, unit_t theDefender, int_t normalAttackValue)
      {
      	return modifiedAttackValue;
      }
      
      int_f mod_UnitDefense(unit_t theDefender, unit_t theAttacker, int_t normalDefenseValue)
      {
      	return modifiedDefenseValue;
      }
      
      //int_f mod_UnitRangedAttack() doesn't seem to be implemented anywhere so is useless
      The return values are the modified attack/defense values to use in the battle. The units are what you expect them to be. The normal attack/defense values are the appropriate values for the attacking/defending units. Note that the defense value takes into account bonuses for terrain and fortifications as far as I can tell. The veteran status of a unit doesn't seem to be accounted for in this value (at least not for the attacker that I tested), it may be included after the function is called or in a seperate call to the function, or not at all!


      As an example of how the functions are called, an infantryman attacks a warrior (no bonuses for anything) :

      First mod_UnitAttack() is called twice (?why?) with the infantryman as attacker and attack value of 25. Then mod_UnitDefense() is called with warrior as defender, defense value 10.

      Then the same functions, but with infantryman and warrior reversed, ie twice mod_UnitAttack() with warrior as attacker (value 10) then once mod_UnitDefense() with Infantryman as defender (value 35).

      Then repeated until someone dies.

      Now, if the warrior was in a forest, his defense value would rise to 12 (10 +25% bonus rounded down), and his attack value would remain at 10. If the infantryman was on a mountain his defense would rise to 70 (35 +100% bonus), but his attack would remain at 25. This happens regardless of who initiated the battle.

      [This gets more complicated when ranged units are included too. All the ranged units do their attacking first and then enemy ranged units, then front line units attack as above. No calls to mod_UnitRangedAttack() are made though, only an appropriate mod_UnitDefense().]


      I hope that makes sense! If that's not clear I'll try again.

      TTFN, MATT:-)

      Comment


      • #4
        So to summarise:
        mod_UnitRangedAttack doesn't work.
        the mod function returns the attack or defense value to be used in the battle.

        I don't get why it needs two unit arguments. I loaded a game successfully with just one unit, one integer, to alter that unit's attack/defense throughout the game.

        Also, how did you find out when the functions were being called? With a messagebox?

        What happens there are two attackers against one defending unit?
        Concrete, Abstract, or Squoingy?
        "I don't believe in giving scripting languages because the only additional power they give users is the power to create bugs." - Mike Breitkreutz, Firaxis

        Comment


        • #5
          Your summary is much more elegant than my ramble, I wish I'd thought of it!

          I guess the two unit arguments are there for functionality. For example you could script a defense bonus for pikemen against mounted units, a la civ2, by checking the appropriate unit arguments. It seems that you can script the function with as many arguments as you like, there is no error check as far as this is concerned (well not with debugslic=no anyway).

          I did use message boxes to work out when the functions were called, and also what arguments were passed into the function (via a text output).

          As for 2(knights - as flankers) vs 1(warrior), it is as you might expect. One knight attacks and the warrior defends, then the next knight attacks and the warrior defends again. Finally the warrior attacks the knight he is facing. Then the knights go again, and so on.

          It seems that the only difference between being an overall attacker or defender in a battle is who strikes first.

          Comment


          • #6
            does it have any effect though?
            Concrete, Abstract, or Squoingy?
            "I don't believe in giving scripting languages because the only additional power they give users is the power to create bugs." - Mike Breitkreutz, Firaxis

            Comment


            • #7
              (I assume you're referring to my last sentence in which case...)

              All other things being equal, it will (statistically speaking) make little or no difference whether you are the overall attacker or defender. It will have a larger effect if you outnumber the enemy and have flankers/ranged units in your line in which case the first strike will kill off the enemy quicker, but that may only result in a few less hit points lost by your units in a battle you're very likely to win anyway!

              Having said that, little or no difference might be 1 hit point difference between the overall attacker and overall defender, which is the difference between a dead unit and one that can be healed and return to fight again.

              I have a distinct feeling that I may be wrong on that though - it seems a bit odd.

              Comment


              • #8
                no-no, does the actual function have any effect on the attack and defense stats of the unit?
                Concrete, Abstract, or Squoingy?
                "I don't believe in giving scripting languages because the only additional power they give users is the power to create bugs." - Mike Breitkreutz, Firaxis

                Comment


                • #9
                  Sorry! From my testing it appears that the mod functions change the value to use for that particular round of combat. It doesn't permanently change the stats of the units. I guess that's the effect hoped for.

                  Comment


                  • #10
                    From my testing it appears that the mod functions change the value to use for that particular round of combat. It doesn't permanently change the stats of the units
                    Yeah, but if it's called on every round of combat, then it might as well be permanant.
                    Concrete, Abstract, or Squoingy?
                    "I don't believe in giving scripting languages because the only additional power they give users is the power to create bugs." - Mike Breitkreutz, Firaxis

                    Comment


                    • #11
                      True, that would reduce function overheads too. The only problem with permanace might be that you'd have to check if the bonus had been applied each time the function was called, creating another function overhead instead. It looks like either way could have been implemented and the programmers happened to choose that one. It's a shame we'll never know why!

                      Thanks for your help on this one.

                      Comment


                      • #12
                        Don't try a battle between two units with 0 attack. It um, crashes the game...
                        Concrete, Abstract, or Squoingy?
                        "I don't believe in giving scripting languages because the only additional power they give users is the power to create bugs." - Mike Breitkreutz, Firaxis

                        Comment


                        • #13
                          On second thoughts, maybe make that a "no it doesn't work". I just tried it, by setting all my units to have 100 attack/defence and it had no effect.

                          Comment


                          • #14
                            all the attack figures are scaled up by 100. 100 in units.txt = 1 attack point. Try varying it.

                            I haven't been able to determine accurately whether it can return more than 1 and 0 or a range
                            Concrete, Abstract, or Squoingy?
                            "I don't believe in giving scripting languages because the only additional power they give users is the power to create bugs." - Mike Breitkreutz, Firaxis

                            Comment


                            • #15
                              Ah, my mistake. I see what you mean.

                              Comment

                              Working...
                              X