Exemplo n.º 1
0
// weapon list changed
void player_start_editor::OnSelchangeWeaponList() 
{
	int selected;
	int wi_index;
	char weapon_name[255] = "";
	char weapon_usage_buff[10];

	// If the weapon list is selected the variable weapon list shouldn't be
	m_weapon_variable_list.SetCurSel(-1);

	// determine if we've selected something
	selected = m_weapon_list.GetCurSel();	
	if (selected != -1) {
		// lookup the weapon
		m_weapon_list.GetText(selected, weapon_name);
		wi_index = weapon_info_lookup(weapon_name);

		// if we have a valid ship type
		if(wi_index >= 0){
			// if this item is checked
			if(m_weapon_list.GetCheck(selected)) {								
				if (static_weapon_variable_pool[selected_team][wi_index] == -1) {
					if (static_weapon_pool[selected_team][wi_index] <= 0){
						static_weapon_pool[selected_team][wi_index] = 100;
					}
					m_weapon_pool = static_weapon_pool[selected_team][wi_index];
					// Set the combo reflect that we are not using variables for this weapon
					m_weapon_quantity_variable.SetCurSel(0); 	
				}
				// If the number of ships was set by a variable
				else {
					Assert (Sexp_variables[static_weapon_variable_pool[selected_team][wi_index]].type & SEXP_VARIABLE_NUMBER);

					m_weapon_pool = atoi(Sexp_variables[static_weapon_variable_pool[selected_team][wi_index]].text);
					int selected_variable = sexp_variable_typed_count(static_weapon_variable_pool[selected_team][wi_index], SEXP_VARIABLE_NUMBER);
					m_weapon_quantity_variable.SetCurSel(selected_variable + 1);
				}
			} 
			// otherwise zero the count
			else {
				static_weapon_pool[selected_team][wi_index] = 0;				
				static_weapon_variable_pool[selected_team][wi_index] = -1;
				m_weapon_pool = 0;
				m_weapon_quantity_variable.SetCurSel(0); 	
			}
		
			// set the number used in wings
			sprintf(weapon_usage_buff, "%d", weapon_usage[selected_team][wi_index]); 
			m_weapons_used_in_wings.SetWindowText(weapon_usage_buff); 
	
		} else {
			Int3();
		}
	}
		
	// update stuff
	UpdateData(FALSE);
}
Exemplo n.º 2
0
// Returns the weapon_info index of the selected and checked ship_list item or -1 if nothing is checked or 
// the weapon is invalid
int player_start_editor::GetSelectedWeaponListIndex()
{
	char name[255] = "";
	int selected = m_weapon_list.GetCurSel();	
	if((selected != -1) && m_weapon_list.GetCheck(selected))
	{
		// lookup the weapon
		m_weapon_list.GetText(m_weapon_list.GetCurSel(), name);
		int weapon_index = weapon_info_lookup(name);
		return weapon_index;
	}
	return -1; 
}
// weapon pool count change
void player_start_editor::OnUpdateWeaponPool() 
{
	int selected, wi_index;
	char weapon_name[255] = "";

	if (!dlg_inited){
		return;
	}

	UpdateData(TRUE);	
	
	// if we have a ship selected and checked, update the pool	
	selected = m_weapon_list.GetCurSel();	
	if((selected != -1) && m_weapon_list.GetCheck(selected)){
		// lookup the ship
		m_weapon_list.GetText(m_weapon_list.GetCurSel(), weapon_name);
		wi_index = weapon_info_lookup(weapon_name);

		// if we have a valid ship type
		if(wi_index >= 0){
			weapon_pool[selected_team][wi_index] = m_weapon_pool;
		}
	};
}
Exemplo n.º 4
0
void pilotfile::csg_read_info()
{
	char t_string[NAME_LENGTH+1] = { '\0' };
	index_list_t ilist;
	int idx, list_size = 0;
	ubyte allowed = 0;

	if ( !m_have_flags ) {
		throw "Info before Flags!";
	}

	//
	// NOTE: lists may contain missing/invalid entries for current data
	//       this is not necessarily fatal
	//

	// ship list (NOTE: may contain more than MAX_SHIP_CLASSES)
	list_size = cfread_int(cfp);

	for (idx = 0; idx < list_size; idx++) {
		cfread_string_len(t_string, NAME_LENGTH, cfp);

		ilist.name = t_string;
		ilist.index = ship_info_lookup(t_string);

		ship_list.push_back(ilist);
	}

	// weapon list (NOTE: may contain more than MAX_WEAPON_TYPES)
	list_size = cfread_int(cfp);

	for (idx = 0; idx < list_size; idx++) {
		cfread_string_len(t_string, NAME_LENGTH, cfp);

		ilist.name = t_string;
		ilist.index = weapon_info_lookup(t_string);

		weapon_list.push_back(ilist);
	}

	// intel list (NOTE: may contain more than MAX_INTEL_ENTRIES)
	list_size = cfread_int(cfp);

	for (idx = 0; idx < list_size; idx++) {
		cfread_string_len(t_string, NAME_LENGTH, cfp);

		ilist.name = t_string;
		ilist.index = intel_info_lookup(t_string);

		intel_list.push_back(ilist);
	}

	// medals list (NOTE: may contain more than Num_medals)
	list_size = cfread_int(cfp);

	for (idx = 0; idx < list_size; idx++) {
		cfread_string_len(t_string, NAME_LENGTH, cfp);

		ilist.name = t_string;
		ilist.index = medals_info_lookup(t_string);

		medals_list.push_back(ilist);
	}

	// last ship flown (index into ship_list)
	idx = cfread_int(cfp);

	// check the idx is within bounds
	Assertion ((idx < (int)ship_list.size()), "Campaign file contains an incorrect value for the last flown ship class. No data in ship_list for ship number %d.", idx); 
	if (idx >= (int)ship_list.size())
		idx = -1;
	else if (idx != -1)
		p->last_ship_flown_si_index = ship_list[idx].index;
	else
		p->last_ship_flown_si_index = -1;

	// progression state
	Campaign.prev_mission = cfread_int(cfp);
	Campaign.next_mission = cfread_int(cfp);

	// loop state
	Campaign.loop_reentry = cfread_int(cfp);
	Campaign.loop_enabled = cfread_int(cfp);

	// missions completed
	Campaign.num_missions_completed = cfread_int(cfp);

	// allowed ships
	list_size = (int)ship_list.size();
	for (idx = 0; idx < list_size; idx++) {
		allowed = cfread_ubyte(cfp);

		if (allowed) {
			if (ship_list[idx].index >= 0) {
				Campaign.ships_allowed[ship_list[idx].index] = 1;
			} else {
				m_data_invalid = true;
			}
		}
	}

	// allowed weapons
	list_size = (int)weapon_list.size();
	for (idx = 0; idx < list_size; idx++) {
		allowed = cfread_ubyte(cfp);

		if (allowed) {
			if (weapon_list[idx].index >= 0) {
				Campaign.weapons_allowed[weapon_list[idx].index] = 1;
			} else {
				m_data_invalid = true;
			}
		}
	}

	if (csg_ver >= 2) {
		// single/campaign squad name & image
		cfread_string_len(p->s_squad_name, NAME_LENGTH, cfp);
		cfread_string_len(p->s_squad_filename, MAX_FILENAME_LEN, cfp);
	}

	// if anything we need/use was missing then it should be considered fatal
	if (m_data_invalid) {
		throw "Invalid data for CSG!";
	}
}
Exemplo n.º 5
0
void parse_ssm(const char *filename)
{
	char weapon_name[NAME_LENGTH];

	try
	{
		read_file_text(filename, CF_TYPE_TABLES);
		reset_parse();

		// parse the table
		while(required_string_either("#end", "$SSM:")) {
			required_string("$SSM:");
			ssm_info s;
			int string_index;

			// name
			stuff_string(s.name, F_NAME, NAME_LENGTH);
			if (*s.name == 0) {
				sprintf(s.name, "SSM " SIZE_T_ARG, Ssm_info.size());
				mprintf(("Found an SSM entry without a name.  Assigning \"%s\".\n", s.name));
			}

			// stuff data
			required_string("+Weapon:");
			stuff_string(weapon_name, F_NAME, NAME_LENGTH);

			string_index = optional_string_either("+Count:", "+Min Count:");
			if (string_index == 0) {
				stuff_int(&s.count);
				s.max_count = -1;
			} else if (string_index == 1) {
				stuff_int(&s.count);
				required_string("+Max Count:");
				stuff_int(&s.max_count);
			} else {
				s.count = 1;
				s.max_count = -1;
			}

			required_string("+WarpRadius:");
			stuff_float(&s.warp_radius);

			if (optional_string("+WarpTime:")) {
				stuff_float(&s.warp_time);
				// According to fireballs.cpp, "Warp lifetime must be at least 4 seconds!"
				if ( (s.warp_time) < 4.0f) {
					// So let's warn them before they try to use it, shall we?
					Warning(LOCATION, "Expected a '+WarpTime:' value equal or greater than 4.0, found '%f' in weapon '%s'.\n Setting to 4.0, please check and set to a number 4.0 or greater!\n", s.warp_time, weapon_name);
					// And then make the Assert obsolete -- Zacam
					s.warp_time = 4.0f;
				}
			} else {
				s.warp_time = 4.0f;
			}

			string_index = required_string_either("+Radius:", "+Min Radius:");
			if (string_index == 0) {
				required_string("+Radius:");
				stuff_float(&s.radius);
				s.max_radius = -1.0f;
			} else {
				required_string("+Min Radius:");
				stuff_float(&s.radius);
				required_string("+Max Radius:");
				stuff_float(&s.max_radius);
			}

			string_index = optional_string_either("+Offset:", "+Min Offset:");
			if (string_index == 0) {
				stuff_float(&s.offset);
				s.max_offset = -1.0f;
			} else if (string_index == 1) {
				stuff_float(&s.offset);
				required_string("+Max Offset:");
				stuff_float(&s.max_offset);
			} else {
				s.offset = 0.0f;
				s.max_offset = -1.0f;
			}
			
			if (optional_string("+Shape:")) {
				switch(required_string_one_of(3, "Point", "Circle", "Sphere")) {
				case 0:
					required_string("Point");
					s.shape = SSM_SHAPE_POINT;
					break;
				case 1:
					required_string("Circle");
				case -1:	// If we're ignoring parse errors and can't identify the shape, go with a circle.
					s.shape = SSM_SHAPE_CIRCLE;
					break;
				case 2:
					required_string("Sphere");
					s.shape = SSM_SHAPE_SPHERE;
					break;
				default:
					Assertion(false, "Impossible return value from required_string_one_of(); get a coder!\n");
				}
			} else {
				s.shape = SSM_SHAPE_CIRCLE;
			}

			if (optional_string("+HUD Message:"))
				stuff_boolean(&s.send_message);
			else
				s.send_message = true;

			if (optional_string("+Custom Message:")) {
				stuff_string(s.message, F_NAME, NAME_LENGTH);
				s.use_custom_message = true;
			}

			s.sound_index = -1;
			parse_sound("+Alarm Sound:", &s.sound_index, s.name);

			// see if we have a valid weapon
			s.weapon_info_index = weapon_info_lookup(weapon_name);
			if(s.weapon_info_index >= 0) {
				// valid
				int existing = ssm_info_lookup(s.name);
				if (existing >= 0) {	// Redefined the existing entry instead of adding a duplicate.
					Ssm_info[existing] = s;
				} else {
					Ssm_info.push_back(s);
				}
			}
		}
	}
	catch (const parse::ParseException& e)
	{
		mprintf(("TABLES: Unable to parse '%s'!  Error message = %s.\n", filename, e.what()));
		return;
	}
}
Exemplo n.º 6
0
// ok
void player_start_editor::OnOK()
{
	int i, idx;
	int num_choices; 
	
	int num_sexp_variables = sexp_variable_count();	

	// store player entry time delay
	Entry_delay_time = i2f(m_delay);	

	// store ship pools	
	for(i=0; i<MAX_TVT_TEAMS; i++) {
		num_choices = 0; 
		// First look through the variables list and write out anything there
		for (idx=0; idx < num_sexp_variables; idx++) 		{
			// As soon as we come across a sexp_variable we are using
			if (dynamic_ship_pool[i][idx] != -1) 			{
				Assert (Sexp_variables[idx].type & SEXP_VARIABLE_STRING); 
				int ship_class = ship_info_lookup(Sexp_variables[idx].text);
				
				// If the variable doesn't actually contain a valid ship class name. Warn the user and skip to the next one
				if (ship_class < 0)  {
					char buffer[256];
					sprintf(buffer, 
							"Sexp Variable %s holds the value %s. This is not a valid ship class. Skipping this entry",
							Sexp_variables[idx].variable_name,
							Sexp_variables[idx].text
							);
					MessageBox(buffer);
					continue;
				}
				
				/* Can we can prevent the user from having to enter all his variables again just cause he can't spull gud?
				// If the variable doesn't actually contain a valid ship class name. Warn the user
				if (ship_class < 0)
				{
					char buffer[256];
					sprintf(buffer, 
							"Sexp Variable %s holds the value %s. This is not a valid ship class. You should change this!",
							Sexp_variables[idx].variable_name,
							Sexp_variables[idx].text
							);
					MessageBox(buffer);
					ship_class = ship_info_lookup(default_player_ship);
					if (ship_class < 0 ) {
						sprintf(buffer, "No default ship is set either. Skipping variable %s!", Sexp_variables[idx].variable_name); 
					}
				}*/


				// Copy the variable to Team_data
				Team_data[i].ship_list_variables[num_choices] = idx;
				Team_data[i].ship_list[num_choices] = -1;

				// Now we need to set the number of this type available
				if (dynamic_ship_variable_pool[i][idx] == -1) {
					Team_data[i].ship_count[num_choices] = dynamic_ship_pool[i][idx];
					Team_data[i].ship_count_variables[num_choices] = -1; 
				}
				else {
					Assert (Sexp_variables[dynamic_ship_variable_pool[i][idx]].type & SEXP_VARIABLE_NUMBER);

					Team_data[i].ship_count_variables[num_choices] = dynamic_ship_variable_pool[i][idx];
					Team_data[i].ship_count[num_choices] = atoi(Sexp_variables[dynamic_ship_variable_pool[i][idx]].text);
				}

				num_choices++;
			}
		}

		// Now we deal with the loadout ships that are statically assigned by class

		for(idx=0; idx<Num_ship_classes; idx++) {
			// if we have ships here
			if(static_ship_pool[i][idx] > 0 || static_ship_variable_pool[i][idx] > -1) {
				Team_data[i].ship_list[num_choices] = idx;
				Team_data[i].ship_list_variables[num_choices] = -1;

				// Now set the number of this class available
				if (static_ship_variable_pool[i][idx] == -1) {
					Team_data[i].ship_count[num_choices] = static_ship_pool[i][idx];
					Team_data[i].ship_count_variables[num_choices] = -1;
				}
				else {
					Assert (Sexp_variables[static_ship_variable_pool[i][idx]].type & SEXP_VARIABLE_NUMBER);
					
					Team_data[i].ship_count_variables[num_choices] = static_ship_variable_pool[i][idx];
					Team_data[i].ship_count[num_choices] = atoi(Sexp_variables[static_ship_variable_pool[i][idx]].text);
				}

				num_choices++;
			}
		}
		Team_data[i].num_ship_choices = num_choices; 
	}

	// store weapon pools
	for(i=0; i<MAX_TVT_TEAMS; i++){		
		num_choices = 0; 

		// First look through the variables list and write out anything there
		for (idx=0; idx < num_sexp_variables; idx++) {
			// As soon as we come across a sexp_variable we are using
			if (dynamic_weapon_pool[i][idx] != -1) {
				Assert (Sexp_variables[idx].type & SEXP_VARIABLE_STRING); 
				int weapon_class = weapon_info_lookup(Sexp_variables[idx].text);
				
				// If the variable doesn't actually contain a valid ship class name. Warn the user and skip to the next one
				if (weapon_class < 0)
				{
					char buffer[256];
					sprintf(buffer, 
							"Sexp Variable %s holds the value %s. This is not a valid weapon class. Skipping this entry",
							Sexp_variables[idx].variable_name,
							Sexp_variables[idx].text
							);
					MessageBox(buffer);
					continue;
				}
				
				// Copy the variable to Team_data
				Team_data[i].weaponry_pool_variable[num_choices] = idx;
				Team_data[i].weaponry_pool[num_choices] = -1;

				// Now we need to set the number of this class available
				if (dynamic_weapon_variable_pool[i][idx] == -1)
				{
					Team_data[i].weaponry_count[num_choices] = dynamic_weapon_pool[i][idx];
					Team_data[i].weaponry_amount_variable[num_choices] = -1; 
				}
				else 
				{
					Assert (Sexp_variables[dynamic_weapon_variable_pool[i][idx]].type & SEXP_VARIABLE_NUMBER);

					Team_data[i].weaponry_amount_variable[num_choices] = dynamic_weapon_variable_pool[i][idx];
					Team_data[i].weaponry_count[num_choices] = atoi(Sexp_variables[dynamic_weapon_variable_pool[i][idx]].text);
				}

				num_choices++;
			}
		}

		// Now we deal with the loadout weapons that are statically assigned by class

		for(idx=0; idx<Num_weapon_types; idx++)
		{
			// if we have weapons here
			if(static_weapon_pool[i][idx] > 0 || static_weapon_variable_pool[i][idx] > -1)
			{
				Team_data[i].weaponry_pool[num_choices] = idx;
				Team_data[i].weaponry_pool_variable[num_choices] = -1;

				// Now set the number of this class available
				if (static_weapon_variable_pool[i][idx] == -1)
				{
					Team_data[i].weaponry_count[num_choices] = static_weapon_pool[i][idx];
					Team_data[i].weaponry_amount_variable[num_choices] = -1;
				}
				else 
				{
					Assert (Sexp_variables[static_weapon_variable_pool[i][idx]].type & SEXP_VARIABLE_NUMBER);
					
					Team_data[i].weaponry_amount_variable[num_choices] = static_weapon_variable_pool[i][idx];
					Team_data[i].weaponry_count[num_choices] = atoi(Sexp_variables[static_weapon_variable_pool[i][idx]].text);
				}

				num_choices++;
			}
		}
		Team_data[i].num_weapon_choices = num_choices; 
	}

	theApp.record_window_data(&Player_wnd_data, this);
	CDialog::OnOK();
}
Exemplo n.º 7
0
void pilotfile_convert::csg_import_ships_weapons()
{
	index_list_t ilist;
	char name[35];
	int idx;
	int list_size = 0;

	int ship_count = cfread_int(cfp);
	int weap_count = cfread_int(cfp);

	for (idx = 0; idx < ship_count; idx++) {
		ubyte allowed = cfread_ubyte(cfp);
		csg->ships_allowed.push_back( (allowed != 0) );

		cfread_string_len(name, sizeof(name), cfp);

		ilist.name = name;
		ilist.index = ship_info_lookup(name);

		if (ilist.index < 0) {
			std::ostringstream error_msg;
			error_msg << "Data mismatch (ship lookup: " << ilist.name << ")!";
			throw std::runtime_error(error_msg.str().c_str());
		}

		csg->ship_list.push_back( ilist );
	}

	for (idx = 0; idx < weap_count; idx++) {
		ubyte allowed = cfread_ubyte(cfp);
		csg->weapons_allowed.push_back( allowed != 0 );

		cfread_string_len(name, sizeof(name), cfp);

		ilist.name = name;
		ilist.index = weapon_info_lookup(name);

		if (ilist.index < 0) {
			std::ostringstream error_msg;
			error_msg << "Data mismatch (weapon lookup: " << ilist.name << ")!";
			throw std::runtime_error(error_msg.str().c_str());
		}

		csg->weapon_list.push_back( ilist );
	}

	// get last ship flown index
	for (idx = 0; idx < ship_count; idx++) {
		if ( csg->ship_list[idx].name == plr->last_ship_flown ) {
			csg->last_ship_flown_index = idx;
			break;
		}
	}

	if (csg->last_ship_flown_index < 0) {
		std::ostringstream error_msg;
		error_msg << "Data mismatch (player ship: " << csg->last_ship_flown_index << ")!";
		throw std::runtime_error(error_msg.str().c_str());
	}

	// create list of medals (since it's missing from the old files)
	list_size = Num_medals;

	for (idx = 0; idx < list_size; idx++) {
		ilist.name = Medals[idx].name;
		ilist.index = idx;

		csg->medals_list.push_back( ilist );
	}

	// stuff intel list as well (present but burried in old files)
	list_size = Intel_info_size;

	for (idx = 0; idx < list_size; idx++) {
		ilist.name = Intel_info[idx].name;
		ilist.index = idx;

		csg->intel_list.push_back( ilist );
	}
}
Exemplo n.º 8
0
// game init
void ssm_init()
{	
	int rval;
	ssm_info bogus, *s;
	char weapon_name[NAME_LENGTH];

	if ((rval = setjmp(parse_abort)) != 0) {
		mprintf(("TABLES: Unable to parse '%s'!  Error code = %i.\n", "ssm.tbl", rval));
		return;
	}

	read_file_text("ssm.tbl", CF_TYPE_TABLES);
	reset_parse();

	// parse the table
	Ssm_info_count = 0;
	while(!optional_string("#end")){
		// another ssm definition
		if(optional_string("$SSM:")){
			// pointer to info struct
			if(Ssm_info_count >= MAX_SSM_TYPES){
				s = &bogus;
			} else {
				s = &Ssm_info[Ssm_info_count];
			}

			// name
			stuff_string(s->name, F_NAME, NAME_LENGTH);

			// stuff data
			required_string("+Weapon:");
			stuff_string(weapon_name, F_NAME, NAME_LENGTH);
			required_string("+Count:");
			stuff_int(&s->count);
			required_string("+WarpRadius:");
			stuff_float(&s->warp_radius);
			required_string("+WarpTime:");
			stuff_float(&s->warp_time);
			// According to fireballs.cpp, "Warp lifetime must be at least 4 seconds!"
			if ( (s->warp_time) < 4.0f) {
				// So let's warn them before they try to use it, shall we?
				Warning(LOCATION, "Expected a '+WarpTime:' value equal or greater than 4.0, found '%f' in weapon '%s'.\n Setting to 4.0, please check and set to a number 4.0 or greater!\n", s->warp_time, weapon_name);
				// And then make the Assert obsolete -- Zacam
				s->warp_time = 4.0f;
			}
			required_string("+Radius:");
			stuff_float(&s->radius);
			required_string("+Offset:");
			stuff_float(&s->offset);
			if (optional_string("+HUD Message:")) 
				stuff_boolean(&s->send_message);
			else
				s->send_message = true;
			if (optional_string("+Custom Message:")) {
				stuff_string(s->message, F_NAME, NAME_LENGTH);
				s->use_custom_message = true;
			}

			// see if we have a valid weapon
			s->weapon_info_index = -1;
			s->weapon_info_index = weapon_info_lookup(weapon_name);
			if(s->weapon_info_index >= 0){
				// valid
				Ssm_info_count++;
			}
		}
	}
}