MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame^] | 1 | // MorgenGrauen MUDlib |
| 2 | // |
| 3 | // trading_price.c -- Preisverhalten von Laeden und Haendlern |
| 4 | // |
| 5 | // $Id: trading_price.c,v 3.3 2002/06/09 19:51:40 Tilly Exp $ |
| 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 <bank.h> |
| 15 | |
| 16 | #undef NEED_PROTOTYPES |
| 17 | #include <properties.h> |
| 18 | |
| 19 | // TODO: langfristig zu private aendern? |
| 20 | nosave int buyfact, shop_percent_left, mymoney, wantto, last; |
| 21 | private nosave int wantthresh, maxnum; |
| 22 | |
| 23 | varargs int SetTradingData(int money, int factor, int maxobs) |
| 24 | { |
| 25 | if (extern_call() && previous_object() != this_object()) |
| 26 | log_file("ZENTRALBANK",sprintf("INITIALIZE: %O got (%d,%d,%d) from %O (%O)\n", |
| 27 | this_object(), money,factor,maxobs, |
| 28 | previous_object(),this_player())); |
| 29 | |
| 30 | if (money < 1000) |
| 31 | money = 1000; |
| 32 | |
| 33 | last=wantto=mymoney=money; |
| 34 | wantthresh=wantto/2; |
| 35 | if (wantthresh < 5000) |
| 36 | wantthresh = 5000; |
| 37 | |
| 38 | if (factor < 100) |
| 39 | buyfact = 300; |
| 40 | else |
| 41 | buyfact = factor; |
| 42 | |
| 43 | if (maxobs < 1) |
| 44 | maxnum=3; |
| 45 | else |
| 46 | maxnum=maxobs; |
| 47 | |
| 48 | return mymoney; |
| 49 | } |
| 50 | |
| 51 | void SetBuyFact(int i) |
| 52 | { |
| 53 | buyfact=i*100; |
| 54 | } |
| 55 | |
| 56 | varargs int QueryBuyFact(object client) |
| 57 | { |
| 58 | return buyfact; |
| 59 | } |
| 60 | |
| 61 | int InflateSellValue(int value, int cnt) |
| 62 | { |
| 63 | cnt-=maxnum; |
| 64 | if (cnt<0) cnt=0; |
| 65 | return value-(value*cnt)/(cnt+25); |
| 66 | } |
| 67 | |
| 68 | int TruncateSellValue(int value) |
| 69 | { |
| 70 | if (value > 500) { |
| 71 | value-=500; |
| 72 | value = ((1000*value)/(value+1000))+500; |
| 73 | } |
| 74 | return value; |
| 75 | } |
| 76 | |
| 77 | int ObjectCount(object ob) |
| 78 | { |
| 79 | return objectp(ob); // 0 oder 1 |
| 80 | } |
| 81 | |
| 82 | varargs int QueryValue(object ob, int value, object client) |
| 83 | { |
| 84 | value=TruncateSellValue(InflateSellValue(value,ObjectCount(ob))); |
| 85 | if (3*value>mymoney) |
| 86 | { |
| 87 | log_file("LADEN",sprintf("Out of money: %O for %O (%s)\n",this_object(), |
| 88 | this_player(),dtime(time())[5..])); |
| 89 | value=mymoney/3; |
| 90 | } |
| 91 | if (value<0) value=0; |
| 92 | |
| 93 | /* Preisverfall von beschaedigtenObjekten gleich hier festlegen */ |
| 94 | |
| 95 | if(value && ob->QueryProp(P_DAMAGED)) |
| 96 | { |
| 97 | if(ob->QueryProp(P_WC) || ob->QueryProp(P_AC)) |
| 98 | { |
| 99 | value = (6 * (value / 10)); |
| 100 | } |
| 101 | else |
| 102 | { |
| 103 | value = (4 * (value / 10)); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | return value; |
| 108 | } |
| 109 | |
| 110 | varargs int QuerySellValue(object ob, object client) |
| 111 | { |
| 112 | return QueryValue(ob,ob->QueryProp(P_VALUE),client); |
| 113 | } |
| 114 | |
| 115 | varargs int QueryBuyValue(mixed ob, object client) |
| 116 | { |
| 117 | // Mit Runden. |
| 118 | return (ob->QueryProp(P_VALUE)*QueryBuyFact(client) + 50)/100; |
| 119 | } |
| 120 | |
| 121 | protected void create() |
| 122 | { |
| 123 | SetProp(P_SHOP_PERCENT_LEFT, 0); |
| 124 | SetTradingData(50000,300,3); |
| 125 | } |
| 126 | |
| 127 | protected void create_super() { |
| 128 | set_next_reset(-1); |
| 129 | } |
| 130 | |
| 131 | void reset() |
| 132 | { |
| 133 | SetProp(P_SHOP_PERCENT_LEFT, 0); |
| 134 | |
| 135 | if (last/3>mymoney) |
| 136 | wantto=wantto*110/100; |
| 137 | else |
| 138 | if (last/2<mymoney) |
| 139 | wantto=wantto*85/100; |
| 140 | if (wantto<wantthresh) wantto=wantthresh+500; |
| 141 | if (wantto>1500000) wantto=1500000; |
| 142 | if (wantto<mymoney) |
| 143 | { |
| 144 | ZENTRALBANK->PayIn(mymoney-wantto); |
| 145 | mymoney=wantto; |
| 146 | } else |
| 147 | mymoney+=ZENTRALBANK->WithDraw(wantto-mymoney); |
| 148 | last=mymoney; |
| 149 | } |
| 150 | |
| 151 | void _add_money(int i) { |
| 152 | if (extern_call() && previous_object() != this_object()) |
| 153 | log_file("ZENTRALBANK",sprintf("%s: TRANSFER: %O got %d from %O\n", |
| 154 | strftime("%H:%M"), this_object(), i, previous_object())); |
| 155 | mymoney+=i; |
| 156 | } |
| 157 | |
| 158 | int _set_shop_percent_left(int dummy) { |
| 159 | return shop_percent_left=ZENTRALBANK->_query_shop_percent_left(); |
| 160 | } |
| 161 | |
| 162 | int _query_shop_percent_left() { |
| 163 | return shop_percent_left; |
| 164 | } |
| 165 | |
| 166 | int _query_current_money() { |
| 167 | return mymoney; |
| 168 | } |
| 169 | |
| 170 | int _query_wantto() { |
| 171 | return wantto; |
| 172 | } |
| 173 | |
| 174 | |