Some script related cleanup.

master
Per Inge Mathisen 2011-04-25 15:16:49 +02:00
parent 86a92ed314
commit 9be9b6bc2a
7 changed files with 44 additions and 53 deletions

View File

@ -33,6 +33,7 @@
#endif
#include "lib/framework/wzapp.h"
#include "lib/netplay/netplay.h"
#include "lib/ivis_opengl/bitimage.h"
#include "lib/ivis_opengl/pieblitfunc.h"
#include "lib/widget/button.h"
@ -44,6 +45,7 @@
#include "loadsave.h"
#include "multiplay.h"
#include "scores.h"
#include "mission.h"
#define totalslots 36 // challenge slots
#define slotsInColumn 12 // # of slots in a column
@ -85,6 +87,41 @@ static void displayLoadBanner(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset,
pie_BoxFill(x + 2, y + 2, x + psWidget->width - 2, y + psWidget->height - 2, WZCOL_MENU_BACKGROUND);
}
// quite the hack, game name is stored in global sRequestResult
void updateChallenge(bool gameWon)
{
char sPath[64], *fStr;
int seconds = 0, newtime = (gameTime - mission.startTime) / GAME_TICKS_PER_SEC;
bool victory = false;
WzConfig scores(CHALLENGE_SCORES);
fStr = strrchr(sRequestResult, '/');
fStr++; // skip slash
if (fStr == '\0')
{
debug(LOG_ERROR, "Bad path to challenge file (%s)", sRequestResult);
return;
}
sstrcpy(sPath, fStr);
sPath[strlen(sPath) - 4] = '\0'; // remove .ini
scores.beginGroup(sPath);
victory = scores.value("Victory", false).toBool();
seconds = scores.value("Seconds", 0).toInt();
// Update score if we have a victory and best recorded was a loss,
// or both were losses but time is higher, or both were victories
// but time is lower.
if ((!victory && gameWon)
|| (!gameWon && !victory && newtime > seconds)
|| (gameWon && victory && newtime < seconds))
{
scores.setValue("Seconds", newtime);
scores.setValue("Victory", gameWon);
scores.setValue("Player", NetPlay.players[selectedPlayer].name);
}
scores.endGroup();
}
// ////////////////////////////////////////////////////////////////////////////
static void displayLoadSlot(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, WZ_DECL_UNUSED PIELIGHT *pColours)
{

View File

@ -27,6 +27,7 @@ bool addChallenges(void);
bool closeChallenges(void);
bool runChallenges(void);
bool displayChallenges(void);
void updateChallenge(bool gameWon);
extern bool challengesUp;
extern bool challengeActive;

View File

@ -677,7 +677,7 @@ bool loadResearchArtefacts(const char *pArteData, UDWORD bufferSize, UDWORD list
//get the type for comparison later
newType = statType(pArtefact->ref);
pResearch = getResearch(ResearchName, false);
pResearch = getResearch(ResearchName);
if (pResearch == NULL)
{
return false;
@ -2371,7 +2371,7 @@ COMPONENT_STATS * getComponentDetails(char *pName, char *pCompName)
}
//return a pointer to a research topic based on the name
RESEARCH * getResearch(const char *pName, bool resName)
RESEARCH *getResearch(const char *pName)
{
unsigned int inc = 0;

View File

@ -111,7 +111,7 @@ extern bool ResearchShutDown(void);
extern void ResearchRelease(void);
/* For a given view data get the research this is related to */
extern RESEARCH * getResearch(const char *pName, bool resName);
extern RESEARCH * getResearch(const char *pName);
/* sets the status of the topic to cancelled and stores the current research
points accquired */

View File

@ -2297,7 +2297,6 @@ bool scrStructureComplete(void)
/*looks to see if a structure (specified by type) exists and built*/
bool scrStructureBuilt(void)
{
// INTERP_VAL sVal;
UDWORD structInc;
STRUCTURE_STATS *psStats;
SDWORD player;
@ -2308,18 +2307,6 @@ bool scrStructureBuilt(void)
return false;
}
/* if (!stackPop(&sVal))
{
return false;
}
if (sVal.type != ST_STRUCTURESTAT)
{
ASSERT( false, "scrStructureBuilt: type mismatch for object" );
return false;
}
psStats = (STRUCTURE_STATS *)(asStructureStats + sVal.v.ival);
*/
if (player >= MAX_PLAYERS)
{
ASSERT( false, "scrStructureBuilt:player number is too high" );
@ -2348,7 +2335,6 @@ bool scrStructureBuilt(void)
bool scrCentreView(void)
{
BASE_OBJECT *psObj;
// INTERP_VAL sVal;
if (!stackPopParams(1, ST_BASEOBJECT, &psObj))
{
@ -3268,14 +3254,12 @@ bool scrGameOverMessage(void)
SDWORD player;
VIEWDATA *psViewData;
if (!stackPopParams(4, ST_INTMESSAGE, &psViewData , VAL_INT, &msgType,
VAL_INT, &player, VAL_BOOL, &gameWon))
{
return false;
}
if (player >= MAX_PLAYERS)
{
ASSERT( false, "scrGameOverMessage:player number is too high" );
@ -3314,44 +3298,13 @@ bool scrGameOverMessage(void)
if (challengeActive)
{
char sPath[64], *fStr;
int seconds = 0, newtime = (gameTime - mission.startTime) / GAME_TICKS_PER_SEC;
bool victory = false;
WzConfig scores(CHALLENGE_SCORES);
fStr = strrchr(sRequestResult, '/');
fStr++; // skip slash
if (fStr == '\0')
{
debug(LOG_ERROR, "Bad path to challenge file (%s)", sRequestResult);
return true;
}
sstrcpy(sPath, fStr);
sPath[strlen(sPath) - 4] = '\0'; // remove .ini
scores.beginGroup(sPath);
victory = scores.value("Victory", false).toBool();
seconds = scores.value("Seconds", 0).toInt();
// Update score if we have a victory and best recorded was a loss,
// or both were losses but time is higher, or both were victories
// but time is lower.
if ((!victory && gameWon)
|| (!gameWon && !victory && newtime > seconds)
|| (gameWon && victory && newtime < seconds))
{
scores.setValue("Seconds", newtime);
scores.setValue("Victory", gameWon);
scores.setValue("Player", NetPlay.players[selectedPlayer].name);
}
scores.endGroup();
updateChallenge(gameWon);
}
return true;
}
// -----------------------------------------------------------------------------------------
//function to call when the game is over
bool scrGameOver(void)

View File

@ -1248,7 +1248,7 @@ bool scrValDefLoad(SDWORD version, INTERP_VAL *psVal, char *pBuffer, UDWORD size
}
else
{
psVal->v.oval = (void*)getResearch(pBuffer, true);
psVal->v.oval = (void*)getResearch(pBuffer);
if (psVal->v.oval == NULL)
{
debug( LOG_FATAL, "scrValDefLoad: couldn't find research %s", pBuffer );

View File

@ -698,7 +698,7 @@ var_init: var_entry TYPE var_value
yyerror("Typemismatch for variable %d", $1);
YYABORT;
}
data.v.oval = getResearch($3.pString, true); /* store pointer */
data.v.oval = getResearch($3.pString); /* store pointer */
if (data.v.oval == NULL)
{
yyerror("Research %s not found", $3.pString);