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