* Add a new resource type (for use with .wrf files): DBPROP which is similar to SPROP, with as difference that instead of a CSV file it specifies an SQLite database file to load from

* Add the code to load propulsions from the propulsion table of the given database file (function `loadPropulsionStatsFromDB`)
  * This code will make sure to load the propulsion stats-data in a similar manner (i.e. the resulting data in-memory should be the same) to the propulsion.txt loading code
 * Use this stats loading implementation on single player


git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@4444 4a71c877-e1ca-e34f-864e-861f7616d084
master
Giel van Schijndel 2008-03-31 14:05:57 +00:00
parent 4166f82efa
commit e2f81aaa54
4 changed files with 149 additions and 2 deletions

View File

@ -9,8 +9,8 @@ directory "stats-sql"
file DBWEAPON "stats.db" file DBWEAPON "stats.db"
file DBBODY "stats.db" file DBBODY "stats.db"
file DBBRAIN "stats.db" file DBBRAIN "stats.db"
file DBPROP "stats.db"
directory "stats" directory "stats"
file SPROP "propulsion.txt"
file SSENSOR "sensor.txt" file SSENSOR "sensor.txt"
file SECM "ecm.txt" file SECM "ecm.txt"
file SREPAIR "repair.txt" file SREPAIR "repair.txt"

View File

