MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1 | // MorgenGrauen MUDlib |
| 2 | // |
| 3 | // inpc/boozing.c -- Intelligentes Saufen |
| 4 | // |
| 5 | // $Id: boozing.c 8396 2013-02-18 21:56:37Z 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.h> |
| 13 | #include <living.h> |
| 14 | #include <inpc.h> |
| 15 | #include <container/moneyhandler.h> |
| 16 | #include <properties.h> |
| 17 | |
| 18 | #define DRINK_IDS 1 |
| 19 | #define DRINK_COST 2 |
| 20 | #define DRINK_HEAL 3 |
| 21 | #define DRINK_ALC 4 |
| 22 | #define DRINK_SAT 5 |
| 23 | |
| 24 | int Drink() { |
| 25 | mixed drinks; |
| 26 | object env; |
| 27 | int i,max,mon,hdiff; |
| 28 | |
| 29 | if ((mon=QueryMoney())<=0 |
| 30 | || !(env=environment()) |
| 31 | || !pointerp(drinks=env->query_drink()) |
| 32 | || (hdiff=QueryProp(P_MAX_HP)-QueryProp(P_HP))<=0) |
| 33 | return 0; |
| 34 | max=-1; |
| 35 | for (i=sizeof(drinks)-1;i>=0;i--) { |
| 36 | if (drinks[i][DRINK_COST]>mon |
| 37 | || ((drinks[i][DRINK_ALC]>0) && |
| 38 | ((drinks[i][DRINK_ALC]+QueryProp(P_ALCOHOL)) |
| 39 | > (100-QueryProp(P_I_HATE_ALCOHOL)))) |
| 40 | || drinks[i][DRINK_SAT]+QueryProp(P_DRINK)>100 |
| 41 | || drinks[i][DRINK_HEAL]<=0) |
| 42 | continue; |
| 43 | if (max<0 |
| 44 | || (drinks[i][DRINK_HEAL]>drinks[max][DRINK_HEAL] && |
| 45 | drinks[max][DRINK_HEAL]<hdiff) |
| 46 | || (drinks[i][DRINK_HEAL]>=hdiff && |
| 47 | drinks[i][DRINK_COST]<drinks[max][DRINK_COST])) |
| 48 | max=i; |
| 49 | } |
| 50 | if (max<0) return 0; |
| 51 | command("bestell "+drinks[max][DRINK_IDS][0]); |
| 52 | return 1; |
| 53 | } |
| 54 | |
| 55 | void DrinkLoop() { |
| 56 | while (remove_call_out("DrinkLoop")>=0); |
| 57 | if (!Drink()) |
| 58 | return; |
| 59 | call_out("DrinkLoop",0); |
| 60 | } |
| 61 | |