Search in sources :

Example 1 with QuakeFile

use of jake2.util.QuakeFile in project narchy by automenta.

the class GameSave method WriteLevel.

/**
 * WriteLevel
 */
public static void WriteLevel(String filename) {
    try {
        int i;
        edict_t ent;
        QuakeFile f;
        f = new QuakeFile(filename, "rw");
        if (f == null)
            game_import_t.error("Couldn't open for writing: " + filename);
        // write out level_locals_t
        GameBase.level.write(f);
        // write out all the entities
        for (i = 0; i < GameBase.num_edicts; i++) {
            ent = GameBase.g_edicts[i];
            if (!ent.inuse)
                continue;
            f.writeInt(i);
            ent.write(f);
        }
        i = -1;
        f.writeInt(-1);
        f.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : QuakeFile(jake2.util.QuakeFile)

Example 2 with QuakeFile

use of jake2.util.QuakeFile in project narchy by automenta.

the class SV_CCMDS method SV_ReadServerFile.

/*
	==============
	SV_ReadServerFile
	
	==============
	*/
public static void SV_ReadServerFile() {
    String filename = "", name = "", string, mapcmd;
    try {
        QuakeFile f;
        mapcmd = "";
        Com.DPrintf("SV_ReadServerFile()\n");
        filename = FS.Gamedir() + "/save/current/server.ssv";
        f = new QuakeFile(filename, "r");
        // read the comment field but ignore
        f.readString();
        // read the mapcmd
        mapcmd = f.readString();
        // these will be things like coop, skill, deathmatch, etc
        while (true) {
            name = f.readString();
            if (name == null)
                break;
            string = f.readString();
            Com.DPrintf("Set " + name + " = " + string + '\n');
            Cvar.ForceSet(name, string);
        }
        f.close();
        // start a new game fresh with new cvars
        SV_INIT.SV_InitGame();
        SV_INIT.svs.mapcmd = mapcmd;
        // read game state
        filename = FS.Gamedir() + "/save/current/game.ssv";
        GameSave.ReadGame(filename);
    } catch (Exception e) {
        Com.Printf("Couldn't read file " + filename + '\n');
        e.printStackTrace();
    }
}
Also used : QuakeFile(jake2.util.QuakeFile) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 3 with QuakeFile

use of jake2.util.QuakeFile in project narchy by automenta.

the class SV_CCMDS method SV_WriteLevelFile.

/*
	==============
	SV_WriteLevelFile
	
	==============
	*/
public static void SV_WriteLevelFile() {
    String name;
    QuakeFile f;
    Com.DPrintf("SV_WriteLevelFile()\n");
    name = FS.Gamedir() + "/save/current/" + SV_INIT.sv.name + ".sv2";
    try {
        f = new QuakeFile(name, "rw");
        for (int i = 0; i < Defines.MAX_CONFIGSTRINGS; i++) f.writeString(SV_INIT.sv.configstrings[i]);
        CM.CM_WritePortalState(f);
        f.close();
    } catch (Exception e) {
        Com.Printf("Failed to open " + name + '\n');
        e.printStackTrace();
    }
    name = FS.Gamedir() + "/save/current/" + SV_INIT.sv.name + ".sav";
    GameSave.WriteLevel(name);
}
Also used : QuakeFile(jake2.util.QuakeFile) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 4 with QuakeFile

use of jake2.util.QuakeFile in project narchy by automenta.

the class GameSave method WriteGame.

/**
 * WriteGame
 *
 * This will be called whenever the game goes to a new level, and when the
 * user explicitly saves the game.
 *
 * Game information include cross level data, like multi level triggers,
 * help computer info, and all client states.
 *
 * A single player death will automatically restore from the last save
 * position.
 */
public static void WriteGame(String filename, boolean autosave) {
    try {
        QuakeFile f;
        if (!autosave)
            PlayerClient.SaveClientData();
        f = new QuakeFile(filename, "rw");
        if (f == null)
            game_import_t.error("Couldn't write to " + filename);
        GameBase.game.autosaved = autosave;
        GameBase.game.write(f);
        GameBase.game.autosaved = false;
        for (int i = 0; i < GameBase.game.maxclients; i++) GameBase.game.clients[i].write(f);
        Lib.fclose(f);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : QuakeFile(jake2.util.QuakeFile)

Example 5 with QuakeFile

use of jake2.util.QuakeFile in project narchy by automenta.

the class GameSave method ReadLevel.

/**
 * ReadLevel
 *
 * SpawnEntities will allready have been called on the level the same way it
 * was when the level was saved.
 *
 * That is necessary to get the baselines set up identically.
 *
 * The server will have cleared all of the world links before calling
 * ReadLevel.
 *
 * No clients are connected yet.
 */
public static void ReadLevel(String filename) {
    try {
        edict_t ent;
        QuakeFile f = new QuakeFile(filename, "r");
        if (f == null)
            game_import_t.error("Couldn't read level file " + filename);
        // wipe all the entities
        CreateEdicts();
        GameBase.num_edicts = (int) GameBase.maxclients.value + 1;
        // load the level locals
        GameBase.level.read(f);
        // load all the entities
        while (true) {
            int entnum = f.readInt();
            if (entnum == -1)
                break;
            if (entnum >= GameBase.num_edicts)
                GameBase.num_edicts = entnum + 1;
            ent = GameBase.g_edicts[entnum];
            ent.read(f);
            ent.cleararealinks();
            game_import_t.linkentity(ent);
        }
        Lib.fclose(f);
        // mark all clients as unconnected
        for (int i = 0; i < GameBase.maxclients.value; i++) {
            ent = GameBase.g_edicts[i + 1];
            ent.client = GameBase.game.clients[i];
            ent.client.pers.connected = false;
        }
        // do any load time things at this point
        for (int i = 0; i < GameBase.num_edicts; i++) {
            ent = GameBase.g_edicts[i];
            if (!ent.inuse)
                continue;
            // fire any cross-level triggers
            if (ent.classname != null)
                if (Lib.strcmp(ent.classname, "target_crosslevel_target") == 0)
                    ent.nextthink = GameBase.level.time + ent.delay;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : QuakeFile(jake2.util.QuakeFile)

Aggregations

QuakeFile (jake2.util.QuakeFile)9 IOException (java.io.IOException)4 FileNotFoundException (java.io.FileNotFoundException)3 Vargs (jake2.util.Vargs)1 Calendar (java.util.Calendar)1