/
area/
classes/net/sourceforge/pain/logic/
classes/net/sourceforge/pain/logic/event/
classes/net/sourceforge/pain/logic/fn/util/
classes/net/sourceforge/pain/network/console/
classes/net/sourceforge/pain/plugin/
classes/net/sourceforge/pain/plugin/reset/
classes/net/sourceforge/pain/plugin/shutdown/
classes/net/sourceforge/pain/plugin/social/
classest/net/sourceforge/pain/db/data/
doc/
doc/paindb/resources/
src/net/sourceforge/pain/logic/
src/net/sourceforge/pain/logic/event/
src/net/sourceforge/pain/logic/fn/util/
src/net/sourceforge/pain/network/console/
src/net/sourceforge/pain/network/console/telnet/
src/net/sourceforge/pain/plugin/
src/net/sourceforge/pain/plugin/command/
src/net/sourceforge/pain/plugin/reset/
src/net/sourceforge/pain/plugin/shutdown/
src/net/sourceforge/pain/plugin/social/
src/net/sourceforge/pain/util/
tests/
tests/net/sourceforge/pain/db/data/
package net.sourceforge.pain.data;


import net.sourceforge.pain.db.*;
import net.sourceforge.pain.data.type.*;

import java.util.*;


public final class World extends DbObject {

	private static final int NAME = 0;
	private static final int TIME = 1;
	private static final int PROTOTYPES_REGISTRY = 2;
	private static final int RACES = 3;
	private static final int INDEXED_SPACES_REGISTRY = 4;
	private static final int FIRST_ACTIVE_PLAYER = 5;
	private static final int RESET_GROUPS = 6;
	private static final int PLAYERS_QUIT_SPACE = 7;
	private static final int DEFAULT_BIRTH_SPACE = 8;
	private static final int PLAYERS_REGISTRY = 9;
	private static final int NFIELDS = 10;

	public World() {
	}

	public World(PainDB db) throws Exception {
		super(db);
		// all these values aggregated!
		setReference(TIME, new WorldTime(db));
		setReference(PROTOTYPES_REGISTRY, new PrototypesRegistry(db));
		setReference(INDEXED_SPACES_REGISTRY, new IndexedSpacesRegistry(db));
		setReference(RESET_GROUPS, new ResetGroupRegistry(db));
		setReference(PLAYERS_REGISTRY, new PlayersRegistry(db));

		final Space quitSpace = (Space) ObjectFactory.create(Space.class);
		quitSpace.setCapacity(Integer.MAX_VALUE);
		quitSpace.setDesc("quit space");
		quitSpace.setName("quit space");
		setReference(PLAYERS_QUIT_SPACE, quitSpace);
	}

	public DbClassSchema provideSchema() {
		byte types[] = new byte[NFIELDS];
		String names[] = new String[NFIELDS];

		types[NAME] = DbType.STRING;
		names[NAME] = "name";

		types[TIME] = DbType.REFERENCE;
		names[TIME] = "time";

		types[PROTOTYPES_REGISTRY] = DbType.REFERENCE;
		names[PROTOTYPES_REGISTRY] = "prototypes_registry";

		types[INDEXED_SPACES_REGISTRY] = DbType.REFERENCE;
		names[INDEXED_SPACES_REGISTRY] = "indexed_spaces";

		types[RACES] = DbType.REFERENCE_SET;
		names[RACES] = "races";

		types[FIRST_ACTIVE_PLAYER] = DbType.REFERENCE;
		names[FIRST_ACTIVE_PLAYER] = "first_active_player";

		types[RESET_GROUPS] = DbType.REFERENCE;
		names[RESET_GROUPS] = "resets_groups";

		types[PLAYERS_QUIT_SPACE] = DbType.REFERENCE;
		names[PLAYERS_QUIT_SPACE] = "quit_players_space";

		types[DEFAULT_BIRTH_SPACE] = DbType.REFERENCE;
		names[DEFAULT_BIRTH_SPACE] = "default_birth_space";

		types[PLAYERS_REGISTRY] = DbType.REFERENCE;
		names[PLAYERS_REGISTRY] = "players_registry";

		return new DbClassSchema(types, names);
	}

	public void setName(String name) {
		setString(NAME, name);
	}

	public String getName() {
		return getString(NAME);
	}

	public WorldTime getWorldTime() {
		return (WorldTime) getReference(TIME);
	}


	public Player getFirstActivePlayer() {
		return (Player) getReference(FIRST_ACTIVE_PLAYER);
	}

	public void setFirstActivePlayer(Player p) {
		setReference(FIRST_ACTIVE_PLAYER, p);
	}

	public PrototypesRegistry getPrototypesRegistry() {
		return (PrototypesRegistry) getReference(PROTOTYPES_REGISTRY);
	}

	public IndexedSpacesRegistry getIndexedSpacesRegistry() {
		return (IndexedSpacesRegistry) getReference(INDEXED_SPACES_REGISTRY);
	}

	public Set getRaces() {
		return getRefSet(RACES);
	}

	public ResetGroupRegistry getResetGroupRegistry() {
		return (ResetGroupRegistry) getReference(RESET_GROUPS);
	}

	public Space getPlayersQuitSpace() {
		return (Space) getReference(PLAYERS_QUIT_SPACE);
	}

	public Space getDefaultBirthSpace() {
		return (Space) getReference(DEFAULT_BIRTH_SPACE);
	}

	public void setDefaultBirthSpace(Space space) {
		setReference(DEFAULT_BIRTH_SPACE, space);
	}

	public PlayersRegistry getPlayersRegistry() {
		return (PlayersRegistry) getReference(PLAYERS_REGISTRY);
	}

}