cp_alien_interest.c
Go to the documentation of this file.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_alien_interest.h"
00029 #include "save/save_interest.h"
00030
00036 void CL_ResetAlienInterest (void)
00037 {
00038 int i;
00039
00040 ccs.lastInterestIncreaseDelay = 0;
00041 ccs.lastMissionSpawnedDelay = 0;
00042 ccs.overallInterest = INITIAL_OVERALL_INTEREST;
00043
00044 for (i = 0; i < INTERESTCATEGORY_MAX; i++)
00045 ccs.interest[i] = 0;
00046 ccs.interest[INTERESTCATEGORY_RECON] = INITIAL_OVERALL_INTEREST;
00047 }
00048
00055 void CL_ChangeIndividualInterest (float interestFactor, interestCategory_t category)
00056 {
00057 if (category == INTERESTCATEGORY_MAX) {
00058 Com_Printf("CL_ChangeIndividualInterest: Unsupported value of category\n");
00059 return;
00060 }
00061
00062 if (interestFactor > 0.0f) {
00063 const int gain = (int) (interestFactor * ccs.overallInterest);
00064 const int diff = ccs.overallInterest - ccs.interest[category];
00065
00066
00067 const float slowerIncreaseFraction = 0.5f;
00068
00069
00070 if (diff > gain)
00071
00072 ccs.interest[category] += gain;
00073 else if (diff > 0)
00074
00075 ccs.interest[category] = ccs.overallInterest + (int) (slowerIncreaseFraction * (gain - diff));
00076 else
00077
00078 ccs.interest[category] += (int) (slowerIncreaseFraction * gain);
00079 } else {
00080
00081 ccs.interest[category] += (int) (interestFactor * ccs.interest[category]);
00082 if (ccs.interest[category] < 0) {
00083
00084 ccs.interest[category] = 0;
00085 }
00086 }
00087 }
00088
00094 void CP_IncreaseAlienInterest (void)
00095 {
00096
00097 const int delayBetweenIncrease = HOURS_PER_ONE_INTEREST - ccs.curCampaign->difficulty;
00098
00099 ccs.lastInterestIncreaseDelay++;
00100
00101 if (ccs.lastInterestIncreaseDelay > delayBetweenIncrease) {
00102 ccs.overallInterest++;
00103 ccs.lastInterestIncreaseDelay %= delayBetweenIncrease;
00104 }
00105 }
00106
00111 qboolean CP_SaveInterestsXML (mxml_node_t *parent)
00112 {
00113 mxml_node_t *interestsNode = mxml_AddNode(parent, SAVE_INTERESTS);
00114 int i;
00115
00116 mxml_AddShortValue(interestsNode, SAVE_INTERESTS_LASTINCREASEDELAY, ccs.lastInterestIncreaseDelay);
00117 mxml_AddShortValue(interestsNode, SAVE_INTERESTS_LASTMISSIONSPAWNEDDELAY, ccs.lastMissionSpawnedDelay);
00118 mxml_AddShortValue(interestsNode, SAVE_INTERESTS_OVERALL, ccs.overallInterest);
00119 Com_RegisterConstList(saveInterestConstants);
00120 for (i = 0; i < INTERESTCATEGORY_MAX; i++) {
00121 mxml_node_t * interestNode = mxml_AddNode(interestsNode, SAVE_INTERESTS_INTEREST);
00122 mxml_AddString(interestNode, SAVE_INTERESTS_ID, Com_GetConstVariable(SAVE_INTERESTCAT_NAMESPACE, i));
00123 mxml_AddShort(interestNode, SAVE_INTERESTS_VAL, ccs.interest[i]);
00124 }
00125 Com_UnregisterConstList(saveInterestConstants);
00126 return qtrue;
00127 }
00128
00133 qboolean CP_LoadInterestsXML (mxml_node_t *parent)
00134 {
00135 mxml_node_t *node;
00136 mxml_node_t *interestsNode = mxml_GetNode(parent, SAVE_INTERESTS);
00137 qboolean success = qtrue;
00138
00139 ccs.lastInterestIncreaseDelay = mxml_GetInt(interestsNode, SAVE_INTERESTS_LASTINCREASEDELAY, 0);
00140 ccs.lastMissionSpawnedDelay = mxml_GetInt(interestsNode, SAVE_INTERESTS_LASTMISSIONSPAWNEDDELAY, 0);
00141 ccs.overallInterest = mxml_GetInt(interestsNode, SAVE_INTERESTS_OVERALL, 0);
00142 Com_RegisterConstList(saveInterestConstants);
00143 for (node = mxml_GetNode(interestsNode, SAVE_INTERESTS_INTEREST); node;
00144 node = mxml_GetNextNode(node, interestsNode, SAVE_INTERESTS_INTEREST)) {
00145 const char *categoryId = mxml_GetString(node, SAVE_INTERESTS_ID);
00146 int cat;
00147
00148 if (!Com_GetConstInt(categoryId, (int*) &cat)) {
00149 Com_Printf("Invaild interest category '%s'\n", categoryId);
00150 success = qfalse;
00151 break;
00152 }
00153 ccs.interest[cat]= mxml_GetInt(node, SAVE_INTERESTS_VAL, 0);
00154 }
00155 Com_UnregisterConstList(saveInterestConstants);
00156 return success;
00157 }
00158