00001 #if defined(macintosh)
00002 #include <types.h>
00003 #include <time.h>
00004 #else
00005 #include <sys/types.h>
00006 #include <sys/time.h>
00007 #endif
00008 #include <stdio.h>
00009 #include <string.h>
00010 #include <stdlib.h>
00011 #include <unistd.h>
00012 #include "merc.h"
00013 #include "interp.h"
00014 #include "recycle.h"
00015 #include "tables.h"
00016 #include "lookup.h"
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 void do_tithe (CHAR_DATA *ch, char *argument)
00038 {
00039 char buf[MAX_STRING_LENGTH];
00040
00041 if (ch->king == 0 && !IS_IMMORTAL(ch))
00042 {
00043 send_to_char("Huh?\n\r",ch);
00044 return;
00045 }
00046
00047 if (!IS_SET(ch->kking, KING_LEADER) && !IS_IMMORTAL(ch))
00048 {
00049 send_to_char("You must be a kingdomer leader to set the tithe status of your kingdom.\n\r",ch);
00050 return;
00051 }
00052
00053
00054
00055
00056
00057 if (argument[0] == '\0')
00058 {
00059
00060 send_to_char("Current tithe status: ",ch);
00061 if (kingdom_data[ch->king].tithe == 0)
00062 send_to_char("None.\n\r",ch);
00063 else
00064 {
00065 sprintf(buf, "%d percent.\n\r", (int)kingdom_data[ch->king].tithe);
00066 send_to_char(buf,ch);
00067 }
00068
00069 return;
00070 }
00071
00072 if (!is_number(argument))
00073 {
00074 send_to_char("Value must be numerical and must be between 0 and 15. No percent sign should be used.\n\r",ch);
00075 return;
00076 }
00077
00078 if (atoi(argument) > 20 || atoi (argument) < 0)
00079 {
00080 send_to_char("Value must be between 0 and 15. No percent sign should be used.\n\r",ch);
00081 return;
00082 }
00083
00084 if (atoi(argument) == 0)
00085 sprintf(buf, "You will no longer tithe your citizens.\n\r");
00086 else
00087 sprintf(buf, "You will now tithe your citizens at %d percent.\n\r", atoi(argument));
00088
00089 send_to_char(buf,ch);
00090 kingdom_data[ch->king].tithe = atoi(argument);
00091 save_kingdom_data();
00092 return;
00093 }
00094
00095
00096
00097
00098 void check_tithe (CHAR_DATA *ch, int silver,int gold)
00099 {
00100 int to_keep;
00101 int tithe;
00102 int tithe_gold, tithe_silver;
00103 char buf[MAX_STRING_LENGTH];
00104
00105
00106 if ((silver <= 100 && gold <= 0) || kingdom_data[ch->king].tithe == 0)
00107 {
00108 ch->silver += silver;
00109 ch->gold += gold;
00110 return;
00111 }
00112
00113
00114
00115
00116
00117
00118
00119 tithe_silver = silver * (kingdom_data[ch->king].tithe / 100);
00120 tithe_gold = (gold * 100) * (kingdom_data[ch->king].tithe / 100);
00121
00122 tithe = tithe_gold + tithe_silver;
00123
00124
00125
00126
00127
00128
00129
00130 kingdom_data[ch->king].tithe_account += tithe;
00131
00132 sprintf(buf, "Your tithe at %d percent was %d silver and %d gold.\n\r",(int)kingdom_data[ch->king].tithe,
00133 tithe_silver + (tithe_gold % 100), tithe_gold / 100);
00134 send_to_char(buf,ch);
00135
00136
00137
00138
00139
00140 silver = silver - (tithe_silver + (tithe_gold % 100));
00141 gold = gold - (tithe_gold / 100);
00142 ch->silver += silver;
00143 ch->gold += gold;
00144 save_kingdom_data();
00145
00146 return;
00147
00148 }
00149
00150 void kingdom_check_tithe (CHAR_DATA *ch, char *argument)
00151 {
00152 char buf[MAX_STRING_LENGTH];
00153 int gold,silver;
00154 long int total;
00155
00156
00157
00158 if (ch->king == 0 && !IS_IMMORTAL(ch))
00159 {
00160 send_to_char("Huh?\n\r",ch);
00161 return;
00162 }
00163
00164 if (!IS_SET(ch->kking, KING_LEADER) && !IS_IMMORTAL(ch))
00165 {
00166 send_to_char("Huh?\n\r",ch);
00167 return;
00168 }
00169
00170 total = kingdom_data[ch->king].tithe_account;
00171
00172 send_to_char("Current Tithe Account Status:\n\r",ch);
00173 send_to_char("-----------------------------\n\r",ch);
00174 send_to_char("In bank: ",ch);
00175 if (kingdom_data[ch->king].tithe_account <= 0)
00176 sprintf(buf, "Empty.\n\r");
00177 else
00178 {
00179 if (total > 100)
00180 {
00181 gold = total / 100;
00182 silver = total - (gold * 100);
00183 sprintf(buf, "%d {YGold{x, %d {WSilver{x\n\r", gold, silver);
00184 }
00185 else
00186 sprintf(buf, "%ld Silver.\n\r",total);
00187 }
00188 send_to_char(buf,ch);
00189
00190 }
00191
00192 void get_tithe (CHAR_DATA *ch, char *argument)
00193 {
00194 char buf[MAX_STRING_LENGTH];
00195 int total;
00196 char arg[MAX_STRING_LENGTH];
00197
00198
00199
00200 if (ch->king == 0 && !IS_IMMORTAL(ch))
00201 {
00202 send_to_char("Huh?\n\r",ch);
00203 return;
00204 }
00205 if (!IS_SET(ch->kking, KING_LEADER) && !IS_IMMORTAL(ch))
00206 {
00207 send_to_char("Huh?\n\r",ch);
00208 return;
00209 }
00210
00211 argument = one_argument(argument,arg);
00212
00213 if (arg[0] == '\0')
00214 {
00215 do_function(ch, &kingdom_check_tithe, "");
00216 return;
00217 }
00218
00219 if (argument[0] == '\0')
00220 {
00221 send_to_char("Syntax: GetTithe <amount> <type> (type can be gold or silver)\n\r",ch);
00222 return;
00223 }
00224
00225 if (!is_number(arg))
00226 {
00227 send_to_char("Syntax: GetTithe <amount> <type> (type can be gold or silver)\n\r",ch);
00228 return;
00229 }
00230
00231 if (!str_prefix(argument, "gold"))
00232 {
00233 total = kingdom_data[ch->king].tithe_account;
00234 if ((atoi(arg) * 100) > total)
00235 {
00236 send_to_char("Insufficent funds.\n\r",ch);
00237 do_function(ch, &kingdom_check_tithe,"");
00238 return;
00239 }
00240
00241 ch->gold += atoi(arg);
00242 kingdom_data[ch->king].tithe_account -= (atoi(arg) * 100);
00243 sprintf(buf, "%s gold has been deducted from your tithe account.\n\r", arg);
00244 send_to_char(buf,ch);
00245 return;
00246 }
00247
00248 if (!str_prefix(argument, "silver"))
00249 {
00250 total = kingdom_data[ch->king].tithe_account;
00251 if (atoi(arg) > total)
00252 {
00253 send_to_char("Insufficent funds.\n\r",ch);
00254 do_function(ch,&kingdom_check_tithe,"");
00255 return;
00256 }
00257
00258 ch->silver += atoi(arg);
00259 kingdom_data[ch->king].tithe_account -= atoi(arg);
00260 sprintf(buf, "%s silver has been deducted from your tithe account.\n\r",arg);
00261 send_to_char(buf,ch);
00262 return;
00263 }
00264
00265 do_function(ch, &get_tithe, "");
00266 return;
00267 }