Exemplo n.º 1
0
void NormalGame::init(Log *_log)
{
	STACKTRACE;
	Game::init(_log);

	team_table_size = 0;

	view->window->locate(0,0,0,0,0,0.9,0,1);

	tw_delete_file(home_ini_full_path("tmp.ini"));
	tw_delete_file(home_ini_full_path("fleets.tmp"));
	tw_set_config_file(home_ini_full_path("tmp.ini"));
	set_config_string (NULL, "Ignorethis", "");
	if (!log->playback) init_players();
	log_file(home_ini_full_path("tmp.ini"));
	if (log->playback) {
		for (int i = 0; true; i += 1) {
			char buffy[64];
			sprintf(buffy, "Player%d", i + 1);
			log_file(home_ini_full_path("tmp.ini"));
			const char *type = get_config_string(buffy, "Type", NULL);
			if (!type) break;
			const char *name = get_config_string(buffy, "Name", buffy);
			int channel = get_config_int(buffy, "Channel", -2);
			int ti = get_config_int(buffy, "Team", 0);
			add_player(create_control(channel, type), ti, name, buffy);
			player_fleet[i]->load(NULL, buffy);
			player_fleet[i]->save("fleets.tmp", buffy);
		}
	}

	prepare();
	init_objects();

	next_choose_new_ships_time = game_time + 200;

	// team and health indicators.
	indteamtoggle = 0;
	indhealthtoggle = 0;

	return;
}
Exemplo n.º 2
0
void save_spacesprite(SpaceSprite *ss, const char *spritename, const char *destination, const char *extension)
{
	STACKTRACE;
	int i;
	char buf[512];

	if (!ss)
		return;

	if (ss->frames()) {
		for (i = 0; i < ss->frames(); i += 1) {
			if (strchr(extension, '.')) {
				sprintf(buf, "tmp/%s%03d%s", spritename, i, extension);
			} else {
				sprintf(buf, "tmp/%s%03d.bmp", spritename, i);
			}

			save_bitmap(buf, ss->get_bitmap(i), NULL);
		}

	}

	sprintf(buf, "tmp/%s.ini", spritename);
	tw_set_config_file(buf);
	set_config_string("Main", "Type", "SpaceSprite");
	set_config_int("SpaceSprite", "Number", (int)ss->frames());
	set_config_int("SpaceSprite", "Width", (int)ss->width());
	set_config_int("SpaceSprite", "Height", (int)ss->height());
	set_config_string("SpaceSprite", "SubType", "Normal");
	set_config_string("SpaceSprite", "Extension", extension);
	chdir("tmp");
	sprintf(buf, "dat ../ships/%s.dat -k -a *", destination);
	//	system(buf);
	sprintf(buf, "move * ..\\ships\\%s", destination);
	system(buf);
	chdir("..");
	return;
}
Exemplo n.º 3
0
void audio_menu (Game *game)
{
	int i;

	//set dialog values
	audio_dialog[DIALOG_AUDIO_SOUND_ON].flags = sound.sound_on ? D_SELECTED : 0;
	audio_dialog[DIALOG_AUDIO_MUSIC_ON].flags = sound.music_on ? D_SELECTED : 0;
	audio_dialog[DIALOG_AUDIO_SOUND_VOL].d2 = sound.sound_volume;
	audio_dialog[DIALOG_AUDIO_MUSIC_VOL].d2 = sound.music_volume;

	//do the dialog
	i = tw_popup_dialog(NULL, audio_dialog, 0);
	if (i != DIALOG_AUDIO_OK) return;

	//set actual values
	sound.set_volumes(
		audio_dialog[DIALOG_AUDIO_SOUND_VOL].d2,
		audio_dialog[DIALOG_AUDIO_MUSIC_VOL].d2,
		audio_dialog[DIALOG_AUDIO_SOUND_ON].flags & D_SELECTED,
		audio_dialog[DIALOG_AUDIO_MUSIC_ON].flags & D_SELECTED
		);
	tw_set_config_file("client.ini");
	sound.save();
};
Exemplo n.º 4
0
void change_options()
{
	STACKTRACE;
	int optionsRet, i;

	tw_set_config_file("client.ini");
	//	old_optionsDialog[OPTIONS_DIALOG_AA].d1 = get_aa_mode();

	old_optionsDialog[OPTIONS_DIALOG_INTERPOLATION_ON].flags =
		interpolate_frames ? D_SELECTED : 0;
	int aa = get_config_int("Rendering", "AA_Mode", AA_NO_AA);
	old_optionsDialog[OPTIONS_DIALOG_AA_ON].flags =
		(aa&AA_NO_AA) ? 0 : D_SELECTED;
	old_optionsDialog[OPTIONS_DIALOG_NOALIGN_ON].flags =
		(aa&AA_NO_ALIGN) ? D_SELECTED : 0;
	old_optionsDialog[OPTIONS_DIALOG_BLEND_ON].flags =
		(aa&AA_BLEND) ? D_SELECTED : 0;
	old_optionsDialog[OPTIONS_DIALOG_ALPHA_ON].flags =
		(aa&AA_ALPHA) ? D_SELECTED : 0;

	tw_set_config_file("server.ini");
	old_optionsDialog[OPTIONS_DIALOG_STARS_SLIDER].d2 =
		get_config_int("Stars", "Depth", 192);
	old_optionsDialog[OPTIONS_DIALOG_RELATIVITY_SLIDER].d2 =
		iround(get_config_float("Game", "ShotRelativity", 0.5) * 1000);
	if (get_config_int("Game", "FriendlyFire", 1))
		old_optionsDialog[OPTIONS_DIALOG_FRIENDLY_FIRE].flags = D_SELECTED;
	else
		old_optionsDialog[OPTIONS_DIALOG_FRIENDLY_FIRE].flags = 0;

	if (get_config_int("View", "CameraHidesCloakers", 1))
		old_optionsDialog[OPTIONS_DIALOG_HIDE_CLOAKERS].flags = D_SELECTED;
	else
		old_optionsDialog[OPTIONS_DIALOG_HIDE_CLOAKERS].flags = 0;

	tw_set_config_file("client.ini");

	if (get_config_int("Planet", "PlanetDimension", 2) == 3)
		old_optionsDialog[OPTIONS_DIALOG_3DPLANET].flags = D_SELECTED;
	else
		old_optionsDialog[OPTIONS_DIALOG_3DPLANET].flags = 0;

	i = get_view_num ( get_config_string ( "View", "View", NULL ) );
	if (i == -1) i = 0;
	old_optionsDialog[OPTIONS_DIALOG_VIEW].d1 = i;

	optionsRet = tw_popup_dialog(NULL, old_optionsDialog, OPTIONS_DIALOG_OK);

	if (optionsRet == OPTIONS_DIALOG_CANCEL) return;

	//	set_aa_mode(old_optionsDialog[OPTIONS_DIALOG_AA].d1);

	tw_set_config_file("client.ini");
	//	set_config_int("View", "Anti-Aliasing", get_aa_mode());
	interpolate_frames =
		(old_optionsDialog[OPTIONS_DIALOG_INTERPOLATION_ON].flags & D_SELECTED) ? 1 : 0;
	set_config_int("View", "InterpolateFrames", interpolate_frames);
	aa&=~AA_NO_AA;aa|= (old_optionsDialog[OPTIONS_DIALOG_AA_ON].flags) ?
		0 : AA_NO_AA;
	aa&=~AA_NO_ALIGN;aa|= (old_optionsDialog[OPTIONS_DIALOG_NOALIGN_ON].flags) ?
		AA_NO_ALIGN : 0;
	aa&=~AA_BLEND;aa|= (old_optionsDialog[OPTIONS_DIALOG_BLEND_ON].flags) ?
		AA_BLEND : 0;
	aa&=~AA_ALPHA;aa|= (old_optionsDialog[OPTIONS_DIALOG_ALPHA_ON].flags) ?
		AA_ALPHA : 0;
	set_config_int("Rendering", "AA_Mode", aa);
	set_tw_aa_mode(aa);

	if (old_optionsDialog[OPTIONS_DIALOG_3DPLANET].flags == D_SELECTED)
		i = 3;
	else
		i = 2;
	set_config_int("Planet", "PlanetDimension", i);

	View *v = get_view(
		view_name[old_optionsDialog[OPTIONS_DIALOG_VIEW].d1],
		NULL
		);
	set_view(v);
	twconfig_set_string("/cfg/client.ini/view/view",
		view_name[old_optionsDialog[OPTIONS_DIALOG_VIEW].d1]);
	if (game && !game->view_locked) game->change_view(
			view_name[old_optionsDialog[OPTIONS_DIALOG_VIEW].d1]);

	twconfig_set_int("/cfg/server.ini/stars/depth",
		old_optionsDialog[OPTIONS_DIALOG_STARS_SLIDER].d2);

	twconfig_set_float("/cfg/server.ini/game/shotrelativity",
		old_optionsDialog[OPTIONS_DIALOG_RELATIVITY_SLIDER].d2 / 1000.0);

	if (old_optionsDialog[OPTIONS_DIALOG_FRIENDLY_FIRE].flags & D_SELECTED)
		i = 1;
	else i = 0;
	twconfig_set_int("/cfg/server.ini/game/friendlyfire", i);

	if (old_optionsDialog[OPTIONS_DIALOG_HIDE_CLOAKERS].flags & D_SELECTED)
		i = 1;
	else i = 0;
	twconfig_set_int("/cfg/server.ini/view/camerahidescloakers", i);

	return;
}
Exemplo n.º 5
0
void video_menu (Game *game)
{
	int choice = -1;
	bool done = false;
	int i, width, height, bpp, fs, native_res, native_bpp;

	DIALOG old_settings[sizeof(video_dialog)/sizeof(video_dialog[0])];

	tw_set_config_file(home_ini_full_path("client.ini"));
	if (get_config_int("Video", "NativeResolution", 1)) {
		i = static_get_native_resolution_index();
	} else {
		sprintf(dialog_string[3], "%dx%d", videosystem.width, videosystem.height);
		for (i = 0; i< sizeof(resolution)/sizeof(resolution[0]); i++) {
			if (strcmp(resolution[i], dialog_string[3]) == 0) {
				break;
			}
		}
		if (i == sizeof(resolution)/sizeof(resolution[0])) {
			i = static_get_native_resolution_index();
		}
	}
	video_dialog[DIALOG_VIDEO_RESLIST].d1 = i;

	if (get_config_int("Video", "NativeBpp", 1)) {
		i = static_get_native_bpp_index();
	} else {
		for (i = 0; i< sizeof(color_depth)/sizeof(color_depth[0]); i++) {
			if (atoi(color_depth[i]) == videosystem.bpp) {
				break;
			}
			if (i == sizeof(color_depth)/sizeof(color_depth[0])) {
				i = static_get_native_bpp_index();
			}
		}
	}

	video_dialog[DIALOG_VIDEO_BPPLIST].d1 = i;

	//set button for fullscreen
	video_dialog[DIALOG_VIDEO_FULLSCREEN].flags = videosystem.fullscreen ? D_SELECTED : 0;

	int startfs = video_dialog[DIALOG_VIDEO_FULLSCREEN].flags;

	//set gamma correction
	video_dialog[DIALOG_VIDEO_GAMMA_SLIDER].d2 = get_gamma();
	memcpy(old_settings, video_dialog, sizeof(video_dialog));

	while ( (choice != DIALOG_VIDEO_EXIT) && (!done) ) {
		//do the dialog
		choice = tw_popup_dialog(NULL, video_dialog, 0);
		if (choice == -1)
			choice = DIALOG_VIDEO_EXIT;

		static_video_dialog_to_params(video_dialog, &width, &height, &bpp, &fs, &native_res, &native_bpp);

		switch (choice) {
			case DIALOG_VIDEO_GET_DEFAULT:
				set_config_int("Video", "BitsPerPixel", 16);
				set_config_int("Video", "ScreenWidth", 640);
				set_config_int("Video", "ScreenHeight", 480);
				set_config_int("Video", "FullScreen", 1);
				set_config_int("Video", "Gamma", 128);
				set_config_int("Video", "NativeResolution", 1);
				set_config_int("Video", "NativeBpp", 1);

				if (tw_get_desktop_resolution(&width, &height)) {
					tw_error("Unable to get desktop resolution!!!");
				}
				videosystem.set_resolution(width, height, tw_desktop_color_depth(), 1);
				return;
				break;
			case DIALOG_VIDEO_OK:
				set_gamma(video_dialog[DIALOG_VIDEO_GAMMA_SLIDER].d2);
				if (videosystem.set_resolution(width, height, bpp, fs)) {
					if (confirmVideoChanges()) {
						set_config_int("Video", "BitsPerPixel", bpp);
						set_config_int("Video", "ScreenWidth", width);
						set_config_int("Video", "ScreenHeight", height);
						set_config_int("Video", "FullScreen", fs);
						set_config_int("Video", "Gamma", get_gamma());

						if (video_dialog[DIALOG_VIDEO_RESLIST].d1 == static_get_native_resolution_index()) {
							set_config_int("Video", "NativeResolution", 1);
						} else {
							set_config_int("Video", "NativeResolution", 0);
						}
						if (video_dialog[DIALOG_VIDEO_BPPLIST].d1 == static_get_native_bpp_index()) {
							set_config_int("Video", "NativeBpp", 1);
						} else {
							set_config_int("Video", "NativeBpp", 0);
						}
						return;
					} else {
						static_video_dialog_to_params(old_settings, &width, &height, &bpp, &fs, &native_res, &native_bpp);
						videosystem.set_resolution(width, height, bpp, fs);
						memcpy(video_dialog, old_settings, sizeof(video_dialog));
					}
				}
				break;

			case DIALOG_VIDEO_GAMMA_SLIDER:
				set_gamma(video_dialog[DIALOG_VIDEO_GAMMA_SLIDER].d2);
				break;

			case DIALOG_VIDEO_EXIT:
			case -1:
				return;
				break;
		}
	}
	return;
}
Exemplo n.º 6
0
REGISTER_FILE
#include "scp.h"
#include "frame.h"

