Need some help with code - specifically adding fire arrows

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

    Need some help with code - specifically adding fire arrows

    As far as I can tell I have the ability pretty much finished, however any monster that I have added the flag for the spell to I keep getting the message "A monster tried to cast a spell that has not yet been defined."

    I think the problem may be in relation to the execution of the range attack, here is the code that I think is responsible.

    Taken from line 1920 of the the melee1.c file
    Code:
    /*** Execute the ranged attack chosen. ***/	
    
    switch (attack)
    	{
    		/* RF4_ARROW1, RF4_ARROW2 */
    		case 96+0:
    		case 96+1:
    		case 96+19:
    		{
                int dd = (attack == 96+0) ? 1 : 2;
    
    			disturb(1, 0);
    			if (spower < 2)
    			{
    				if (blind) msg_print("You hear a twang.");
    				else msg_format("%^s fires an arrow.", m_name);
    			}
    			else
    			{
    				if (blind) msg_print("You hear a loud thwang.");
    				else msg_format("%^s fires an arrow.", m_name);
    			}
    			if (spower > 18)
    			{
    				if (blind) msg_print("You hear a whoosh of fire.");
    			else msg_format("%^s fires a flaming arrow.", m_name);
    		}
    
    
    			mon_bolt(m_idx, GF_ARROW, dd, get_sides(attack), -1);
    
    			break;
    		}
    The "if (spower > 18)" is set so high because pre-existing abilities number 1-18, so I have the flame arrow ability labelled "96+19"

    If it's relevant, the code that triggers the display of the message "A monster tried to cast a spell that has not yet been defined." can be found in melee.c line 2247

    Code:
    		default:
    		{
    			msg_print("A monster tried to cast a spell that has not yet been defined.");
    		}
    	}
    Any pointer would be appreciated. Thanks
    Last edited by Guest; June 28, 2021, 11:18.
  • Nick
    Vanilla maintainer
    • Apr 2007
    • 9638

    #2
    I'm not very familiar with Sil code, but here are my guesses:
    • The pre-existing ability numbers have nothing to do with spell power. They are listed in defines.h under "Monster racial flags - 'spells'" - you need to add one at the end for fire arrows (there are a bunch of unused ones labelled things like RF4_RF4XXX17). Pick the next unused one, which should correspond to the first number n not used as 96+n in the big switch statement you quoted (n=15 in my copy of the code, but that may be old).
    • You will need to put entries for your new spell in the spell_info_RF4 table in tables.c
    My advice would be to search for RF4_ARROW1, and mimic all the things that the code does for that.
    One for the Dark Lord on his dark throne
    In the Land of Mordor where the Shadows lie.

    Comment

    • Guest

      #3
      Thanks Nick! however I've made sure that the new flame arrow is coming up the same amount of times in just as many files as Arrow1, so I know wherever Arrow1 is mentioned Arrow3 (the flame arrows) is also mention in the exact same way.

      I'm nearly certain the issue is still in the code from melee1.c above, where the ability is not being "announced" correctly so it's being cancelled and replaced with "A monster tried to cast a spell that has not yet been defined."

      Comment

      • backwardsEric
        Knight
        • Aug 2019
        • 527

        #4
        Originally posted by Gothmog
        I'm nearly certain the issue is still in the code from melee1.c above, where the ability is not being "announced" correctly so it's being cancelled and replaced with "A monster tried to cast a spell that has not yet been defined."
        What's the value of attack in make_attack_ranged() when a fire arrow is attempted? From what you've posted, it's not 115 (96 + 19). Since that value is being selected in melee2.c's choose_ranged_attack() from the monster spell flags, that points to a mismatch between the value of the spell flag for the fire arrow spell and the integer, 96 + 19, you used in make_attack_ranged() for the fire arrow. To match, it looks like the monster spell flag in defines.h for a fire arrow should be 0x80000 (i.e. 1 << 20 to match the rule that the flag is the 1 << (attack - 95)). If the value of the monster spell flag looks correct, then the problem is likely the conversion of the spell string used in monster.txt (i.e. "ARROW1" for RF4_ARROW1) to the spell flag value.

        Comment

        Working...
        😀
        😂
        🥰
        😘
        🤢
        😎
        😞
        😡
        👍
        👎