chr_shared.c

Go to the documentation of this file.
00001 
00006 /*
00007 Copyright (C) 2002-2010 UFO: Alien Invasion.
00008 
00009 This program is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU General Public License
00011 as published by the Free Software Foundation; either version 2
00012 of the License, or (at your option) any later version.
00013 
00014 This program is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00017 
00018 See the GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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     /* Add modifiers for difficulty setting here! */
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                 /* No rates or all set to 0 default to first template */
00090                 ct = td->characterTemplates[0];
00091         } else
00092             /* Only one template */
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     /* Abilities and skills -- random within the range */
00101     for (i = 0; i < SKILL_NUM_TYPES; i++) {
00102         const int abilityWindow = chrTemplate[i][1] - chrTemplate[i][0];
00103         /* Reminder: In case if abilityWindow==0 the ability will be set to the lower limit. */
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         /* Health. */
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     /* Morale */
00119     chr->morale = GET_MORALE(chr->score.skills[ABILITY_MIND]);
00120     if (chr->morale >= MAX_SKILL)
00121         chr->morale = MAX_SKILL;
00122 
00123     /* Initialize the experience values */
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     /* models of UGVs don't change - because they are already armoured */
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     /* models of UGVs don't change - because they are already armoured */
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 }

Generated by  doxygen 1.6.2