@ -195,6 +195,19 @@ static BOOL bufferSPROPLoad(const char *pBuffer, UDWORD size, void **ppData)
return true; return true;
} }
static BOOL dataDBPROPLoad(const char* filename, void **ppData)
{
if (!loadPropulsionStatsFromDB(filename)
|| !allocComponentList(COMP_PROPULSION, numPropulsionStats))
{
return false;
}
// not interested in this value
*ppData = NULL;
return true;
}
/* Load the Sensor stats */ /* Load the Sensor stats */
static BOOL bufferSSENSORLoad(const char *pBuffer, UDWORD size, void **ppData) static BOOL bufferSSENSORLoad(const char *pBuffer, UDWORD size, void **ppData)
{ {
@ -990,6 +1003,7 @@ static const RES_TYPE_MIN_FILE FileResourceTypes[] =
{"DBWEAPON", dataDBWEAPONLoad, NULL}, {"DBWEAPON", dataDBWEAPONLoad, NULL},
{"DBBODY", dataDBBODYLoad, dataReleaseStats}, {"DBBODY", dataDBBODYLoad, dataReleaseStats},
{"DBBRAIN", dataDBBRAINLoad, NULL}, {"DBBRAIN", dataDBBRAINLoad, NULL},
{"DBPROP", dataDBPROPLoad, NULL},
{"WAV", dataAudioLoad, (RES_FREE)sound_ReleaseTrack}, {"WAV", dataAudioLoad, (RES_FREE)sound_ReleaseTrack},
{"AUDIOCFG", dataAudioCfgLoad, NULL}, {"AUDIOCFG", dataAudioCfgLoad, NULL},
{"ANI", dataAnimLoad, dataAnimRelease}, {"ANI", dataAnimLoad, dataAnimRelease},

View File

@ -782,7 +782,6 @@ bool loadBrainStatsFromDB(const char* filename)
"FROM `brain`;", &stmt)) "FROM `brain`;", &stmt))
goto in_db_err; goto in_db_err;
while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) while ((rc = sqlite3_step(stmt)) == SQLITE_ROW)
{ {
BRAIN_STATS sStats, * const stats = &sStats; BRAIN_STATS sStats, * const stats = &sStats;
@ -858,3 +857,136 @@ in_db_err:
return retval; return retval;
} }
/** Load the propulsion stats from the given SQLite database file
* \param filename name of the database file to load the propulsion stats from.
*/
bool loadPropulsionStatsFromDB(const char* filename)
{
bool retval = false;
sqlite3* db;
sqlite3_stmt* stmt;
int rc;
if (!openDB(filename, &db))
goto in_db_err;
// Prepare this SQL statement for execution
if (!prepareStatement(db, "SELECT MAX(id) FROM `propulsion`;", &stmt))
goto in_db_err;
/* Execute and process the results of the above SQL statement to
* determine the amount of propulsions we're about to fetch. Then make
* sure to allocate memory for that amount of propulsions. */
rc = sqlite3_step(stmt);
if (rc != SQLITE_ROW
|| sqlite3_data_count(stmt) != 1
|| !statsAllocPropulsion(sqlite3_column_int(stmt, 0)))
{
goto in_statement_err;
}
sqlite3_finalize(stmt);
if (!prepareStatement(db, "SELECT `id`,"
"`name`,"
"`techlevel`,"
"`buildPower`,"
"`buildPoints`,"
"`weight`,"
"`hitpoints`,"
"`systempoints`,"
"`body`,"
"`GfxFile`,"
"`type`,"
"`maxSpeed`,"
"`designable`"
"FROM `propulsion`;", &stmt))
goto in_db_err;
while ((rc = sqlite3_step(stmt)) == SQLITE_ROW)
{
PROPULSION_STATS sStats, * const stats = &sStats;
unsigned int colnum = 0;
const unsigned int propulsion_id = sqlite3_column_int(stmt, colnum++);
memset(stats, 0, sizeof(*stats));
stats->ref = REF_PROPULSION_START + propulsion_id - 1;
// name TEXT NOT NULL, -- Text id name (short language independant name)
if (!allocateStatName((BASE_STATS *)stats, (const char*)sqlite3_column_text(stmt, colnum++)))
{
goto in_statement_err;
}
// techlevel TEXT NOT NULL, -- Technology level of this component
if (!setTechLevel((BASE_STATS *)stats, (const char*)sqlite3_column_text(stmt, colnum++)))
{
goto in_statement_err;
}
// buildPower NUMERIC NOT NULL, -- Power required to build this component
stats->buildPower = sqlite3_column_double(stmt, colnum++);
// buildPoints NUMERIC NOT NULL, -- Time required to build this component
stats->buildPoints = sqlite3_column_double(stmt, colnum++);
// weight NUMERIC NOT NULL, -- Component's weight (mass?)
stats->weight = sqlite3_column_double(stmt, colnum++);
// hitpoints NUMERIC NOT NULL, -- Component's hitpoints - SEEMS TO BE UNUSED
stats->hitPoints = sqlite3_column_double(stmt, colnum++);
// systempoints NUMERIC NOT NULL, -- Space the component takes in the droid - SEEMS TO BE UNUSED
stats->systemPoints = sqlite3_column_double(stmt, colnum++);
// body NUMERIC NOT NULL, -- Component's body points
stats->body = sqlite3_column_double(stmt, colnum++);
// Get the IMD for the component
// GfxFile TEXT, -- The IMD to draw for this component
if (sqlite3_column_type(stmt, colnum) != SQLITE_NULL)
{
stats->pIMD = (iIMDShape *) resGetData("IMD", (const char*)sqlite3_column_text(stmt, colnum++));
if (stats->pIMD == NULL)
{
debug(LOG_ERROR, "Cannot find the propulsion PIE for record %s", getStatName(stats));
abort();
goto in_statement_err;
}
}
else
{
stats->pIMD = NULL;
++colnum;
}
// type TEXT NOT NULL, -- Type of propulsion
stats->propulsionType = getPropulsionType((const char*)sqlite3_column_text(stmt, colnum++));
if (stats->propulsionType == INVALID_PROP_TYPE)
{
debug(LOG_ERROR, "loadPropulsionStatsFromDB: Invalid Propulsion type for %s", getStatName(stats));
abort();
goto in_statement_err;
}
// maxSpeed NUMERIC NOT NULL, -- Max speed for droids with this propulsion
stats->maxSpeed = sqlite3_column_double(stmt, colnum++);
// designable NUMERIC NOT NULL -- flag to indicate whether this component can be used in the design screen
stats->design = sqlite3_column_int(stmt, colnum++) ? true : false;
// set the max stats values for the design screen
if (stats->design)
{
setMaxPropulsionSpeed(stats->maxSpeed);
//setMaxComponentWeight(stats->weight);
}
//save the stats
statsSetPropulsion(stats, propulsion_id - 1);
}
retval = true;
in_statement_err:
sqlite3_finalize(stmt);
in_db_err:
sqlite3_close(db);
return retval;
}

View File

@ -30,5 +30,6 @@
extern bool loadWeaponStatsFromDB(const char* filename); extern bool loadWeaponStatsFromDB(const char* filename);
extern bool loadBodyStatsFromDB(const char* filename); extern bool loadBodyStatsFromDB(const char* filename);
extern bool loadBrainStatsFromDB(const char* filename); extern bool loadBrainStatsFromDB(const char* filename);
extern bool loadPropulsionStatsFromDB(const char* filename);
#endif // __INCLUDED_STATS_DB_H__ #endif // __INCLUDED_STATS_DB_H__