#include <thing.h>#include <living.h>#include <inpc.h>#include <properties.h>#include <combat.h>#include <language.h>
gehe zum Quellcode dieser Datei
Makrodefinitionen | |
| #define | NEED_PROTOTYPES |
| #define | ME this_object() |
Funktionen | |
| mapping | scan_objects (mixed src) |
| mixed * | find_object_by_type (mixed from, mixed typ) |
| int | eval_weapon (object ob) |
| object | find_best_weapon (mixed from) |
| varargs int | wield_best_weapon (mixed from) |
| int | eval_armour (object ob) |
| object | find_best_armour (mixed from, mixed typ) |
| object * | find_best_armours (mixed from) |
| varargs int | wear_best_armours (mixed from) |
| int | eval_combat_object (object ob, mapping vals, object enemy) |
| varargs string | find_best_combat_command (mixed from, object enemy, mapping pref) |
| varargs int | use_best_combat_command (mixed enemy, mixed from, mapping pref) |
| void | add_select_commands () |
| void add_select_commands | ( | ) |
Definiert in Zeile 333 der Datei select.c.
Wird benutzt von create().
00333 { 00334 add_action("wield_best_weapon","zuecke_beste_waffe"); 00335 add_action("wear_best_armours","trage_beste_ruestungen"); 00336 add_action("use_best_combat_command","benutze_beste_sonderwaffe"); 00337 }

| int eval_armour | ( | object | ob | ) |
| int eval_combat_object | ( | object | ob, | |
| mapping | vals, | |||
| object | enemy | |||
| ) |
Definiert in Zeile 246 der Datei select.c.
Wird benutzt von find_best_combat_command().

