2019-06-17 10:30:02 +02:00
|
|
|
#include "common.h"
|
2020-04-17 15:31:11 +02:00
|
|
|
|
2019-10-30 00:12:58 +01:00
|
|
|
#include "General.h"
|
2019-06-19 16:55:01 +02:00
|
|
|
#include "FileMgr.h"
|
2019-06-17 10:30:02 +02:00
|
|
|
#include "PedStats.h"
|
|
|
|
|
2020-10-09 11:02:21 +02:00
|
|
|
// --MIAMI: file done
|
|
|
|
|
2020-03-17 19:03:13 +01:00
|
|
|
CPedStats *CPedStats::ms_apPedStats[NUM_PEDSTATS];
|
2019-06-19 16:55:01 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
CPedStats::Initialise(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
debug("Initialising CPedStats...\n");
|
|
|
|
for(i = 0; i < NUM_PEDSTATS; i++){
|
2019-06-19 18:35:51 +02:00
|
|
|
ms_apPedStats[i] = new CPedStats;
|
2019-06-19 16:55:01 +02:00
|
|
|
ms_apPedStats[i]->m_type = PEDSTAT_PLAYER;
|
|
|
|
ms_apPedStats[i]->m_name[8] = 'R'; // WHAT?
|
|
|
|
ms_apPedStats[i]->m_fleeDistance = 20.0f;
|
|
|
|
ms_apPedStats[i]->m_headingChangeRate = 15.0f;
|
|
|
|
ms_apPedStats[i]->m_fear = 50;
|
|
|
|
ms_apPedStats[i]->m_temper = 50;
|
|
|
|
ms_apPedStats[i]->m_lawfulness = 50;
|
|
|
|
ms_apPedStats[i]->m_sexiness = 50;
|
|
|
|
ms_apPedStats[i]->m_attackStrength = 1.0f;
|
|
|
|
ms_apPedStats[i]->m_defendWeakness = 1.0f;
|
|
|
|
ms_apPedStats[i]->m_flags = 0;
|
|
|
|
}
|
|
|
|
debug("Loading pedstats data...\n");
|
|
|
|
CPedStats::LoadPedStats();
|
|
|
|
debug("CPedStats ready\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CPedStats::Shutdown(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
debug("Shutting down CPedStats...\n");
|
|
|
|
for(i = 0; i < NUM_PEDSTATS; i++)
|
|
|
|
delete ms_apPedStats[i];
|
|
|
|
debug("CPedStats shut down\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CPedStats::LoadPedStats(void)
|
|
|
|
{
|
|
|
|
char *buf;
|
|
|
|
char line[256];
|
|
|
|
char name[32];
|
2020-07-22 13:56:28 +02:00
|
|
|
size_t bp, buflen;
|
2019-06-19 16:55:01 +02:00
|
|
|
int lp, linelen;
|
|
|
|
int type;
|
|
|
|
float fleeDist, headingChangeRate, attackStrength, defendWeakness;
|
|
|
|
int fear, temper, lawfullness, sexiness, flags;
|
|
|
|
|
|
|
|
|
|
|
|
type = 0;
|
|
|
|
buf = new char[16 * 1024];
|
|
|
|
|
|
|
|
CFileMgr::SetDir("DATA");
|
|
|
|
buflen = CFileMgr::LoadFile("PEDSTATS.DAT", (uint8*)buf, 16 * 1024, "r");
|
|
|
|
CFileMgr::SetDir("");
|
|
|
|
|
|
|
|
for(bp = 0; bp < buflen; ){
|
|
|
|
// read file line by line
|
|
|
|
for(linelen = 0; buf[bp] != '\n' && bp < buflen; bp++){
|
|
|
|
if(buf[bp] == '\r' || buf[bp] == ',' || buf[bp] == '\t')
|
|
|
|
line[linelen++] = ' ';
|
|
|
|
else
|
|
|
|
line[linelen++] = buf[bp];
|
|
|
|
}
|
|
|
|
bp++;
|
2020-03-17 19:03:13 +01:00
|
|
|
line[linelen] = '\0';
|
2019-06-19 16:55:01 +02:00
|
|
|
|
|
|
|
// skip white space
|
|
|
|
for(lp = 0; line[lp] <= ' '; lp++);
|
|
|
|
|
|
|
|
if(lp >= linelen || // FIX: game uses == here, but this is safer if we have empty lines
|
|
|
|
line[lp] == '#')
|
|
|
|
continue;
|
|
|
|
|
|
|
|
sscanf(&line[lp], "%s %f %f %d %d %d %d %f %f %d",
|
|
|
|
name,
|
|
|
|
&fleeDist,
|
|
|
|
&headingChangeRate,
|
|
|
|
&fear,
|
|
|
|
&temper,
|
|
|
|
&lawfullness,
|
|
|
|
&sexiness,
|
|
|
|
&attackStrength,
|
|
|
|
&defendWeakness,
|
|
|
|
&flags);
|
|
|
|
ms_apPedStats[type]->m_type = (ePedStats)type;
|
|
|
|
strncpy(ms_apPedStats[type]->m_name, name, 24); // FIX: game uses strcpy
|
|
|
|
ms_apPedStats[type]->m_fleeDistance = fleeDist;
|
|
|
|
ms_apPedStats[type]->m_headingChangeRate = headingChangeRate;
|
|
|
|
ms_apPedStats[type]->m_fear = fear;
|
|
|
|
ms_apPedStats[type]->m_temper = temper;
|
|
|
|
ms_apPedStats[type]->m_lawfulness = lawfullness;
|
|
|
|
ms_apPedStats[type]->m_sexiness = sexiness;
|
|
|
|
ms_apPedStats[type]->m_attackStrength = attackStrength;
|
|
|
|
ms_apPedStats[type]->m_defendWeakness = defendWeakness;
|
|
|
|
ms_apPedStats[type]->m_flags = flags;
|
|
|
|
type++;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete[] buf;
|
|
|
|
}
|
|
|
|
|
2020-03-17 19:03:13 +01:00
|
|
|
ePedStats
|
2019-06-19 16:55:01 +02:00
|
|
|
CPedStats::GetPedStatType(char *name)
|
|
|
|
{
|
2020-03-17 19:03:13 +01:00
|
|
|
for(uint16 type = 0; type < NUM_PEDSTATS; type++)
|
2019-10-30 00:12:58 +01:00
|
|
|
if(!CGeneral::faststrcmp(ms_apPedStats[type]->m_name, name))
|
2020-03-17 19:03:13 +01:00
|
|
|
return (ePedStats) type;
|
|
|
|
|
2019-06-19 16:55:01 +02:00
|
|
|
return NUM_PEDSTATS;
|
|
|
|
}
|