Example #1
0
int FindResArg(char *prefix, int *sw, int *sh)
{
	int i;
	int w, h;
	char *endptr;
	int prefixlen = strlen(prefix);

	for (i = 0; i < Num_args; ++i)
		if (Args[i][0] == '-' && !d_strnicmp(Args[i] + 1, prefix, prefixlen))
		{
			w = strtol(Args[i] + 1 + prefixlen, &endptr, 10);
			if (w > 0 && endptr && endptr[0] == 'x')
			{
				h = strtol(endptr + 1, &endptr, 10);
				if (h > 0 && endptr[0] == '\0')
				{
					*sw = w;
					*sh = h;
					return i;
				}
			}
		}

	return 0;
}
Example #2
0
// Return true if this level has a name of the form "level??"
// Note that a pathspec can appear at the beginning of the filename.
int is_real_level(char *filename)
{
	int len = strlen(filename);

	if (len < 6)
		return 0;

	return !d_strnicmp(&filename[len-11], "level", 5);

}
Example #3
0
void add_missions_to_list(mle *mission_list, char *path, char *rel_path, int anarchy_mode)
{
	char **find, **i, *ext;

	find = PHYSFS_enumerateFiles(path);

	for (i = find; *i != NULL; i++)
	{
		if (strlen(path) + strlen(*i) + 1 >= PATH_MAX)
			continue;	// path is too long

		strcat(rel_path, *i);
		if (PHYSFS_isDirectory(path))
		{
			strcat(rel_path, "/");
			add_missions_to_list(mission_list, path, rel_path, anarchy_mode);
			*(strrchr(path, '/')) = 0;
		}
		else if ((ext = strrchr(*i, '.')) && (!d_strnicmp(ext, ".msn", 4) || !d_strnicmp(ext, ".mn2", 4)))
			if (read_mission_file(&mission_list[num_missions], rel_path, ML_MISSIONDIR))
			{
				if (anarchy_mode || !mission_list[num_missions].anarchy_only_flag)
				{
					mission_list[num_missions].builtin_hogsize = 0;
					num_missions++;
				}
				else
					d_free(mission_list[num_missions].path);
			}
		
		if (num_missions >= MAX_MISSIONS)
		{
			break;
		}

		(strrchr(path, '/'))[1] = 0;	// chop off the entry
	}

	PHYSFS_freeList(find);
}
Example #4
0
static int HUD_init_message_literal_worth_showing(int class_flag, const char *message)
{
	int i, j;
	// check if message is already in list and bail out if so
	if (HUD_nmessages > 0)
	{
		// if "normal" message, only check if it's the same at the most recent one, if marked as "may duplicate" check whole list
		for (i = ((class_flag & HM_MAYDUPL)?0:HUD_nmessages-1); i < HUD_nmessages; i++)
		{
			if (!d_strnicmp(message, HUD_messages[i].message, sizeof(char)*HUD_MESSAGE_LENGTH))
			{
				HUD_messages[i].time = F1_0*2; // keep redundant message in list
				if (i >= HUD_nmessages-HUD_MAX_NUM_DISP) // if redundant message on display, update them all
					for (i = (HUD_nmessages-HUD_MAX_NUM_DISP<0?0:HUD_nmessages-HUD_MAX_NUM_DISP), j = 1; i < HUD_nmessages; i++, j++)
						HUD_messages[i].time = F1_0*(j*2);
				return 0;
			}
		}
	}

	if (HUD_nmessages >= HUD_MAX_NUM_STOR)
	{
		HUD_nmessages = HUD_MAX_NUM_STOR; // unnecessary but just in case it might be bigger... which is impossible
		for (i = 0; i < HUD_nmessages-1; i++) 
		{
			memcpy(&HUD_messages[i], &HUD_messages[i+1], sizeof(struct hudmsg));
		}
	}
	else
	{
		HUD_nmessages++;
	}
	snprintf(HUD_messages[HUD_nmessages-1].message, sizeof(char)*HUD_MESSAGE_LENGTH, "%s", message);
	if (HUD_nmessages-HUD_MAX_NUM_DISP < 0)
		HUD_messages[HUD_nmessages-1].time = F1_0*3; // one message - display 3 secs
	else
		for (i = HUD_nmessages-HUD_MAX_NUM_DISP, j = 1; i < HUD_nmessages; i++, j++) // multiple messages - display 2 seconds each
			HUD_messages[i].time = F1_0*(j*2);
	

	if (HUD_color == -1)
		HUD_color = BM_XRGB(0,28,0);
	con_printf(CON_HUD, "%s\n", message);

	if (Newdemo_state == ND_STATE_RECORDING )
		newdemo_record_hud_message( message );

	return 1;
}
Example #5
0
//compare a string for a token. returns true if match
int istok(char *buf,char *tok)
{
	return d_strnicmp(buf,tok,strlen(tok)) == 0;

}
Example #6
0
int FinalCheats(int key)
{
	static char cheat_buffer[CHEAT_MAX_LEN] = "AAAAAAAAAAAAAAA";
	int i = 0, gotcha = 0;

	if (Game_mode & GM_MULTI)
		return 0;

	for (i = 1; i < CHEAT_MAX_LEN; i++)
		cheat_buffer[i-1] = cheat_buffer[i];
	cheat_buffer[CHEAT_MAX_LEN-1] = key_ascii();
	for (i = 0; i < NUM_CHEATS; i++)
	{
		int cheatlen = strlen(cheat_codes[i].string);
		Assert(cheatlen <= CHEAT_MAX_LEN);
		if (d_strnicmp(cheat_codes[i].string, cheat_buffer+CHEAT_MAX_LEN-cheatlen, cheatlen)==0)
		{
			if (!cheats.enabled && *cheat_codes[i].stateptr != cheats.enabled)
				break;
			if (!cheats.enabled)
				HUD_init_message(HM_DEFAULT, TXT_CHEATS_ENABLED);
			*cheat_codes[i].stateptr = !*cheat_codes[i].stateptr;
			cheats.enabled = 1;
			digi_play_sample( SOUND_CHEATER, F1_0);
			Players[Player_num].score = 0;
			gotcha = i;
			break;
		}
	}
	
	if (!gotcha)
		return 0;

	if (cheat_codes[gotcha].stateptr == &cheats.wowie)
	{
		HUD_init_message_literal(HM_DEFAULT, TXT_WOWIE_ZOWIE);

		Players[Player_num].primary_weapon_flags |= 0xff ^ (HAS_PLASMA_FLAG | HAS_FUSION_FLAG);
		Players[Player_num].secondary_weapon_flags |= 0xff ^ (HAS_SMART_FLAG | HAS_MEGA_FLAG);

		for (i=0; i<3; i++)
			Players[Player_num].primary_ammo[i] = Primary_ammo_max[i];
		for (i=0; i<3; i++)
			Players[Player_num].secondary_ammo[i] = Secondary_ammo_max[i];

		if (Newdemo_state == ND_STATE_RECORDING)
			newdemo_record_laser_level(Players[Player_num].laser_level, MAX_LASER_LEVEL);

		Players[Player_num].energy = MAX_ENERGY;
		Players[Player_num].laser_level = MAX_LASER_LEVEL;
		Players[Player_num].flags |= PLAYER_FLAGS_QUAD_LASERS;
		update_laser_weapon_info();
	}

	if (cheat_codes[gotcha].stateptr == &cheats.wowie2)
	{
		HUD_init_message(HM_DEFAULT, "SUPER %s",TXT_WOWIE_ZOWIE);

		Players[Player_num].primary_weapon_flags = 0xff;
		Players[Player_num].secondary_weapon_flags = 0xff;

		for (i=0; i<MAX_PRIMARY_WEAPONS; i++)
			Players[Player_num].primary_ammo[i] = Primary_ammo_max[i];
		for (i=0; i<MAX_SECONDARY_WEAPONS; i++)
			Players[Player_num].secondary_ammo[i] = Secondary_ammo_max[i];

		if (Newdemo_state == ND_STATE_RECORDING)
			newdemo_record_laser_level(Players[Player_num].laser_level, MAX_LASER_LEVEL);

		Players[Player_num].energy = MAX_ENERGY;
		Players[Player_num].laser_level = MAX_LASER_LEVEL;
		Players[Player_num].flags |= PLAYER_FLAGS_QUAD_LASERS;
		update_laser_weapon_info();
	}

	if (cheat_codes[gotcha].stateptr == &cheats.allkeys)
	{
		HUD_init_message_literal(HM_DEFAULT, TXT_ALL_KEYS);
		Players[Player_num].flags |= PLAYER_FLAGS_BLUE_KEY | PLAYER_FLAGS_RED_KEY | PLAYER_FLAGS_GOLD_KEY;
	}

	if (cheat_codes[gotcha].stateptr == &cheats.invul)
	{
		Players[Player_num].flags ^= PLAYER_FLAGS_INVULNERABLE;
		HUD_init_message(HM_DEFAULT, "%s %s!", TXT_INVULNERABILITY, (Players[Player_num].flags&PLAYER_FLAGS_INVULNERABLE)?TXT_ON:TXT_OFF);
		Players[Player_num].invulnerable_time = GameTime64+i2f(1000);
	}

	if (cheat_codes[gotcha].stateptr == &cheats.cloak)
	{
		Players[Player_num].flags ^= PLAYER_FLAGS_CLOAKED;
		HUD_init_message(HM_DEFAULT, "%s %s!", TXT_CLOAK, (Players[Player_num].flags&PLAYER_FLAGS_CLOAKED)?TXT_ON:TXT_OFF);
		if (Players[Player_num].flags & PLAYER_FLAGS_CLOAKED)
		{
			ai_do_cloak_stuff();
			Players[Player_num].cloak_time = GameTime64;
		}
	}

	if (cheat_codes[gotcha].stateptr == &cheats.shields)
	{
		HUD_init_message_literal(HM_DEFAULT, TXT_FULL_SHIELDS);
		Players[Player_num].shields = MAX_SHIELDS;
	}

	if (cheat_codes[gotcha].stateptr == &cheats.extralife)
	{
		if (Players[Player_num].lives<50)
		{
			Players[Player_num].lives++;
			HUD_init_message_literal(HM_DEFAULT, "Extra life!");
		}
	}

	if (cheat_codes[gotcha].stateptr == &cheats.killreactor)
	{
		kill_and_so_forth();
	}

	if (cheat_codes[gotcha].stateptr == &cheats.exitpath)
	{
#ifdef SHOW_EXIT_PATH
		if (create_special_path())
			HUD_init_message_literal(HM_DEFAULT, "Exit path illuminated!");
#endif
	}

	if (cheat_codes[gotcha].stateptr == &cheats.levelwarp)
	{
		newmenu_item m;
		char text[10]="";
		int new_level_num;
		int item;
		*cheat_codes[gotcha].stateptr = 0;
		m.type=NM_TYPE_INPUT; m.text_len = 10; m.text = text;
		item = newmenu_do( NULL, TXT_WARP_TO_LEVEL, 1, &m, NULL, NULL );
		if (item != -1) {
			new_level_num = atoi(m.text);
			if (new_level_num!=0 && new_level_num>=0 && new_level_num<=Last_level)
			{
				window_set_visible(Game_wind, 0);
				StartNewLevel(new_level_num);
				window_set_visible(Game_wind, 1);
			}
		}
	}

	if (cheat_codes[gotcha].stateptr == &cheats.ghostphysics)
	{
		HUD_init_message(HM_DEFAULT, "%s %s!", "Ghosty mode", cheats.ghostphysics?TXT_ON:TXT_OFF);
	}

	if (cheat_codes[gotcha].stateptr == &cheats.rapidfire)
	{
		do_megawow_powerup(200);
	}

	if (cheat_codes[gotcha].stateptr == &cheats.turbo)
	{
		HUD_init_message(HM_DEFAULT, "%s %s!", "Turbo mode", cheats.turbo?TXT_ON:TXT_OFF);
	}

	if (cheat_codes[gotcha].stateptr == &cheats.robotfiringsuspended)
	{
		HUD_init_message(HM_DEFAULT, "Robot firing %s!", cheats.robotfiringsuspended?TXT_OFF:TXT_ON);
	}

	if (cheat_codes[gotcha].stateptr == &cheats.acid)
	{
		HUD_init_message_literal(HM_DEFAULT, cheats.acid?"Going up!":"Coming down!");
	}

	return 1;
}
Example #7
0
File: hud.c Project: jihnsius/d2r
// Call to flash a message on the HUD.  Returns true if message drawn.
// (message might not be drawn if previous message was same)
int HUD_init_message_va(int class_flag, char * format, va_list args)
{
	int i, j;
#ifndef macintosh
	char message[HUD_MESSAGE_LENGTH+1] = "";
#else
	char message[1024] = "";
#endif

#ifndef macintosh
	vsnprintf(message, sizeof(char)*HUD_MESSAGE_LENGTH, format, args);
#else
	vsprintf(message, format, args);
#endif


	// check if message is already in list and bail out if so
	if (HUD_nmessages > 0)
	{
		// if "normal" message, only check if it's the same at the most recent one, if marked as "may duplicate" check whole list
		for (i = ((class_flag & HM_MAYDUPL)?0:HUD_nmessages-1); i < HUD_nmessages; i++)
		{
			if (!d_strnicmp(message, HUD_messages[i].message, sizeof(char)*HUD_MESSAGE_LENGTH))
			{
				HUD_messages[i].time = F1_0*2; // keep redundant message in list
				if (i >= HUD_nmessages-HUD_MAX_NUM_DISP) // if redundant message on display, update them all
					for (i = (HUD_nmessages-HUD_MAX_NUM_DISP<0?0:HUD_nmessages-HUD_MAX_NUM_DISP), j = 1; i < HUD_nmessages; i++, j++)
						HUD_messages[i].time = F1_0*(j*2);
				return 0;
			}
		}
	}

	// HACK!!!
	// clean message if necessary.
	// using placeholders may mess up message string and crash game(s).
	// block them also to prevent attacks from other clients.
	for (i = 0; i <= strlen(message); i++)
		if (message[i] == '%')
			message [i] = ' ';

	if (HUD_nmessages >= HUD_MAX_NUM_STOR)
	{
		HUD_nmessages = HUD_MAX_NUM_STOR; // unnecessary but just in case it might be bigger... which is impossible
		for (i = 0; i < HUD_nmessages-1; i++) 
		{
			memcpy(&HUD_messages[i], &HUD_messages[i+1], sizeof(struct hudmsg));
		}
	}
	else
	{
		HUD_nmessages++;
	}
	if (class_flag != HM_CONSOLE)
	{
		snprintf(HUD_messages[HUD_nmessages-1].message, sizeof(char)*HUD_MESSAGE_LENGTH, "%s", message);
		if (HUD_nmessages-HUD_MAX_NUM_DISP < 0)
			HUD_messages[HUD_nmessages-1].time = F1_0*3; // one message - display 3 secs
		else
			for (i = HUD_nmessages-HUD_MAX_NUM_DISP, j = 1; i < HUD_nmessages; i++, j++) // multiple messages - display 2 seconds each
				HUD_messages[i].time = F1_0*(j*2);
	}
	
	// jinx 02-16-13 console
	
	time_t now;
	struct tm *current;
	now = time(0);
	current = localtime(&now);

	char h[5];
	char m[5];
	char s[5];
	
	if (class_flag != HM_CONSOLE)
		snprintf(HUD_messages[HUD_nmessages-1].message, sizeof(char)*HUD_MESSAGE_LENGTH, "%s", message);
	
	if (current->tm_hour <= 9) 
		sprintf(h, "0%d", current->tm_hour);
	if (current->tm_hour > 9)
		sprintf(h, "%d", current->tm_hour);
	if (current->tm_min <= 9) 
		sprintf(m, "0%d", current->tm_min);
	if (current->tm_min > 9)
		sprintf(m, "%d", current->tm_min);
	if (current->tm_sec <= 9) 
		sprintf(s, "0%d", current->tm_sec);
	if (current->tm_sec > 9)
		sprintf(s, "%d", current->tm_sec);
	
	if (HUD_color == -1)
		HUD_color = BM_XRGB(0,28,0);
		
	if (HUD_color == -1)
		HUD_color = BM_XRGB(0,28,0);
	con_printf(CON_HUD, "[%s:%s:%s] %s\n", h, m, s, message);
	
	// jinx 02-16-13 console

	if (Newdemo_state == ND_STATE_RECORDING )
		newdemo_record_hud_message( message );

	return 1;
}