00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "../cl_shared.h"
00027 #include "cp_campaign.h"
00028 #include "cp_nations.h"
00029 #include "cp_time.h"
00030
00041 void CP_NationHandleBudget (void)
00042 {
00043 int i, j;
00044 char message[1024];
00045 int cost;
00046 int totalIncome = 0;
00047 int totalExpenditure = 0;
00048 int initialCredits = ccs.credits;
00049 employee_t *employee;
00050
00051
00052
00053 E_RefreshUnhiredEmployeeGlobalList(EMPL_PILOT, qtrue);
00054
00055 for (i = 0; i < ccs.numNations; i++) {
00056 nation_t *nation = &ccs.nations[i];
00057 const int funding = NAT_GetFunding(nation, 0);
00058 int newScientists = 0, newSoldiers = 0, newWorkers = 0;
00059
00060 totalIncome += funding;
00061
00062 for (j = 0; 0.25 + j < (float) nation->maxScientists * nation->stats[0].happiness * nation->stats[0].happiness; j++) {
00063
00064 E_CreateEmployee(EMPL_SCIENTIST, nation, NULL);
00065 newScientists++;
00066 }
00067
00068
00069 if (nation->stats[0].happiness > 0) {
00070 for (j = 0; 0.25 + j < (float) nation->maxSoldiers * nation->stats[0].happiness * nation->stats[0].happiness * nation->stats[0].happiness; j++) {
00071
00072 E_CreateEmployee(EMPL_SOLDIER, nation, NULL);
00073 newSoldiers++;
00074 }
00075 }
00076
00077 for (j = 0; 0.25 + j * 2 < (float) nation->maxSoldiers * nation->stats[0].happiness; j++) {
00078
00079 E_CreateEmployee(EMPL_WORKER, nation, NULL);
00080 newWorkers++;
00081 }
00082
00083 Com_sprintf(message, sizeof(message), _("Gained %i %s, %i %s, %i %s, and %i %s from nation %s (%s)"),
00084 funding, ngettext("credit", "credits", funding),
00085 newScientists, ngettext("scientist", "scientists", newScientists),
00086 newSoldiers, ngettext("soldier", "soldiers", newSoldiers),
00087 newWorkers, ngettext("worker", "workers", newWorkers),
00088 _(nation->name), NAT_GetHappinessString(nation));
00089 MS_AddNewMessageSound(_("Notice"), message, qfalse, MSG_STANDARD, NULL, qfalse);
00090 }
00091
00092 for (i = 0; i < MAX_EMPL; i++) {
00093 employee = NULL;
00094 cost = 0;
00095 while ((employee = E_GetNextHired(i, employee))) {
00096 cost += CP_GetSalaryBaseEmployee(employee->type)
00097 + employee->chr.score.rank * CP_GetSalaryRankBonusEmployee(employee->type);
00098 }
00099 totalExpenditure += cost;
00100 Com_sprintf(message, sizeof(message), _("Paid %i credits to: %s"), cost, E_GetEmployeeString(i));
00101 MS_AddNewMessageSound(_("Notice"), message, qfalse, MSG_STANDARD, NULL, qfalse);
00102 }
00103
00104 cost = 0;
00105 for (i = 0; i < MAX_BASES; i++) {
00106 base_t *base = B_GetFoundedBaseByIDX(i);
00107 aircraft_t *aircraft;
00108
00109 if (!base)
00110 continue;
00111
00112 aircraft = NULL;
00113 while ((aircraft = AIR_GetNextFromBase(base, aircraft)) != NULL)
00114 cost += aircraft->price * SALARY_AIRCRAFT_FACTOR / SALARY_AIRCRAFT_DIVISOR;
00115 }
00116 totalExpenditure += cost;
00117
00118 if (cost != 0) {
00119 Com_sprintf(message, sizeof(message), _("Paid %i credits for aircraft"), cost);
00120 MS_AddNewMessageSound(_("Notice"), message, qfalse, MSG_STANDARD, NULL, qfalse);
00121 }
00122
00123 for (i = 0; i < MAX_BASES; i++) {
00124 const base_t const *base = B_GetFoundedBaseByIDX(i);
00125 if (!base)
00126 continue;
00127 cost = CP_GetSalaryUpKeepBase(base);
00128 totalExpenditure += cost;
00129
00130 Com_sprintf(message, sizeof(message), _("Paid %i credits for upkeep of %s"), cost, base->name);
00131 MS_AddNewMessageSound(_("Notice"), message, qfalse, MSG_STANDARD, NULL, qfalse);
00132 }
00133
00134 cost = CP_GetSalaryAdministrative();
00135 Com_sprintf(message, sizeof(message), _("Paid %i credits for administrative overhead."), cost);
00136 totalExpenditure += cost;
00137 MS_AddNewMessageSound(_("Notice"), message, qfalse, MSG_STANDARD, NULL, qfalse);
00138
00139 if (initialCredits < 0) {
00140 float interest = initialCredits * SALARY_DEBT_INTEREST;
00141
00142 cost = (int)ceil(interest);
00143 Com_sprintf(message, sizeof(message), _("Paid %i credits in interest on your debt."), cost);
00144 totalExpenditure += cost;
00145 MS_AddNewMessageSound(_("Notice"), message, qfalse, MSG_STANDARD, NULL, qfalse);
00146 }
00147 CL_UpdateCredits(ccs.credits - totalExpenditure + totalIncome);
00148 CL_GameTimeStop();
00149 }
00150
00157 void CP_NationBackupMonthlyData (void)
00158 {
00159 int i, nat;
00160
00165 for (nat = 0; nat < ccs.numNations; nat++) {
00166 nation_t *nation = &ccs.nations[nat];
00167
00168 for (i = MONTHS_PER_YEAR - 1; i > 0; i--) {
00169 nation->stats[i] = nation->stats[i - 1];
00170 }
00171 }
00172 }