ID:151214
 
OK, I have my fighting code, but when the 2 mobs fight, they are both immortal, here's the code:
mob/War(mob/attacker)
//attacker has offended src

if(src.enemy==attacker) return //we already hate this guy
if(src.enemy) //we already hate somebody else
if(src.mood == ASSERTIVE) src.mood = HOSTILE //anger mounts!

//fight the new guy if he is closer
if(get_dist(src,src.enemy) < get_dist(src,attacker)) return

else spawn src.Swing() //start swinging

src.dir = get_dir(src,src.enemy)
src.enemy = attacker

var/mob/M
for(M as mob in oview(,src))
M.SeeWar(attacker,src)


mob/SeeWar(attacker,mob/trg)
//attacker has offended trg--do we care?
if(src.party_id && src.party_id == trg.party_id && src.rank <= trg.rank)
src.War(attacker) //yes we care because trg is a friend


mob/Peace()
src.enemy = 0

mob/OneSwing(mob/trg,dexterity,Offense)
var/p
var/x

src.dir = get_dir(src,trg) //face the enemy

//sigmoidal hit probability
if(trg.armor + dexterity == 0) return
x = (trg.armor - dexterity)/(trg.armor + dexterity)
p = 1/(1 + 100 ** x)

trg.War(src)
if(prob(p*100))
//improve dexterity skill
src.max_dexterity += 0.1 * (1-p)

p *= -0.07 * src.shield //hit energy
src.Addshield(p)
p *= Offense/trg.defense

switch(-p/trg.max_HP)
if(0.00 to 0.10) view() << "[mob] grazes [usr]."
if(0.10 to 0.25) view() << "[src] hits [trg]."
if(0.25 to 0.50) view() << "[src] smashes [trg]."
else view() << "[src] sends [trg] reeling."


trg.AddHP(p)
return p

else
//improve armor skill
trg.max_armor += 0.1 * p


mob/Swing()
spawn
usr = src //so procs like AddHP give credit where it is due

while(src.enemy)
if(get_dist(src,src.enemy) <= 1) //in range
src.OneSwing(src.enemy,src.dexterity,src.offense)


//next swing is randomly delayed anywhere up to swing_lag
sleep(rand(src.swing_lag))

src.Peace()






I think the problem is in there, my bad guy code is this:
Wolf
icon = 'wolf.dmi'
HP = 3
shield = 1
dexterity = 2
armor = 4
offense = 2
karma = 1

And the good mobs is similar, and idea's? Thanks,
Gilser
This is probably a good time to introduce you to the gentle art of debugging. Debugging isn't bad in itself... the problem is you almost always have to do it when you're eager to move on to something else. But with a little patience, you can track down the problem.

Consider what the problem is. The mobs never die in combat. So what you have to do is make sure they're attacking each other, make sure they're doing reasonable amounts of damage, and make sure that they're dying when their hit points fall below 0. Here's some sample code, with debugging statements. (I always mark mine with the comment //dbg because then it's easy to scan the whole project for "dbg" and remove debugging lines when they're no longer needed.)

mob/proc/Attack(mob/myTarget, myDamage)
world << "myTarget is [myTarget] myDamage is [myDamage] myTarget.health is [myTarget.health]" //dbg

if(myDamage > myTarget.health)
world << "[myTarget] just died!"
del myTarget
else
myTarget.health -= myDamage
myTarget << "You just took [myDamage] points of damage!"
src << "You just hit [myTarget] for [myDamage] points of damage!"

In this example, I only put in one debugging statement. Often that would be all I'd need to know where to look. But what if it wasn't? Well, simple: add more! As long as you mark the debugging output with //dbg or some other unique comment, it'll be easy to go back and remove those lines later.
In response to Guy T.