Exemplo n.º 1
0
void tmSetDialog(sdword phrasenum, char *sentence)
{
    if (tmKASDialog[phrasenum])
    {
        memFree(tmKASDialog[phrasenum]);
        tmKASDialog[phrasenum] = NULL;
    }
    tmKASDialog[phrasenum] = memStringDupe(sentence);
}
Exemplo n.º 2
0
/*-----------------------------------------------------------------------------
    Name        : spTitleFind
    Description : Finds the title of a mission file (on first line, in brackets)
    Inputs      : directory, fileName - combine to form path to the file.
    Outputs     : Allocated memory for and duplicates a string.
    Return      : Pointer to title string.
----------------------------------------------------------------------------*/
char *spTitleFind(char *directory, char *fileName)
{
    char string[256], fullName[_MAX_PATH];
    filehandle handle;
    sdword status;

    memStrncpy(fullName, directory, _MAX_PATH - 1);
    strcat(fullName, fileName);
    strcat(fullName,"\\");
    strcat(fullName, fileName);
    strcat(fullName,".level");
    handle = fileOpen(fullName, FF_TextMode|FF_ReturnNULLOnFail);
    if (!handle)
    {
        return NULL;
    }

    for (;;)
    {
        status = fileLineRead(handle,string,256);

        if (status == FR_EndOfFile)
        {
            break;
        }

        if ((string[0] == '\n') || (string[0] == '/') || (string[0] == ';') || (string[0] == ' '))
        {
            continue;
        }

        if (strlen(string) >= 3 && *string == '[' && string[strlen(string) - 1] == ']')
        {
            fileClose(handle);
            string[strlen(string) - 1] = 0;
            return(memStringDupe(&string[1]));
        }
    }

    fileClose(handle);

    return memStringDupe(fullName);
}
Exemplo n.º 3
0
/*-----------------------------------------------------------------------------
    Name        : spMissionDescriptionSet
    Description : Script-parse callback for setting description text
    Inputs      :
    Outputs     :
    Return      :
----------------------------------------------------------------------------*/
static void spMissionDescriptionSet(char *directory,char *field,void *dataToFillIn)
{
    if (spDescription == NULL)
    {
        spDescription = memStringDupe(field);
    }
    else
    {
        spDescription = memRealloc(spDescription, strlen(spDescription) + strlen(field) + 3, "DescriptionString", 0);
        strcat(spDescription, "\\n");                       //auto-newline
        strcat(spDescription, field);
    }
}
Exemplo n.º 4
0
/*-----------------------------------------------------------------------------
    Name        : frReloadFonts
    Description : reloads all of the currently loaded fonts with respect to the currently selected language.
    Inputs      : none
    Outputs     : none
    Return      : void
----------------------------------------------------------------------------*/
void frReloadFonts(void)
{
    sdword index;
    fonthandle curfont;
    char   name[64];
    char fullName[128];

    curfont = fontCurrentGet();

    for (index = FR_NumberFonts - 1; index >= 1; index--)
    {                                                       //for all of the registry
        if (frFontRegistry[index].name != NULL)
        {
            // free memory associated with the current font
            strcpy(name, frFontRegistry[index].name);
            memFree(frFontRegistry[index].name);            //free previously allocated name
            frFontRegistry[index].name = NULL;              //no longer registered
            fontDiscard(frFontRegistry[index].handle);      //free the font

            frFontRegistry[index].name = memStringDupe(name);//duplicate name string
            strcpy(fullName, FR_PrependPath);                       //prepare file path
            if (strCurLanguage==languageEnglish)
            {
                strcat(fullName, FR_English);
            }
            else if (strCurLanguage==languageFrench)
            {
                strcat(fullName, FR_French);
            }
            else if (strCurLanguage==languageGerman)
            {
                strcat(fullName, FR_German);
            }
            else if (strCurLanguage==languageSpanish)
            {
                strcat(fullName, FR_Spanish);
            }
            else if (strCurLanguage==languageItalian)
            {
                strcat(fullName, FR_Italian);
            }
            strcat(fullName, name);
            frFontRegistry[index].fontdat = fontLoad(fullName);  //load file
            frFontRegistry[index].handle = index;
        }
    }

    fontMakeCurrent(curfont);
}
Exemplo n.º 5
0
lodinfo *lodTableReadScript(char *directory, char *fileName)
{
    lodinfo *info;
    sdword index;

    for (index = 0; index < LOD_NumberLevels; index++)
    {                                                       //initialize the lodmaxinfo structure
        lodMaxInfo.level[index].flags = LT_Invalid;
        lodMaxInfo.level[index].pData = NULL;
    }

    trBaseColorScalar = trStripeColorScalar = 0.0f;
    scriptSetStruct(directory, fileName, lodScriptTable, (ubyte *)&lodMaxInfo);//read the script file
    trBaseColorScalar = trStripeColorScalar = 0.0f;

    for (index = 0; index < LOD_NumberLevels; index++)
    {
        if ((lodMaxInfo.level[index].flags & LM_LODType) == LT_Invalid)
        {
            break;
        }
        if ((lodMaxInfo.level[index].flags & LM_LODType) == LT_Mesh)
        {                                                   //if it's a mesh
            lodMaxInfo.level[index].hBindings =                //create a bindings list
                meshBindingListCreate((meshdata *)lodMaxInfo.level[index].pData);
        }
        else
        {
            lodMaxInfo.level[index].hBindings = NULL;
        }
    }
    info = memAlloc(lodTableSize(index), "LOD Table", NonVolatile); //allocate the table
    memcpy(info, &lodMaxInfo, lodTableSize(index));            //and copy over the max table
    info->nLevels = index;                                  //store number of levels
#if LOD_AUTO_SAVE
    {
        char partialName[_MAX_PATH];
        char *fullName;
        sprintf(partialName, "%s%s", directory, fileName);
        fullName = filePathPrepend(partialName, 0);
        info->fileName = memStringDupe(fullName);           //store full path to file for saving
    }
#endif
    return(info);
}
Exemplo n.º 6
0
/*-----------------------------------------------------------------------------
    Name        : spTitleListLoad
    Description : Scans the missions directory and loads in the titles of all
                    the mission files available.
    Inputs      : void
    Outputs     : Fills in spScenarios and spNumberScenarios
    Return      : void
----------------------------------------------------------------------------*/
void spTitleListLoad(void)
{
#if !(defined(CGW) || defined (Downloadable) || defined(DLPublicBeta) || defined(OEM))
    struct _finddata_t find;
    sdword handle, startHandle;
#endif
    sdword index, numplayers;
    char fileName[_MAX_PATH], nameBuffer[_MAX_PATH];
#if MAIN_Password
    char upperNameBuffer[_MAX_PATH];
#endif
    char bitmapfileName[_MAX_PATH];
    char *pString;
    char *title;
    filehandle scriptFile;

#if defined(CGW) || defined(Downloadable) || defined(DLPublicBeta)
    scriptFile = fileOpen("DemoMissions.script", FF_TextMode);
#else
    //oem has all missions!
    scriptFile = fileOpen("multiPlayerMissions.script", FF_TextMode);
#endif
    dbgAssert(scriptFile != 0);

    while (fileLineRead(scriptFile, nameBuffer, _MAX_PATH) != FR_EndOfFile)
    {
        if (nameBuffer[0] == ';' || (nameBuffer[0] == '/' && nameBuffer[1] == '/'))
        {
            continue;
        }
        numplayers = 0;
        for (pString = nameBuffer; *pString != 0; pString++)
        {                                                   //search for a numeral character
            if (strchr("0123456789", *pString) != NULL)
            {                                               //if this is a numeral
                numplayers = atoi(pString);
                memset(fileName, 0, _MAX_PATH);
                memStrncpy(fileName, nameBuffer, pString - nameBuffer + 1);//copy the start of the string
                memStrncpy(bitmapfileName, nameBuffer, pString - nameBuffer + 1);//copy the start of the string
                strcat(fileName, "%d");                     //make something like:
                strcat(fileName, pString + 1);              //'StdGame%d.level'
            }
        }

        if (numplayers == 0)
        {
            goto alreadyLoaded;
        }

        title = spTitleFind("MultiPlayer\\", nameBuffer);
        if (title == NULL)
        {
            goto alreadyLoaded;                             //break-continue
        }
#if MAIN_Password
        if (!mainEnableSpecialMissions)
        {                                                   //if this is an "off-limits" mission
            strcpy(upperNameBuffer, title);
            _strupr(upperNameBuffer);
            if (strstr(upperNameBuffer, "ALL"))
            {
                memFree(title);
                goto alreadyLoaded;                         //break-continue
            }
        }
#endif //MAIN_Password

        for (index = 0; index < spNumberScenarios; index++)
        {
            if (!_stricmp(spScenarios[index].fileSpec, fileName))
            {                                               //if matching file specs,
                // matches, but we should update max number of player if necessary
                if (numplayers > spScenarios[index].maxplayers) spScenarios[index].maxplayers = numplayers;
                if (numplayers < spScenarios[index].minplayers) spScenarios[index].minplayers = numplayers;
                memFree(title);
                goto alreadyLoaded;                         //break-continue
            }
        }

        if (spNumberScenarios >= spScenarioListLength)
        {
            spScenarioListLength += SP_ScenarioListGrowth;
            spScenarios = memRealloc(spScenarios, spScenarioListLength * sizeof(spscenario), "spScenarios", NonVolatile);
        }
        dbgAssert(spNumberScenarios < spScenarioListLength);
        spScenarios[spNumberScenarios].fileSpec = memStringDupe(fileName);
        spScenarios[spNumberScenarios].bitmapfileSpec = memStringDupe(bitmapfileName);
        spScenarios[spNumberScenarios].title = title;
        spScenarios[spNumberScenarios].maxplayers = numplayers;
        spScenarios[spNumberScenarios].minplayers = numplayers;
        spNumberScenarios++;

alreadyLoaded:;
    }
    fileClose(scriptFile);

#if !(defined(CGW) || defined (Downloadable) || defined(DLPublicBeta) || defined(OEM))
    startHandle = handle = _findfirst(filePathPrepend("MultiPlayer\\*.", 0), &find);

    while (handle != -1)
    {
        if (find.name[0] == '.')
        {
            goto alreadyLoadedFromFileSystem;
        }
        fileName[0] = 0;
        numplayers = 0;
        for (pString = find.name; *pString != 0; pString++)
        {                                                   //search for a numeral character
            if (strchr("0123456789", *pString) != NULL)
            {                                               //if this is a numeral
                numplayers = atoi(pString);
                memset(fileName, 0, _MAX_PATH);
                strncpy(fileName, find.name, pString - find.name);//copy the start of the string
                memStrncpy(bitmapfileName, find.name, pString - find.name + 1);//copy the start of the string
                strcat(fileName, "%d");                     //make something like:
                strcat(fileName, pString + 1);              //'StdGame%d.level'
            }
        }
        if (numplayers == 0)
        {
            goto alreadyLoadedFromFileSystem;
        }

        if (fileName[0] == 0)
        {
            goto alreadyLoadedFromFileSystem;
        }

        title = spTitleFind("MultiPlayer\\", find.name);
        if (title == NULL)
        {
            goto alreadyLoadedFromFileSystem;
        }
#if MAIN_Password
        if (!mainEnableSpecialMissions)
        {                                                   //if this is an "off-limits" mission
            strcpy(upperNameBuffer, title);
            _strupr(upperNameBuffer);
            if (strstr(upperNameBuffer, "ALL"))
            {
                memFree(title);
                goto alreadyLoadedFromFileSystem;           //break-continue
            }
        }
#endif //MAIN_Password

        for (index = 0; index < spNumberScenarios; index++)
        {
            if (!_stricmp(spScenarios[index].fileSpec, fileName))
            {                                               //if matching file specs,
                // matches, but we should update max number of player if necessary
                if (numplayers > spScenarios[index].maxplayers) spScenarios[index].maxplayers = numplayers;
                if (numplayers < spScenarios[index].minplayers) spScenarios[index].minplayers = numplayers;
                memFree(title);
                goto alreadyLoadedFromFileSystem;                         //break-continue
            }
        }

        if (spNumberScenarios >= spScenarioListLength)
        {
            spScenarioListLength += SP_ScenarioListGrowth;
            spScenarios = memRealloc(spScenarios, spScenarioListLength * sizeof(spscenario), "spScenarios", NonVolatile);
        }
        dbgAssert(spNumberScenarios < spScenarioListLength);
        spScenarios[spNumberScenarios].fileSpec = memStringDupe(fileName);
        spScenarios[spNumberScenarios].bitmapfileSpec = memStringDupe(bitmapfileName);
        spScenarios[spNumberScenarios].title = title;
        spScenarios[spNumberScenarios].maxplayers = numplayers;
        spScenarios[spNumberScenarios].minplayers = numplayers;
        spNumberScenarios++;

alreadyLoadedFromFileSystem:;
        handle = _findnext(startHandle, &find);
    }
#endif //defined(CGW) || defined (Downloadable) || defined(DLPublicBeta) || defined(OEM)

    dbgAssert(spNumberScenarios > 0);
    if (spNumberScenarios > 1)
    {
        //alphabetically sort the scenario list
        qsort(&spScenarios[0],spNumberScenarios,sizeof(spscenario),compareScenariosCB);
    }

    //find the default scenario's index
    if (spCurrentSelected == 0)
    {                                                       //if it's not already selected
        spCurrentSelected = spScenarioFind(DefaultScenario);
    }
}
Exemplo n.º 7
0
/*-----------------------------------------------------------------------------
    Name        : gpTitleListLoad
    Description : Scans the games directory and loads in the titles of all
                    the game files available.
    Inputs      : void
    Outputs     : Fills in gpGames and gpNumberGames
    Return      : void
----------------------------------------------------------------------------*/
void gpTitleListLoad(void)
{
#ifdef _WIN32
    struct _finddata_t find;
    sdword handle, startHandle;
#else
    DIR* dp;
    struct dirent* dir_entry;
#endif
    sdword index;
    char fileName[PATH_MAX]   = "";
    char fileSearch[PATH_MAX] = "";
//    char *pString;
//    char *title;

    for (index = 0; index < gpNumberGames; index++)
    {
        memFree(gpGames[index].fileSpec);
        memFree(gpGames[index].title);
    }
    if (gpNumberGames > 0)
    {
        memFree(gpGames);
        gpGames = NULL;
        gpNumberGames = 0;
    }

    strcpy(fileSearch,SavedGamesPath);
#ifdef _WIN32
    strcat(fileSearch,"*.*");

    startHandle = handle = _findfirst(filePathPrepend(fileSearch, FF_UserSettingsPath), &find);

    while (handle != -1)
    {
        if (find.name[0] == '.')
        {
            goto alreadyLoaded;
        }
        fileName[0] = 0;

        strcpy(fileName, find.name);

        if (fileName[0] == 0)
        {
            goto alreadyLoaded;
        }

        if (strstr(fileName,PKTS_EXTENSION))
        {
            goto alreadyLoaded;
        }

        for (index = 0; index < gpNumberGames; index++)
        {
            if (!strcasecmp(gpGames[index].fileSpec, fileName))
            {                                               //if matching file specs,
                goto alreadyLoaded;                         //break-continue
            }
        }

        gpGames = memRealloc(gpGames, (gpNumberGames+1) * sizeof(gpgame), "gpGames", NonVolatile);

        gpGames[gpNumberGames].fileSpec = memStringDupe(fileName);
        //gpGames[gpNumberGames].title = title;
        gpGames[gpNumberGames].title = memStringDupe(fileName);

        gpNumberGames++;
alreadyLoaded:;
        handle = _findnext(startHandle, &find);
    }
#else
    dp = opendir(filePathPrepend(fileSearch, FF_UserSettingsPath));

    if (dp)
    {
        while ((dir_entry = readdir(dp)))
        {
            if (dir_entry->d_name[0] == '.')
                continue;
            fileName[0] = 0;

            strcpy(fileName, dir_entry->d_name);

            if (fileName[0] == 0)
                continue;

            if (strstr(fileName,PKTS_EXTENSION))
                continue;

            for (index = 0; index < gpNumberGames; index++)
            {
                if (!strcasecmp(gpGames[index].fileSpec, fileName))
                {                                               /*if matching file specs,*/
                    break;                                      /*break-continue*/
                }
            }
            if (index < gpNumberGames)
                continue;

            gpGames = memRealloc(gpGames, (gpNumberGames+1) * sizeof(gpgame), "gpGames", NonVolatile);

            gpGames[gpNumberGames].fileSpec = memStringDupe(fileName);
            //gpGames[gpNumberGames].title = title;
            gpGames[gpNumberGames].title = memStringDupe(fileName);

            gpNumberGames++;
        }

        closedir(dp);
    }
#endif

    if (gpNumberGames > 1)
    {
        //alphabetically sort the game list
        qsort(&gpGames[0],gpNumberGames,sizeof(gpgame),compareGamesCB);
    }
    gpCurrentSelected = gpCurrentGame = 0;      //set default game
}
Exemplo n.º 8
0
/*-----------------------------------------------------------------------------
    Name        : frFontRegister
    Description : Register usage of a font, loading it if needed
    Inputs      :
    Outputs     :
    Return      :
----------------------------------------------------------------------------*/
fonthandle frFontRegister(char *fileName)
{
    sdword index, freeIndex = -1;
    char fullName[80];

    for (index = FR_NumberFonts - 1; index >= 1; index--)
    {                                                       //for all of the registry
        if (frFontRegistry[index].name == NULL)
        {                                                   //if this one free
            freeIndex = index;
        }
        else
        {
            if (frNamesCompare(fileName, frFontRegistry[index].name))
            {                                               //if this is the font you want
#if FR_VERBOSE_LEVEL >= 2
            dbgMessagef("frFontRegister: Returning pre-registered font %s with usage count of %d",
                        frFontRegistry[index].name, frFontRegistry[index].nUsageCount);
#endif
                frFontRegistry[index].nUsageCount++;        //increment usage count
                return(index);       //return pre-loaded handle
            }
        }
    }
#if FR_ERROR_CHECKING
    if (freeIndex == -1)
    {
        dbgFatalf(DBG_Loc, "Font registry not big enough for %s, only %d long", fileName, FR_NumberFonts);
    }
#endif
#if FR_VERBOSE_LEVEL >= 1
    dbgMessagef("frFontRegister: Font %s not pre-registered, loading now...", fileName);
#endif
    frFontRegistry[freeIndex].name = memStringDupe(fileName);//duplicate name string
    frFontRegistry[freeIndex].nUsageCount = 1;              //start usage count at 1
    strcpy(fullName, FR_PrependPath);                       //prepare file path
    if (strCurLanguage==languageEnglish)
    {
        strcat(fullName, FR_English);
    }
    else if (strCurLanguage==languageFrench)
    {
        strcat(fullName, FR_French);
    }
    else if (strCurLanguage==languageGerman)
    {
        strcat(fullName, FR_German);
    }
    else if (strCurLanguage==languageSpanish)
    {
        strcat(fullName, FR_Spanish);
    }
    else if (strCurLanguage==languageItalian)
    {
        strcat(fullName, FR_Italian);
    }
    strcat(fullName, fileName);
    frFontRegistry[freeIndex].fontdat = fontLoad(fullName);  //load file
    frFontRegistry[freeIndex].handle = freeIndex;
    return(freeIndex);
}
Exemplo n.º 9
0
/*-----------------------------------------------------------------------------
    Name        : strSetStringCB
    Description : Set String call back for setscript
    Inputs      : directory, field, where to stick it
    Outputs     : none
    Return      : none
----------------------------------------------------------------------------*/
void strSetStringCB(char *directory,char *field,void **dataToFillIn)
{
    *dataToFillIn = (void *)memStringDupe(field);
    *dataToFillIn = strParseString(*dataToFillIn);
}
Exemplo n.º 10
0
/*-----------------------------------------------------------------------------
    Name        : gpTitleListLoad
    Description : Scans the games directory and loads in the titles of all
                    the game files available.
    Inputs      : void
    Outputs     : Fills in gpGames and gpNumberGames
    Return      : void
----------------------------------------------------------------------------*/
void gpTitleListLoad(void)
{
    struct _finddata_t find;
    sdword handle, startHandle;
    sdword index;
    char fileName[_MAX_PATH];
    char fileSearch[100];
//    char *pString;
//    char *title;

    for (index = 0; index < gpNumberGames; index++)
    {
        memFree(gpGames[index].fileSpec);
        memFree(gpGames[index].title);
    }
    if (gpNumberGames > 0)
    {
        memFree(gpGames);
        gpGames = NULL;
        gpNumberGames = 0;
    }

    strcpy(fileSearch,SavedGamesPath);
    strcat(fileSearch,"*.*");

    startHandle = handle = _findfirst(filePathPrepend(fileSearch, 0), &find);

    while (handle != -1)
    {
        if (find.name[0] == '.')
        {
            goto alreadyLoaded;
        }
        fileName[0] = 0;

        strcpy(fileName, find.name);

        if (fileName[0] == 0)
        {
            goto alreadyLoaded;
        }

        if (strstr(fileName,PKTS_EXTENSION))
        {
            goto alreadyLoaded;
        }

        for (index = 0; index < gpNumberGames; index++)
        {
            if (!_stricmp(gpGames[index].fileSpec, fileName))
            {                                               //if matching file specs,
                goto alreadyLoaded;                         //break-continue
            }
        }

        gpGames = memRealloc(gpGames, (gpNumberGames+1) * sizeof(gpgame), "gpGames", NonVolatile);

        gpGames[gpNumberGames].fileSpec = memStringDupe(fileName);
        //gpGames[gpNumberGames].title = title;
        gpGames[gpNumberGames].title = memStringDupe(fileName);

        gpNumberGames++;
alreadyLoaded:;
        handle = _findnext(startHandle, &find);
    }

    if (gpNumberGames > 1)
    {
        //alphabetically sort the game list
        qsort(&gpGames[0],gpNumberGames,sizeof(gpgame),compareGamesCB);
    }
    gpCurrentSelected = gpCurrentGame = 0;      //set default game
}