chr_shared.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 "q_shared.h"
00027 #include "chr_shared.h"
00028
00033 qboolean CHRSH_IsTeamDefAlien (const teamDef_t* const td)
00034 {
00035 return td->race == RACE_TAMAN || td->race == RACE_ORTNOK
00036 || td->race == RACE_BLOODSPIDER || td->race == RACE_SHEVAAR;
00037 }
00038
00043 qboolean CHRSH_IsTeamDefRobot (const teamDef_t* const td)
00044 {
00045 return td->race == RACE_ROBOT || td->race == RACE_BLOODSPIDER;
00046 }
00047
00054 void CHRSH_CharGenAbilitySkills (character_t * chr, qboolean multiplayer)
00055 {
00056 int i;
00057 const int (*chrTemplate)[2];
00058 const teamDef_t *td;
00059 const chrTemplate_t *ct;
00060
00061 td = chr->teamDef;
00062
00063
00064 if (multiplayer && td->race == RACE_PHALANX_HUMAN) {
00065 for (i = 0; i < td->numTemplates; i++) {
00066 if (!strcmp(td->characterTemplates[i]->id, "soldier_mp")) {
00067 ct = td->characterTemplates[i];
00068 break;
00069 }
00070 }
00071 if (i >= td->numTemplates)
00072 Sys_Error("CHRSH_CharGenAbilitySkills: No multiplayer character template found (soldier_mp)");
00073 } else if (td->characterTemplates[0]) {
00074 if (td->numTemplates > 1) {
00075 int sumRate = 0;
00076 for (i = 0; i < td->numTemplates; i++) {
00077 ct = td->characterTemplates[i];
00078 sumRate += ct->rate;
00079 }
00080 if (sumRate) {
00081 const float soldierRoll = frand();
00082 int curRate = 0;
00083 for (ct = td->characterTemplates[0]; ct->id; ct++) {
00084 curRate += ct->rate;
00085 if (curRate && soldierRoll <= (curRate / sumRate))
00086 break;
00087 }
00088 } else
00089
00090 ct = td->characterTemplates[0];
00091 } else
00092
00093 ct = td->characterTemplates[0];
00094 } else
00095 Sys_Error("CHRSH_CharGenAbilitySkills: No character template for team %s!", td->id);
00096 chrTemplate = ct->skills;
00097
00098 assert(chrTemplate);
00099
00100
00101 for (i = 0; i < SKILL_NUM_TYPES; i++) {
00102 const int abilityWindow = chrTemplate[i][1] - chrTemplate[i][0];
00103
00104 const int temp = (frand() * abilityWindow) + chrTemplate[i][0];
00105 chr->score.skills[i] = temp;
00106 chr->score.initialSkills[i] = temp;
00107 }
00108
00109 {
00110
00111 const int abilityWindow = chrTemplate[i][1] - chrTemplate[i][0];
00112 const int temp = (frand() * abilityWindow) + chrTemplate[i][0];
00113 chr->score.initialSkills[SKILL_NUM_TYPES] = temp;
00114 chr->maxHP = temp;
00115 chr->HP = temp;
00116 }
00117
00118
00119 chr->morale = GET_MORALE(chr->score.skills[ABILITY_MIND]);
00120 if (chr->morale >= MAX_SKILL)
00121 chr->morale = MAX_SKILL;
00122
00123
00124 for (i = 0; i <= SKILL_NUM_TYPES; i++) {
00125 chr->score.experience[i] = 0;
00126 }
00127 }
00128
00135 const char *CHRSH_CharGetBody (const character_t * const chr)
00136 {
00137 static char returnModel[MAX_VAR];
00138
00139
00140 if (INVSH_HasArmour(&chr->i) && chr->teamDef->race != RACE_ROBOT) {
00141 const objDef_t *od = INVSH_HasArmour(&chr->i)->item.t;
00142 const char *id = od->armourPath;
00143 if (!INV_IsArmour(od))
00144 Sys_Error("CHRSH_CharGetBody: Item is no armour");
00145
00146 Com_sprintf(returnModel, sizeof(returnModel), "%s%s/%s", chr->path, id, chr->body);
00147 } else
00148 Com_sprintf(returnModel, sizeof(returnModel), "%s/%s", chr->path, chr->body);
00149 return returnModel;
00150 }
00151
00157 const char *CHRSH_CharGetHead (const character_t * const chr)
00158 {
00159 static char returnModel[MAX_VAR];
00160
00161
00162 if (INVSH_HasArmour(&chr->i) && chr->teamDef->race != RACE_ROBOT) {
00163 const objDef_t *od = INVSH_HasArmour(&chr->i)->item.t;
00164 const char *id = od->armourPath;
00165 if (!INV_IsArmour(od))
00166 Sys_Error("CHRSH_CharGetBody: Item is no armour");
00167
00168 Com_sprintf(returnModel, sizeof(returnModel), "%s%s/%s", chr->path, id, chr->head);
00169 } else
00170 Com_sprintf(returnModel, sizeof(returnModel), "%s/%s", chr->path, chr->head);
00171 return returnModel;
00172 }