| int eval_weapon | ( | object | ob | ) |
| object find_best_armour | ( | mixed | from, | |
| mixed | typ | |||
| ) |
Definiert in Zeile 150 der Datei select.c.
Benutzt eval_armour(), find_object_by_type(), i und ob().
Wird benutzt von find_best_armours().
00150 { 00151 // Findet die beste Ruestung eines Typs 00152 int i,ac,bac; 00153 object *res,bob; 00154 00155 if (!pointerp(res=find_object_by_type(from, typ))) 00156 return 0; 00157 bac=-1; 00158 bob=0; 00159 foreach(object ob: res) 00160 { 00161 if (!objectp(ob)) continue; 00162 ac=eval_armour(ob); 00163 if (ac>bac) 00164 { 00165 bob=ob; 00166 bac=ac; 00167 } 00168 } 00169 return bob; 00170 }


| object* find_best_armours | ( | mixed | from | ) |
Definiert in Zeile 172 der Datei select.c.
Benutzt AT_MISC, find_best_armour(), i, ob(), scan_objects() und VALID_ARMOUR_CLASS.
Wird benutzt von wear_best_armours().
00172 { 00173 // Findet die besten Ruestungen, die gleichzeitig getragen werden koennen 00174 mapping ol; 00175 object *res,ob; 00176 mixed *types; 00177 int i; 00178 00179 if (!mappingp(ol=scan_objects(from))) 00180 return ({}); 00181 if (!pointerp(res=ol[AT_MISC])) 00182 res=({}); 00183 types=m_indices(ol); 00184 foreach(object typ: types) 00185 { 00186 if (VALID_ARMOUR_CLASS[typ]) // anderer Armour-Typ ausser AT_MISC? 00187 { 00188 ob=find_best_armour(from,typ); 00189 if (objectp(ob)) 00190 res+=({ob}); 00191 } 00192 } 00193 return res; 00194 }


| varargs string find_best_combat_command | ( | mixed | from, | |
| object | enemy, | |||
| mapping | pref | |||
| ) |
Definiert in Zeile 251 der Datei select.c.
Benutzt C_AVG, C_HEAL, C_MAX, C_MIN, eval_combat_object(), find_object_by_type(), i, ME, name, ob(), obs, OT_COMBAT_OBJECT, P_COMBATCMDS, P_HP, P_MAX_HP, P_RESISTANCE_STRENGTHS, QueryProp(), RAW, SelectEnemy() und x.
Wird benutzt von use_best_combat_command().
00251 { 00252 // Sucht den guenstigsten Befehl zur Benutzung einer Sonderwaffe heraus 00253 object *obs; 00254 mixed *ind,y,vul; 00255 mapping x; 00256 string best; 00257 int i,j,max,val,mhp; 00258 00259 if (!from) 00260 from=ME; 00261 if (!enemy) 00262 enemy=SelectEnemy(); 00263 if (!mappingp(pref)) // bevorzugte Eigenschaften 00264 pref=([C_MIN:5, 00265 C_AVG:10, 00266 C_MAX:2, 00267 C_HEAL:10 00268 ]); 00269 best=0;max=-1; 00270 if (!pointerp(obs=find_object_by_type(from,OT_COMBAT_OBJECT))) 00271 return best; 00272 mhp=QueryProp(P_MAX_HP)-QueryProp(P_HP); 00273 if (objectp(enemy)) 00274 vul=enemy->QueryProp(P_RESISTANCE_STRENGTHS); 00275 if (mhp<0) mhp=0; 00276 foreach(object ob: obs) 00277 { 00278 if (!objectp(ob)) 00279 continue; 00280 if (!mappingp(x=ob->QueryProp(P_COMBATCMDS))) 00281 continue; 00282 ind=m_indices(x); 00283 for (j=sizeof(ind)-1;j>=0;j--) 00284 { 00285 if (!stringp(ind[j])) continue; 00286 y=x[ind[j]]; 00287 if (mappingp(y)) 00288 { 00289 if (val=y[C_HEAL]) 00290 { 00291 if (val>mhp) val=mhp; // Nur MOEGLICHE Heilung beruecksichtigen 00292 val*=pref[C_HEAL]; 00293 } 00294 else 00295 { 00296 val=y[C_MIN]*pref[C_MIN] 00297 + y[C_AVG]*pref[C_AVG] 00298 + y[C_MAX]*pref[C_MAX]; 00299 // auskommentiert, da eval_resistance() bisher nicht implementiert 00300 // ist. Zesstra, 06.08.2007 00301 //if (y[C_DTYPES] && vul) // Vulnerability des Gegners bedenken... 00302 // val=(int)(((float)val)*(1.0+eval_resistance(y[C_DTYPES],vul))); 00303 } 00304 } 00305 else 00306 { 00307 val=1; 00308 } 00309 val+=eval_combat_object(obs[i],y,enemy); 00310 if (val<max) continue; 00311 max=val; 00312 if (mappingp(y) && y[C_HEAL]>0) 00313 best=sprintf(ind[j],name(RAW)); // Heilung auf sich selbst 00314 else if (objectp(enemy)) 00315 best=sprintf(ind[j],enemy->name(RAW)); // Schaden auf Gegner 00316 } 00317 } 00318 00319 return best; 00320 }


| object find_best_weapon | ( | mixed | from | ) |
Definiert in Zeile 88 der Datei select.c.
Benutzt eval_weapon(), find_object_by_type(), i, log_file, ob() und OT_WEAPON.
Wird benutzt von wield_best_weapon().
00088 { 00089 // Findet die beste Waffe 00090 int i,wc,bwc,cost,cost_limit; 00091 object *res,bob; 00092 00093 if (!pointerp(res=find_object_by_type(from, OT_WEAPON))) 00094 return 0; 00095 bwc=-1;bob=0; 00096 00097 cost_limit = get_eval_cost()/3; 00098 for (i=sizeof(res);i--;) 00099 foreach(object ob: res) 00100 { 00101 if (!objectp(ob)) continue; 00102 wc=eval_weapon(ob); 00103 if (wc>bwc) 00104 { 00105 bob=ob; 00106 bwc=wc; 00107 } 00108 00109 if ( (cost=get_eval_cost()) < cost_limit ) 00110 { 00111 log_file("rochus/raeuber_eval", 00112 "Break in select::find_best_weapon(). Rest-Ticks "+to_string(cost)+ 00113 ", i = "+to_string(i)+", Size "+to_string(sizeof(res))+".\n"); 00114 return bob; // zurueckgeben, was bisher drinsteht. 00115 break; 00116 } 00117 } 00118 return bob; 00119 }


| mixed* find_object_by_type | ( | mixed | from, | |
| mixed | typ | |||
| ) |
Definiert in Zeile 69 der Datei select.c.
Benutzt scan_objects().
Wird benutzt von find_best_armour(), find_best_combat_command() und find_best_weapon().
00069 { 00070 // Findet all Objekte eines Typs, z.B. alle Waffen im Monster 00071 // <from> kann auch ein Mapping sein, das schon die mit scan_objects 00072 // erstellt Klassifikation enthaelt, damit diese nicht mehrfach 00073 // erstellt werden muss. 00074 mixed res; 00075 00076 if (!mappingp(from)) 00077 from=scan_objects(from); 00078 if (!mappingp(from) || 00079 !pointerp(res=from[typ])) 00080 return ({}); 00081 return res; 00082 }


| mapping scan_objects | ( | mixed | src | ) |
Definiert in Zeile 23 der Datei select.c.
Benutzt ctime(), i, log_file, ob(), obs, OT_COMBAT_OBJECT, OT_MISC, OT_WEAPON, P_ARMOUR_TYPE, P_COMBATCMDS, P_WEAPON_TYPE und x.
Wird benutzt von find_best_armours() und find_object_by_type().
00023 { 00024 // Ermittelt zu jedem Typ (Waffe, Ruestungstyp...) alle Objekte diesen Typs 00025 // Gesucht wird: - Im Inventory, falls Objekt angegeben 00026 // - Im Array, falls Array angegeben 00027 object *obs; 00028 mapping res; 00029 mixed x; 00030 int i,cost,cost_limit; 00031 00032 if (mappingp(src)) 00033 return src; 00034 res=([]); 00035 if (objectp(src)) 00036 src=all_inventory(src); 00037 if (!pointerp(src)) 00038 src=({src}); 00039 00040 cost_limit = get_eval_cost()/3; 00041 foreach(object ob: src) 00042 { 00043 if ( (cost=get_eval_cost()) < cost_limit ) 00044 { 00045 log_file("rochus/raeuber_eval", 00046 ctime()+"select::scan_objects(). Rest "+to_string(cost)+ 00047 ", i="+to_string(i)+", Size "+to_string(sizeof(src))+".\n"); 00048 return res; 00049 break; 00050 } 00051 if (!objectp(ob)) 00052 continue; 00053 if (x=ob->QueryProp(P_ARMOUR_TYPE)) 00054 ; 00055 else if (ob->QueryProp(P_WEAPON_TYPE)) 00056 x=OT_WEAPON; 00057 else if (ob->QueryProp(P_COMBATCMDS)) 00058 x=OT_COMBAT_OBJECT; 00059 else 00060 x=OT_MISC; 00061 if (!pointerp(obs=res[x])) 00062 obs=({}); 00063 obs+=({ob}); 00064 res[x]=obs; 00065 } 00066 return res; 00067 }


| varargs int use_best_combat_command | ( | mixed | enemy, | |
| mixed | from, | |||
| mapping | pref | |||
| ) |
Definiert in Zeile 322 der Datei select.c.
Benutzt command und find_best_combat_command().
00322 { 00323 // Fuehrt moeglichst guten Kampfeinsatz mit einer Sonderwaffe aus 00324 string str; 00325 00326 if (stringp(enemy) && environment()) 00327 enemy=present(enemy,environment()); 00328 if (str=find_best_combat_command(from,enemy,pref)) 00329 return command(str); 00330 return 0; 00331 }

| varargs int wear_best_armours | ( | mixed | from | ) |
Definiert in Zeile 196 der Datei select.c.
Benutzt AT_SHIELD, ctime(), find_best_armours(), i, INPC_BEST_SHIELD_ID, log_file, ME, P_ARMOUR_TYPE, P_ARMOURS und QueryProp().
00196 { 00197 // Die besten Ruestungen werden angezogen 00198 // Sollte mit command("trage_beste_ruestungen") aufgerufen werden, 00199 // damit this_player() richtig gesetzt wird. 00200 object *na,*oa,*diff; 00201 int i,cost,cost_limit; 00202 00203 if (!from) 00204 from=ME; 00205 if (!pointerp(na=find_best_armours(from))) 00206 return 0; 00207 if (!pointerp(oa=QueryProp(P_ARMOURS))) 00208 oa=({}); 00209 diff=oa-na; 00210 cost_limit = get_eval_cost()/3; 00211 foreach(object di: diff) 00212 { 00213 di->RemoveId(INPC_BEST_SHIELD_ID); 00214 di->DoUnwear(); 00215 if ( (cost=get_eval_cost()) < cost_limit ) 00216 { 00217 log_file("rochus/raeuber_eval", 00218 ctime()+"Break 1 in select::wear_best_armours(). Rest "+ 00219 to_string(cost)+", i="+to_string(i)+", Size "+ 00220 to_string(sizeof(diff))+".\n"); 00221 return 1; // zurueckgeben, was bisher drinsteht. 00222 break; 00223 } 00224 } 00225 diff=na-oa; 00226 cost_limit = get_eval_cost()/3; 00227 foreach(object di: diff) 00228 { 00229 if ( di->QueryProp(P_ARMOUR_TYPE)==AT_SHIELD 00230 && !di->id(INPC_BEST_SHIELD_ID)) 00231 di->AddId(INPC_BEST_SHIELD_ID); 00232 di->do_wear("alles"); 00233 if ( (cost=get_eval_cost()) < cost_limit ) 00234 { 00235 log_file("rochus/raeuber_eval", 00236 ctime()+"Break 2 in select::wear_best_armours(). Rest "+ 00237 to_string(cost)+", i="+to_string(i)+", Size "+ 00238 to_string(sizeof(diff))+".\n"); 00239 return 1; // zurueckgeben, was bisher drinsteht. 00240 break; 00241 } 00242 } 00243 return 1; 00244 }

| varargs int wield_best_weapon | ( | mixed | from | ) |
Definiert in Zeile 121 der Datei select.c.
Benutzt find_best_weapon(), INPC_BEST_WEAPON_ID, INPC_DONT_WIELD_WEAPONS, ME, ob(), P_WEAPON und QueryProp().
00121 { 00122 // Zueckt die beste Waffe. 00123 // Sollte mit command("zuecke_beste_waffe") aufgerufen werden, 00124 // damit this_player() richtig gesetzt wird. 00125 object ob,old; 00126 00127 // Einige NPC moegen keine Waffen. Zum Beispiel Karate-Gilden-NPC 00128 // Durch Setzen von INPC_DONT_WIELD_WEAPONS kann man das Zuecken verhindern 00129 if(QueryProp(INPC_DONT_WIELD_WEAPONS)) return 0; 00130 00131 if (!from) 00132 from=ME; 00133 00134 if (!objectp(ob=find_best_weapon(from))) 00135 return 0; 00136 if (objectp(old=QueryProp(P_WEAPON)) && old!=ob) { 00137 old->RemoveId(INPC_BEST_WEAPON_ID); 00138 old->DoUnwield(); 00139 } 00140 if (!ob->id(INPC_BEST_WEAPON_ID)) 00141 ob->AddId(INPC_BEST_WEAPON_ID); 00142 00143 return ob->DoWield(); 00144 }

1.6.3