00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00022
00023 #include "crogue.h"
00024
00025 void monst_swing_monst(int attacker, int target, int trigger);
00026 void monst_attack_monst(int attacknum, int attacker, int target);
00027
00028
00029 void pet_move(int pet)
00030 {
00031 int xpos, ypos;
00032 int xi, yi;
00033 int target;
00034 xpos = w->m[pet].x;
00035 ypos = w->m[pet].y;
00036
00037
00038 for(yi = ypos-1; yi <= ypos+1; yi++)
00039 for(xi = xpos-1; xi <= xpos+1; xi++)
00040 {
00041 if(xi == xpos && yi == ypos) continue;
00042
00043 target = monstbytile(xi, yi);
00044 if(target == -1) continue;
00045 if(monst_is_peaceful(target)) continue;
00046
00047 monst_swing_monst(pet, target, MTRIGGER_NORMAL);
00048 return;
00049 }
00050
00051
00052 if( distancesquare(w->plr.x, w->plr.y, xpos, ypos) > 4 )
00053 {
00054 monstmovetowardsplayer(pet);
00055 return;
00056 }
00057
00058
00059 monstmoverandomly(pet, 0);
00060 }
00061
00062
00063
00064 void monst_swing_monst(int attacker, int target, int trigger)
00065 {
00066 int i;
00067 int ret=0;
00068
00069 for(i=0; i<MDESC(attacker)->numattacks; i++)
00070 {
00071 if(MATTACK(attacker, i).trigger == trigger)
00072 {
00073 ret = 1;
00074 if(monst_hit_monst(i, attacker, target))
00075 monst_attack_monst(i, attacker, target);
00076 else
00077 {
00078 if(player_can_see(attacker) && player_can_see(target))
00079 message(gettext("The %s misses the %s!"), monstname(attacker), monstname(target));
00080 else if(player_can_see(attacker))
00081 message(gettext("The %s misses something!"), monstname(attacker));
00082 else if(player_can_see(target))
00083 message(gettext("The %s evades something!"), monstname(target));
00084 else
00085 message(gettext("You hear the sound of combat."));
00086 }
00087 }
00088
00089 if(isNull(w->m[attacker].type) || isNull(w->m[target].type))
00090 return;
00091 }
00092 }
00093
00094
00095 void monst_attack_monst(int attacknum, int attacker, int target)
00096 {
00097 int damage;
00098 monstattack *attacks;
00099
00100 if(attacker == target)
00101 return;
00102
00103 attacks = MDESC(attacker)->attacks;
00104 damage = rrandom( attacks[attacknum].damage );
00105
00106 monst_anger(target);
00107 call_attackfunc( attacks[attacknum].type, attacker, damage, target );
00108 }
00109
00110
00111
00112
00113 ushort monst_battle_pet(ushort monst)
00114 {
00115 int xpos, ypos;
00116 int xi, yi;
00117 int target;
00118 xpos = w->m[monst].x;
00119 ypos = w->m[monst].y;
00120
00121 for(yi = ypos-1; yi <= ypos+1; yi++)
00122 for(xi = xpos-1; xi <= xpos+1; xi++)
00123 {
00124 target = monstbytile(xi, yi);
00125 if(target >= 0)
00126 {
00127 if(monst_is_pet(target))
00128 {
00129 monst_swing_monst(monst, target, MTRIGGER_NORMAL);
00130 return 1;
00131 }
00132 }
00133 }
00134 return 0;
00135 }
00136
00137