#include "mmain.h"
#include "mview.h"
#include "mcontrol.h"
#include "other/planet3d.h"
#include "mshppan.h"
#include "mship.h"
#include "mlog.h"
//#include "mnet1.h"
#include "mitems.h"
#include "mfleet.h"

#include "games/gflmelee.h"

#include "other/twconfig.h"

int NormalGame::add_player (Control *c, int team_index, const char *name, const char *fleet_section, const char *fleet_file)
{
	int i = num_players;
	num_players += 1;
	player_control = (Control**) realloc(player_control,   sizeof(Control*)   * num_players);
	player_name    =    (char**) realloc(player_name,      sizeof(char*)      * num_players);
	//	player_panel = (ShipPanel**) realloc(player_panel,     sizeof(ShipPanel*) * num_players);
	player_fleet =     (Fleet**) realloc(player_fleet,     sizeof(Fleet *)    * num_players);
	player_team =    (TeamCode*) realloc(player_team,      sizeof(TeamCode)   * num_players);
	player_control[i] = c;
	add_focus(c, c->channel);
	//	player_panel[i] = NULL;
	player_fleet[i] = new Fleet();
	player_fleet[i]->reset();
	player_name[i] = strdup(name);
	if (team_index >= team_table_size) {
		int i = team_table_size;
		team_table_size = team_index + 1;
		team_table = (TeamCode*) realloc(team_table, sizeof(TeamCode) * team_table_size);
		for (; i < team_table_size; i += 1) {
			if (i) team_table[i] = new_team();
			else team_table[i] = 0;
		}
	}
	if (team_index) player_team[i] = team_table[team_index];
	else player_team[i] = new_team();
	char sect[40];
	sprintf(sect, "Player%d", i+1);
	if (c->channel == channel_none) {
		tw_error("channel_none not allowed here");
		//log_file(fleet_file);
		//::fleet->load(NULL, fleet_section);
	}
	else if (log->get_direction(c->channel) & Log::direction_write) {
		player_fleet[i]->load(fleet_file, fleet_section);
		log_fleet(c->channel, player_fleet[i]);
		c->target_sign_color = ((3+i) % 7) + 1;
	} else {
		log_fleet(c->channel, player_fleet[i]);
	}
	tw_set_config_file(home_ini_full_path("tmp.ini"));
	set_config_string(sect, "Name", name);
	set_config_string(sect, "Type", c->getTypeName());
	set_config_int(sect, "Team", team_index);
	set_config_int(sect, "Channel", c->channel);
	set_config_int(sect, "StartingFleetCost", player_fleet[i]->getCost());
	set_config_int(sect, "StartingFleetSize", player_fleet[i]->getSize());
	player_fleet[i]->save(NULL, sect);
	player_fleet[i]->save("fleets.tmp", sect);
	return i;
}
Exemplo n.º 7
0
void NormalGame::init_players()
{
	STACKTRACE;
	switch (log->type) {
		case Log::log_normal:
		{
			for (int i = 0; true; i += 1) {
				char buffy[64];
				sprintf(buffy, "Player%d", i + 1);
				tw_set_config_file("scp.ini");
				const char *type = get_config_string(buffy, "Type", NULL);
				if (!type) break;
				if (strcmp(type, "none") == 0) continue;
				const char *name = get_config_string(buffy, "Name", buffy);
				char config[64];
				sprintf(config, "Config%d", get_config_int(buffy, "Config", 0));
				//int channel = channel_server;
				//if (strcmp(type, "WussieBot") == 0) channel = channel_none;
				//if (strcmp(type, "MoronBot") == 0) channel = channel_none;
				int ti = get_config_int(buffy, "Team", 0);
				add_player(create_control(channel_server, type, config), ti, name, buffy);
			}
		}
		break;
		case Log::log_net1client:
		case Log::log_net1server:
		{
			log_file(home_ini_full_path("server.ini"));
			//int use_teams_menu = get_config_int("Network", "NetworkMeleeUseTeams", 0);
			//if (use_teams_menu) {
			if (1) {
				int j;
				for (j = 0; j < 2; j += 1) {
					int ch;
					if (j == 0) ch = channel_server;
					else ch = channel_client;
					if (is_local(ch)) {
								 //each side determines whether they are using manually specified teams
						tw_set_config_file("client.ini");
						int use_teams_menu = get_config_int("Network", "NetworkMeleeUseTeams", 0);
						const char *simple_config =
							"[Player1]\nType=Human\nConfig=0\nTeam=0\n";
						for (int i = 0; true; i += 1) {
							char buffy[64];
							sprintf(buffy, "Player%d", i + 1);
							if (use_teams_menu) tw_set_config_file("scp.ini");
							else set_config_data(simple_config, strlen(simple_config));
							const char *type = get_config_string(buffy, "Type", NULL);
							if (!type) {
								int tmp = 0;
								log_int(ch, tmp);
								break;
							}
							if (strcmp(type, "none") == 0) continue;
							const char *name = get_config_string(buffy, "Name", buffy);
							char config[64];
							sprintf(config, "Config%d", get_config_int(buffy, "Config", 0));
							//int channel = channel_server;
							//if (strcmp(type, "WussieBot") == 0) channel = channel_none;
							//if (strcmp(type, "MoronBot") == 0) channel = channel_none;
							int ti = get_config_int(buffy, "Team", 0);
							{int tmp = 1; log_int(ch, tmp);}
							log_int(ch, ti);
							int name_length = strlen(name);
							log_int(ch, name_length);
							log_data(ch, (char*)name, name_length);
							add_player(create_control(ch, type, config), ti, name, buffy);
						}
					} else {
						for (int i = 0; true; i += 1) {
							int tmp;
							log_int(ch, tmp);
							if (tmp == 0) break;
							int team;
							char *name;
							log_int(ch, team);
							int name_length;
							log_int(ch, name_length);
							name = (char*)malloc((name_length+1)*sizeof(char));
							log_data(ch, name, name_length);
							name[name_length] = 0;
							add_player(create_control(ch, "Whatever"), team, name, NULL);
						}
					}
				}
			}
		}
		break;
	}
	return;
}