[CF-Devel] Firing spells from ranged weapons

crossfire-devel at archives.real-time.com crossfire-devel at archives.real-time.com
Tue May 18 12:06:40 CDT 2004


I've been wanting to make explosive arrows, but couldn't get them to work. 
After mucking about in the code a bit, I found that it's because only 
spell-bullets (102) get checked for detonation and suchlike, but if you 
change the type 13 archs to 102, they aren't ammo any more and you can't 
fire them in the first place.
So, I came up with this. It's rather hackish and probably still has a bug 
or two left in it, but it doesn't double-remove_ob() any more, at least. 
If the other_arch field of the shot being fired is blank, it proceeds 
normally; otherwise, it spawns one of those archetypes and removes the 
original projectile.
Thus, by setting an arrow with, say, other_arch firebullet, you'll be 
shooting fireballs instead of arrows. And the arrows will be 
unrecoverable, although this may not always be desireable.
The new arch inherits hp/maxhp/dam_modifier/range from the parent ammo, if 
it has them.
There's also a check to make sure that hp doesn't get overwritten by the 
original value of dam; since we won't be retrieving the missile 
afterwards, this doesn't really matter. Lastly, there's a check at the end 
that calls move_bullet rather than move_arrow if the itemtype isn't ARROW 
- using move_arrow results in odd bugs when firing at point blank range.
Oh, and there's no check to see if arch_to_object worked. This is probably 
very unsafe.
I'm not sure if this will work for cone/beam weapons, I haven't looked at 
the code for those much yet, but something in fire_bow based on (or 
calling) drop_cone and move_cone will probably be necessary.

A sample archetype:
Object bolt_fb
race crossbow bolts
name bolt
title Firey Blast
type 13
hp 8
maxhp 4
dam_modifier 4
range 10
other_arch firebullet
face bolt.101
animation firebullet
is_animated 0
is_turnable 1
nrof 1
weight 50
value 2
material 2
food 10
dam 3
wc 2
editable 1024
attacktype 5
name_pl bolts
client_type 165
editor_folder arch/weapon/bow
end

$ diff player.c player.orig.c
1471c1471
<     object *left, *bow, *tmp;
---
>
     
          object *left, *bow;
     
     1540,1566d1539
< 	
< 	if(arrow->other_arch) {
< 		tmp = arch_to_object(arrow->other_arch);
< 		if(arrow->range)
< 			tmp->range = arrow->range;
< 		if(arrow->stats.hp)
< 			tmp->stats.hp = arrow->stats.hp;
< 		if(arrow->stats.maxhp)
< 			tmp->stats.maxhp = arrow->stats.maxhp;
< 		if(arrow->dam_modifier)
< 			tmp->dam_modifier = arrow->dam_modifier;
< 		free_object(arrow);
< 		arrow = tmp;
< 	}
< 	
1582,1583c1555
< 	if(!arrow->stats.hp)	/* hack so that hp (duration) doesn't get 
overwritten */
<     	arrow->stats.hp = arrow->stats.dam;
---
>
     
          arrow->stats.hp = arrow->stats.dam;
     
     1634,1640c1606,1607
<     if (!was_destroyed(arrow, tag)) {
< 		if(arrow->type == ARROW) {
< 			move_arrow(arrow);
< 		} else {
< 			move_bullet(arrow);
< 		}
< 	}
---
>
     
          if (!was_destroyed(arrow, tag))
     
     >
     
      	move_arrow(arrow);
     
     
_______________________________________________
crossfire-devel mailing list
     
     crossfire-devel at lists.real-time.com
     
     
     https://mailman.real-time.com/mailman/listinfo/crossfire-devel
     
     
    


More information about the crossfire mailing list