Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals

tithe.c

Go to the documentation of this file.
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 /* This command is coded around my person kingdom system, and may need to be adjusted 
00019  * accordingly to fit with DSL if it is accepted. I will try to make as many comments
00020  * as possible to help with the converting process. If any questions arise, do feel 
00021  * free to ask. */
00022 
00023 /* Things of interests:
00024  *
00025  * tithe_account should be a type int.
00026  * tithe should be a type float, but when saving, it should be saved as an integer, 
00027  *   but and casted as such. When loaded, it should be loaded as an integer but 
00028  *   casted to a float (kingdom_data[king].tithe = (float)fread_number(fp);
00029  *
00030  * check_tithe should be called in all places where the player will be receiving
00031  * a cash prize, except in player-to-player cash giving. Where you place 
00032  * check_tithe, you should remove the ch->gold += and ch->silver+= code since
00033  * check_tithe will do that all for you.
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     /* kingdom_data is the structures that I have for my kingdom system which are loaded and saved to
00054      * disk when needed. They are not hardcoded. I have simply added a 'int tithe' part to the struct
00055      * and updated my save_kingdom_data/load_kingdom_data code to load and save the tithe. */
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 /* Here we'll check the gold drop and compute what needs to be done. */
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     /* If you don't get 1 gold from your kill, then you are not tithed. */
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     /* Calculate the tithe from both gold and silver. In my orginal plans, I had
00115      * it converting the gold to silver, then tithing from that..but that proved
00116      * to have more problems since when you kill something, you can get upwars to
00117      * over a thousand silver. So we'll thithe from both and get better, accurate
00118      * results. */
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     /* tithe_account is the bank account that we'll put this in. Since DSL's accounts
00125      * deal only in eggs, this one will have to be differnt so it can deal in silver/
00126      * gold. TODO: Add code here to check the current account number, and convert to
00127      * eggs/blues. Or, you can just have it do it manually in the command to show 
00128      * how much has been tithed. */
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     /* Need to convert it back to usuable money so we can give it to the citizen. This
00137      * math is pretty accurate I believe and should give what is needed, no more, and no
00138      * less. */
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; /*,blue, eggs*/ /* for you DSL folks to determine */
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 }

Generated on Thu Jan 13 21:48:14 2005 for Beyond the Shadows by  doxygen 1.4.0