MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1 | // MorgenGrauen MUDlib |
| 2 | // |
| 3 | // inpc/eval.c -- Einschaetzen von Gegnern |
| 4 | // |
| 5 | // $Id: eval.c 6371 2007-07-17 22:46:50Z Zesstra $ |
| 6 | #pragma strong_types |
| 7 | #pragma save_types |
| 8 | #pragma range_check |
| 9 | #pragma no_clone |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 10 | |
| 11 | #define NEED_PROTOTYPES |
| 12 | #include <thing/properties.h> |
| 13 | #include <living.h> |
| 14 | #undef NEED_PROTOTYPES |
| 15 | #include <properties.h> |
| 16 | #include <thing.h> |
| 17 | #include <inpc.h> |
| 18 | |
| 19 | varargs void SetEvalFactor(mixed what, int fac, int off) { |
| 20 | mapping offs,facs; |
| 21 | |
| 22 | if (!mappingp(facs=QueryProp(P_EVAL_FACTORS))) facs=([]); |
| 23 | if (!mappingp(offs=QueryProp(P_EVAL_OFFSETS))) offs=([]); |
| 24 | facs[what]=fac; |
| 25 | offs[what]=off; |
| 26 | SetProp(P_EVAL_FACTORS,facs); |
| 27 | SetProp(P_EVAL_OFFSETS,offs); |
| 28 | } |
| 29 | |
| 30 | void SetDefaultEvalFactors() { |
| 31 | SetEvalFactor(P_HP,150,-60); |
| 32 | SetEvalFactor(P_TOTAL_WC,250,0); |
| 33 | SetEvalFactor(P_TOTAL_AC,1000,-50); |
| 34 | SetEvalFactor("abenteurer_pfeil",3,0); |
| 35 | SetEvalFactor("abenteurer_feuerball",8,0); |
| 36 | } |
| 37 | |
| 38 | varargs int |
| 39 | modify_eval(object ob, mixed what, mapping fac, mapping off, int val) { |
| 40 | if (!val) val=QueryProp(what); |
| 41 | val-=off[what]; |
| 42 | if (val<0) val=0; |
| 43 | val=(val*fac[what])/10000; |
| 44 | if (val>200) val=200; |
| 45 | return val; |
| 46 | } |
| 47 | |
| 48 | varargs int eval_enemy(object enemy, mapping fac, mapping off) { |
| 49 | int res; |
| 50 | string gilde; |
| 51 | |
| 52 | if (!objectp(enemy)) return 0; |
| 53 | if (!mappingp(fac)) fac=QueryProp(P_EVAL_FACTORS); |
| 54 | if (!mappingp(fac)) fac=([]); |
| 55 | if (!mappingp(off)) off=QueryProp(P_EVAL_OFFSETS); |
| 56 | if (!mappingp(off)) off=([]); |
| 57 | |
| 58 | res=0; |
| 59 | res+=modify_eval(enemy,P_TOTAL_WC,fac,off); |
| 60 | res+=modify_eval(enemy,P_TOTAL_AC,fac,off); |
| 61 | res+=modify_eval(enemy,P_HP,fac,off); |
| 62 | if (stringp(gilde=enemy->QueryProp(P_GUILD))) |
| 63 | res+=call_other(this_object(),"eval_guild_"+gilde,enemy,fac,off,gilde); |
| 64 | if (res<0) res=0; |
| 65 | if (res>1000) res=1000; |
| 66 | return res; |
| 67 | } |
| 68 | |
| 69 | varargs mixed *eval_enemies(mapping fac, mapping off, object *here) { |
| 70 | int i,sz; |
| 71 | mixed *res; |
| 72 | |
| 73 | res=({}); |
| 74 | if (!here) |
| 75 | here=PresentEnemies(); |
| 76 | if (!pointerp(here) || !(sz=sizeof(here))) |
| 77 | return res; |
| 78 | if (!mappingp(fac)) fac=QueryProp(P_EVAL_FACTORS); |
| 79 | if (!mappingp(fac)) fac=([]); |
| 80 | if (!mappingp(off)) off=QueryProp(P_EVAL_OFFSETS); |
| 81 | if (!mappingp(off)) off=([]); |
| 82 | |
| 83 | for (i=sz-1;i>=0;i--) |
| 84 | res+=({({here[i],eval_enemy(here[i],fac,off)})}); |
| 85 | return res; |
| 86 | } |
| 87 | |
| 88 | varargs int sum_eval_enemies(mapping fac, mapping off, object *here) { |
| 89 | int res,i; |
| 90 | mixed *evals,x,y; |
| 91 | |
| 92 | res=0; |
| 93 | if (!pointerp(evals=eval_enemies(fac,off,here))) |
| 94 | return res; |
| 95 | for (i=sizeof(evals)-1;i>=0;i--) |
| 96 | if (pointerp(x=evals[i]) && sizeof(x)>=2 && intp(y=x[1])) |
| 97 | res+=y; |
| 98 | return res; |
| 99 | } |
| 100 | |
| 101 | varargs object *minimize_prop_filt(object *here, mixed prop) { |
| 102 | object *obs,ob; |
Arathorn | b305145 | 2021-05-13 21:13:03 +0200 | [diff] [blame] | 103 | int i,mhp,hp; |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 104 | |
| 105 | obs=0; |
| 106 | if (!pointerp(here)) |
| 107 | here=PresentEnemies(); |
| 108 | if (!prop) |
| 109 | prop=P_HP; |
| 110 | for (i=sizeof(here)-1;i>=0;i--) { |
| 111 | if (objectp(ob=here[i])) { |
| 112 | hp=ob->QueryProp(prop); |
| 113 | if (!pointerp(obs) || hp<mhp) { |
| 114 | obs=({ob}); |
| 115 | mhp=hp; |
| 116 | } else if (hp==mhp) { |
| 117 | obs+=({ob}); |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | if (!pointerp(obs)) |
| 122 | obs=({}); |
| 123 | return obs; |
| 124 | } |
| 125 | |
| 126 | varargs object *maximize_prop_filt(object *here, mixed prop) { |
| 127 | object *obs,ob; |
Arathorn | b305145 | 2021-05-13 21:13:03 +0200 | [diff] [blame] | 128 | int i,mwc,wc; |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 129 | |
| 130 | obs=0; |
| 131 | if (!pointerp(here)) |
| 132 | here=PresentEnemies(); |
| 133 | if (!prop) |
| 134 | prop=P_TOTAL_WC; |
| 135 | for (i=sizeof(here)-1;i>=0;i--) { |
| 136 | if (objectp(ob=here[i])) { |
| 137 | wc=ob->QueryProp(prop); |
| 138 | if (!pointerp(obs) || wc<mwc) { |
| 139 | obs=({ob}); |
| 140 | mwc=wc; |
| 141 | } else if (wc==mwc) { |
| 142 | obs+=({ob}); |
| 143 | } |
| 144 | } |
| 145 | } |
| 146 | if (!pointerp(obs)) |
| 147 | obs=({}); |
| 148 | return obs; |
| 149 | } |
| 150 | |
| 151 | varargs object *player_filt(object *here) { |
| 152 | object *obs,ob; |
| 153 | int i; |
| 154 | |
| 155 | obs=({}); |
| 156 | if (!pointerp(here)) |
| 157 | here=PresentEnemies(); |
| 158 | for (i=sizeof(here)-1;i>=0;i--) |
| 159 | if (objectp(ob=here[i]) && query_once_interactive(ob)) |
| 160 | obs+=({ob}); |
| 161 | return obs; |
| 162 | } |
| 163 | |
| 164 | varargs object select_enemy_min_prop(object *here, mixed prop) { |
| 165 | object *obs; |
| 166 | int sz; |
| 167 | |
| 168 | if (pointerp(obs=minimize_prop_filt(here,prop)) && (sz=sizeof(obs))) |
| 169 | return obs[random(sz)]; |
| 170 | return 0; |
| 171 | } |
| 172 | |
| 173 | varargs object select_enemy_max_prop(object *here, mixed prop) { |
| 174 | object *obs; |
| 175 | int sz; |
| 176 | |
| 177 | if (pointerp(obs=maximize_prop_filt(here,prop)) && (sz=sizeof(obs))) |
| 178 | return obs[random(sz)]; |
| 179 | return 0; |
| 180 | } |
| 181 | |
| 182 | varargs object select_player_min_prop(object *here, mixed prop) { |
| 183 | return select_enemy_min_prop(player_filt(here),prop); |
| 184 | } |
| 185 | |
| 186 | varargs object select_player_max_prop(object *here, mixed prop) { |
| 187 | return select_enemy_max_prop(player_filt(here),prop); |
| 188 | } |