// Updates the currently selected list entry void AltShipClassDlg::alt_class_update_entry(alt_class &list_item) { int index; // Add a string variable to the list if (num_string_variables && m_set_from_variables.GetCurSel() > 0) { index = string_variable_indices[m_set_from_variables.GetCurSel() -1]; Assert (index >= 0); list_item.variable_index = index; list_item.ship_class = ship_info_lookup(Sexp_variables[index].text); } // Add a ship class to the list else { index = m_set_from_ship_class.GetCurSel(); // Correct the index if the first entry isn't actually a ship class if (num_string_variables) { Assert (index > 0); index--; } list_item.variable_index = -1; list_item.ship_class = ship_class_indices[index]; } // check the default tickbox list_item.default_to_this_class = m_default_to_class.GetCheck() ? true:false; }
// ship list changed void player_start_editor::OnSelchangeShipList() { int selected; int si_index; char ship_name[255] = ""; char ship_usage_buff[10]; // If the ship list is selected the variable ship list should be deselected m_ship_variable_list.SetCurSel(-1); // determine if we've selected something selected = m_ship_list.GetCurSel(); if (selected != -1) { // lookup the ship m_ship_list.GetText(selected, ship_name); si_index = ship_info_lookup(ship_name); // if we have a valid ship type if(si_index >= 0){ // if this item is checked if(m_ship_list.GetCheck(selected)) { if (static_ship_variable_pool[selected_team][si_index] == -1) { if (static_ship_pool[selected_team][si_index] <= 0){ static_ship_pool[selected_team][si_index] = 5; } m_ship_pool = static_ship_pool[selected_team][si_index]; // Set the ship variable ComboBox to reflect that we are not using variables for this ship m_ship_quantity_variable.SetCurSel(0); } // If the number of ships was set by a variable else { Assert (Sexp_variables[static_ship_variable_pool[selected_team][si_index]].type & SEXP_VARIABLE_NUMBER); m_ship_pool = atoi(Sexp_variables[static_ship_variable_pool[selected_team][si_index]].text); int selected_variable = sexp_variable_typed_count(static_ship_variable_pool[selected_team][si_index], SEXP_VARIABLE_NUMBER); m_ship_quantity_variable.SetCurSel(selected_variable + 1); } } // otherwise zero the count else { static_ship_pool[selected_team][si_index] = 0; static_ship_variable_pool[selected_team][si_index] = -1; m_ship_pool = 0; m_ship_quantity_variable.SetCurSel(0); } // set the number used in wings sprintf(ship_usage_buff, "%d", ship_usage[selected_team][si_index]); m_ships_used_in_wings.SetWindowText(ship_usage_buff); } else { Int3(); } } // update stuff UpdateData(FALSE); }
// Returns the ship_info index of the selected and checked ship_list item or -1 if nothing is checked or // the ship is invalid int player_start_editor::GetSelectedShipListIndex() { char name[255] = ""; int selected = m_ship_list.GetCurSel(); if((selected != -1) && m_ship_list.GetCheck(selected)) { // lookup the ship m_ship_list.GetText(m_ship_list.GetCurSel(), name); int ship_index = ship_info_lookup(name); return ship_index; } return -1; }
// ship list changed void player_start_editor::OnSelchangeShipList() { int selected; int si_index; char ship_name[255] = ""; // determine if we've selected something selected = m_ship_list.GetCurSel(); if (selected != -1) { // lookup the ship m_ship_list.GetText(m_ship_list.GetCurSel(), ship_name); si_index = ship_info_lookup(ship_name); // if we have a valid ship type if(si_index >= 0){ // if this item is checked if(m_ship_list.GetCheck(selected)) { if(ship_pool[selected_team][si_index] <= 0){ ship_pool[selected_team][si_index] = 5; m_ship_pool = 5; } else { m_ship_pool = ship_pool[selected_team][si_index]; } } // otherwise zero the count else { ship_pool[selected_team][si_index] = 0; m_ship_pool = 0; } } else { Int3(); } } // update shtuff UpdateData(FALSE); }
// ship pool count change void player_start_editor::OnUpdateShipPool() { int selected, si_index; char ship_name[255] = ""; if (!dlg_inited){ return; } UpdateData(TRUE); // if we have a ship selected and checked, update the pool selected = m_ship_list.GetCurSel(); if((selected != -1) && m_ship_list.GetCheck(selected)){ // lookup the ship m_ship_list.GetText(m_ship_list.GetCurSel(), ship_name); si_index = ship_info_lookup(ship_name); // if we have a valid ship type if(si_index >= 0){ ship_pool[selected_team][si_index] = m_ship_pool; } }; }
int color_combo_box::GetCurSelNEW() { int cur_sel; int ship_info; char ship_name[256]; char *hmmm = ship_name; // see if we have a special item (>= Num_ship_types) cur_sel = GetCurSel(); if(cur_sel >= Num_ship_types){ return cur_sel; } // otherwise lookup the ship by name memset(ship_name, 0, 256); if(GetLBText(cur_sel, hmmm) == CB_ERR){ return CB_ERR; } ship_info = ship_info_lookup(ship_name); if((ship_info < 0) || (ship_info >= Num_ship_types)){ return CB_ERR; } return ship_info; }
// evaluate a kill on a ship int scoring_eval_kill(object *ship_objp) { float max_damage_pct; // the pct% of total damage the max damage object did int max_damage_index; // the index into the dying ship's damage_ship[] array corresponding the greatest amount of damage int killer_sig; // signature of the guy getting credit for the kill (or -1 if none) int idx,net_player_num; player *plr; // pointer to a player struct if it was a player who got the kill net_player *net_plr = NULL; ship *dead_ship; // the ship which was killed net_player *dead_plr = NULL; float scoring_scale_by_damage = 1; // percentage to scale the killer's score by if we score based on the amount of damage caused int kill_score, assist_score; bool is_enemy_player = false; // true if the player just killed an enemy player ship // multiplayer clients bail here if(MULTIPLAYER_CLIENT){ return -1; } // we don't evaluate kills on anything except ships if(ship_objp->type != OBJ_SHIP){ return -1; } if((ship_objp->instance < 0) || (ship_objp->instance >= MAX_SHIPS)){ return -1; } // assign the dead ship dead_ship = &Ships[ship_objp->instance]; // evaluate player deaths if(Game_mode & GM_MULTIPLAYER){ net_player_num = multi_find_player_by_object(ship_objp); if(net_player_num != -1){ Net_players[net_player_num].m_player->stats.m_player_deaths++; nprintf(("Network","Setting player %s deaths to %d\n",Net_players[net_player_num].m_player->callsign,Net_players[net_player_num].m_player->stats.m_player_deaths)); dead_plr = &Net_players[net_player_num]; is_enemy_player = true; } } else { if(ship_objp == Player_obj){ Player->stats.m_player_deaths++; } } net_player_num = -1; // clear out invalid damager ships for(idx=0; idx<MAX_DAMAGE_SLOTS; idx++){ if((dead_ship->damage_ship_id[idx] >= 0) && (ship_get_by_signature(dead_ship->damage_ship_id[idx]) < 0)){ dead_ship->damage_ship[idx] = 0.0f; dead_ship->damage_ship_id[idx] = -1; } } // determine which object did the most damage to the dying object, and how much damage that was max_damage_index = -1; for(idx=0;idx<MAX_DAMAGE_SLOTS;idx++){ // bogus ship if(dead_ship->damage_ship_id[idx] < 0){ continue; } // if this slot did more damage then the next highest slot if((max_damage_index == -1) || (dead_ship->damage_ship[idx] > dead_ship->damage_ship[max_damage_index])){ max_damage_index = idx; } } // doh if((max_damage_index < 0) || (max_damage_index >= MAX_DAMAGE_SLOTS)){ return -1; } // the pct of total damage applied to this ship max_damage_pct = dead_ship->damage_ship[max_damage_index] / dead_ship->total_damage_received; CLAMP(max_damage_pct, 0.0f, 1.0f); // only evaluate if the max damage % is high enough to record a kill and it was done by a valid object if((max_damage_pct >= Kill_percentage) && (dead_ship->damage_ship_id[max_damage_index] >= 0)){ // set killer_sig for this ship to the signature of the guy who gets credit for the kill killer_sig = dead_ship->damage_ship_id[max_damage_index]; // set the scale value if we only award 100% score for 100% damage if (The_mission.ai_profile->flags & AIPF_KILL_SCORING_SCALES_WITH_DAMAGE) { scoring_scale_by_damage = max_damage_pct; } // null this out for now plr = NULL; net_plr = NULL; // get the player (whether single or multiplayer) net_player_num = -1; if(Game_mode & GM_MULTIPLAYER){ net_player_num = multi_find_player_by_signature(killer_sig); if(net_player_num != -1){ plr = Net_players[net_player_num].m_player; net_plr = &Net_players[net_player_num]; } } else { if(Objects[Player->objnum].signature == killer_sig){ plr = Player; } } // if we found a valid player, evaluate some kill details if(plr != NULL){ int si_index; // bogus if((plr->objnum < 0) || (plr->objnum >= MAX_OBJECTS)){ return -1; } // get the ship info index of the ship type of this kill. we need to take ship // copies into account here. si_index = dead_ship->ship_info_index; if (Ship_info[si_index].flags & SIF_SHIP_COPY) { char temp[NAME_LENGTH]; strcpy_s(temp, Ship_info[si_index].name); end_string_at_first_hash_symbol(temp); // Goober5000 - previous error checking guarantees that this will be >= 0 si_index = ship_info_lookup(temp); } // if he killed a guy on his own team increment his bonehead kills if((Ships[Objects[plr->objnum].instance].team == dead_ship->team) && !MULTI_DOGFIGHT ){ if (!(The_mission.flags & MISSION_FLAG_NO_TRAITOR)) { plr->stats.m_bonehead_kills++; kill_score = -(int)(dead_ship->score * scoring_get_scale_factor()); plr->stats.m_score += kill_score; if(net_plr != NULL ) { multi_team_maybe_add_score(-(dead_ship->score), net_plr->p_info.team); } } } // otherwise increment his valid kill count and score else { // dogfight mode if(MULTI_DOGFIGHT && (multi_find_player_by_object(ship_objp) < 0)){ // don't add a kill for dogfight kills on non-players } else { plr->stats.m_okKills[si_index]++; plr->stats.m_kill_count_ok++; // only computer controlled enemies should scale with difficulty if (is_enemy_player) { kill_score = (int)(dead_ship->score * scoring_scale_by_damage); } else { kill_score = (int)(dead_ship->score * scoring_get_scale_factor() * scoring_scale_by_damage); } plr->stats.m_score += kill_score; hud_gauge_popup_start(HUD_KILLS_GAUGE); #ifdef SCORING_DEBUG char kill_score_text[1024] = ""; sprintf(kill_score_text, "SCORING : %s killed a ship worth %d points and gets %d pts for the kill\n", plr->callsign, dead_ship->score, kill_score); if (MULTIPLAYER_MASTER) { send_game_chat_packet(Net_player, kill_score_text, MULTI_MSG_ALL); } HUD_printf(kill_score_text); mprintf((kill_score_text)); #endif // multiplayer if(net_plr != NULL){ multi_team_maybe_add_score(dead_ship->score , net_plr->p_info.team); // award teammates % of score value for big ship kills // not in dogfight tho // and not if there is no assist threshold (as otherwise assists could get higher scores than kills) if (!(Netgame.type_flags & NG_TYPE_DOGFIGHT) && (Ship_info[dead_ship->ship_info_index].flags & (SIF_BIG_SHIP | SIF_HUGE_SHIP))) { for (idx=0; idx<MAX_PLAYERS; idx++) { if (MULTI_CONNECTED(Net_players[idx]) && (Net_players[idx].p_info.team == net_plr->p_info.team) && (&Net_players[idx] != net_plr)) { assist_score = (int)(dead_ship->score * The_mission.ai_profile->assist_award_percentage_scale[Game_skill_level]); Net_players[idx].m_player->stats.m_score += assist_score; #ifdef SCORING_DEBUG // DEBUG CODE TO TEST NEW SCORING char score_text[1024] = ""; sprintf(score_text, "SCORING : All team mates get %d pts for helping kill the capship\n", assist_score); send_game_chat_packet(Net_player, score_text, MULTI_MSG_ALL); HUD_printf(score_text); mprintf((score_text)); #endif } } } // death message if((Net_player != NULL) && (Net_player->flags & NETINFO_FLAG_AM_MASTER) && (net_plr != NULL) && (dead_plr != NULL) && (net_plr->m_player != NULL) && (dead_plr->m_player != NULL)){ char dead_text[1024] = ""; sprintf(dead_text, "%s gets the kill for %s", net_plr->m_player->callsign, dead_plr->m_player->callsign); send_game_chat_packet(Net_player, dead_text, MULTI_MSG_ALL, NULL, NULL, 2); HUD_printf(dead_text); } } } } // increment his all-encompassing kills plr->stats.m_kills[si_index]++; plr->stats.m_kill_count++; // update everyone on this guy's kills if this is multiplayer if(MULTIPLAYER_MASTER && (net_player_num != -1)){ // send appropriate stats if(Netgame.type_flags & NG_TYPE_DOGFIGHT){ // evaluate dogfight kills multi_df_eval_kill(&Net_players[net_player_num], ship_objp); // update stats send_player_stats_block_packet(&Net_players[net_player_num], STATS_DOGFIGHT_KILLS); } else { send_player_stats_block_packet(&Net_players[net_player_num], STATS_MISSION_KILLS); } } } } else { // set killer_sig for this ship to -1, indicating no one got the kill for it killer_sig = -1; } // pass in the guy who got the credit for the kill (if any), so that he doesn't also // get credit for an assist scoring_eval_assists(dead_ship,killer_sig, is_enemy_player); #ifdef SCORING_DEBUG if (Game_mode & GM_MULTIPLAYER) { char buf[256]; sprintf(Scoring_debug_text, "SCORING : %s killed.\nDamage by ship:\n\n", Ship_info[dead_ship->ship_info_index].name); // show damage done by player for (int i=0; i<MAX_DAMAGE_SLOTS; i++) { int net_player_num = multi_find_player_by_signature(dead_ship->damage_ship_id[i]); if (net_player_num != -1) { plr = Net_players[net_player_num].m_player; sprintf(buf, "%s: %f", plr->callsign, dead_ship->damage_ship[i]); if (dead_ship->damage_ship_id[i] == killer_sig ) { strcat_s(buf, " KILLER\n"); } else { strcat_s(buf, "\n"); } strcat_s(Scoring_debug_text, buf); } } mprintf ((Scoring_debug_text)); } #endif return max_damage_index; }
void pilotfile::plr_read_stats_multi() { int idx, j, list_size = 0; index_list_t ilist; char t_string[NAME_LENGTH+1]; // global, all-time stats (used only until campaign stats are loaded) multi_stats.score = cfread_int(cfp); multi_stats.rank = cfread_int(cfp); multi_stats.assists = cfread_int(cfp); multi_stats.kill_count = cfread_int(cfp); multi_stats.kill_count_ok = cfread_int(cfp); multi_stats.bonehead_kills = cfread_int(cfp); multi_stats.p_shots_fired = cfread_uint(cfp); multi_stats.p_shots_hit = cfread_uint(cfp); multi_stats.p_bonehead_hits = cfread_uint(cfp); multi_stats.s_shots_fired = cfread_uint(cfp); multi_stats.s_shots_hit = cfread_uint(cfp); multi_stats.s_bonehead_hits = cfread_uint(cfp); multi_stats.flight_time = cfread_uint(cfp); multi_stats.missions_flown = cfread_uint(cfp); multi_stats.last_flown = (_fs_time_t)cfread_int(cfp); multi_stats.last_backup = (_fs_time_t)cfread_int(cfp); // ship kills (contains ships across all mods, not just current) list_size = cfread_int(cfp); multi_stats.ship_kills.reserve(list_size); 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); ilist.val = cfread_int(cfp); multi_stats.ship_kills.push_back(ilist); } // medals earned (contains medals across all mods, not just current) list_size = cfread_int(cfp); multi_stats.medals_earned.reserve(list_size); 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); ilist.val = cfread_int(cfp); multi_stats.medals_earned.push_back(ilist); } // if in multiplayer mode then set these stats as the player stats if (Game_mode & GM_MULTIPLAYER) { p->stats.score = multi_stats.score; p->stats.rank = multi_stats.rank; p->stats.assists = multi_stats.assists; p->stats.kill_count = multi_stats.kill_count; p->stats.kill_count_ok = multi_stats.kill_count_ok; p->stats.bonehead_kills = multi_stats.bonehead_kills; p->stats.p_shots_fired = multi_stats.p_shots_fired; p->stats.p_shots_hit = multi_stats.p_shots_hit; p->stats.p_bonehead_hits = multi_stats.p_bonehead_hits; p->stats.s_shots_fired = multi_stats.s_shots_fired; p->stats.s_shots_hit = multi_stats.s_shots_hit; p->stats.s_bonehead_hits = multi_stats.s_bonehead_hits; p->stats.flight_time = multi_stats.flight_time; p->stats.missions_flown = multi_stats.missions_flown; p->stats.last_flown = multi_stats.last_flown; p->stats.last_backup = multi_stats.last_backup; // ship kills (have to find ones that match content) list_size = (int)multi_stats.ship_kills.size(); for (idx = 0; idx < list_size; idx++) { j = multi_stats.ship_kills[idx].index; if (j >= 0) { p->stats.kills[j] = multi_stats.ship_kills[idx].val; } } // medals earned (have to fine ones that match content) list_size = (int)multi_stats.medals_earned.size(); for (idx = 0; idx < list_size; idx++) { j = multi_stats.medals_earned[idx].index; if (j >= 0) { p->stats.medals[j] = multi_stats.medals_earned[idx].val; } } } }
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!"; } }
int FS2NetD_GetPlayerData(const char *player_name, player *pl, bool can_create, bool do_send) { int buffer_size, buffer_offset; bool my_packet = false; char buffer[16384]; if (do_send) { ubyte create = (ubyte)can_create; INIT_PACKET( PCKT_PILOT_GET ); PXO_ADD_INT( (can_create) ? Multi_tracker_id : -2 ); PXO_ADD_STRING( player_name ); PXO_ADD_DATA( create ); DONE_PACKET(); if ( FS2NetD_SendData(buffer, buffer_size) == -1 ) { return -1; } } else if ( FS2NetD_DataReady() ) { const fix end_time = timer_get_fixed_seconds() + (15 * F1_0); int rc; uint rc_total = 0; ubyte reply_type = 0; int si_index = 0; ushort bogus, num_type_kills = 0, num_medals = 0; char ship_name[NAME_LENGTH]; int idx; do { rc = FS2NetD_GetData(buffer+rc_total, sizeof(buffer)-rc_total); if (rc <= 0) { break; } rc_total += rc; Sleep(20); } while ( FS2NetD_DataReady() && (rc_total < (int)sizeof(buffer)) ); if (rc < BASE_PACKET_SIZE) { return -1; } VRFY_PACKET2( PCKT_PILOT_REPLY ); if ( !my_packet ) { return -1; } if ( buffer_size > (int)sizeof(buffer) ) { ml_printf("FS2NetD WARNING: Pilot update data is larger than receive buffer! Some data will be lost!"); } // make sure that we get the entire packet while ( (rc_total < (uint)buffer_size) && (rc_total < sizeof(buffer)) && (timer_get_fixed_seconds() <= end_time) ) { if ( FS2NetD_DataReady() ) { rc = FS2NetD_GetData(buffer+rc_total, sizeof(buffer) - rc_total); if (rc <= 0) { continue; } rc_total += rc; } Sleep(20); } PXO_GET_DATA( reply_type ); // if we weren't retrieved then bail out now if (reply_type != 0) { return (int)reply_type; } PXO_GET_INT( pl->stats.score ); // points PXO_GET_UINT( pl->stats.missions_flown ); // missions PXO_GET_UINT( pl->stats.flight_time ); // flighttime PXO_GET_INT( pl->stats.last_flown ); // LastFlight PXO_GET_INT( pl->stats.kill_count ); // Kills PXO_GET_INT( pl->stats.kill_count_ok ); // NonFriendlyKills PXO_GET_INT( pl->stats.assists ); // Assists PXO_GET_UINT( pl->stats.p_shots_fired ); // PriShots PXO_GET_UINT( pl->stats.p_shots_hit ); // PriHits PXO_GET_UINT( pl->stats.p_bonehead_hits ); // PriFHits PXO_GET_UINT( pl->stats.s_shots_fired ); // SecShots PXO_GET_UINT( pl->stats.s_shots_hit ); // SecHits PXO_GET_UINT( pl->stats.s_bonehead_hits ); // SecFHits PXO_GET_INT( pl->stats.rank ); // rank PXO_GET_USHORT( num_type_kills ); for (idx = 0; idx < (int)num_type_kills; idx++) { memset( ship_name, 0, sizeof(ship_name) ); PXO_GET_STRING( ship_name ); si_index = ship_info_lookup( ship_name ); if (si_index == -1) { PXO_GET_USHORT( bogus ); } else { PXO_GET_USHORT( pl->stats.kills[si_index] ); } } PXO_GET_USHORT( num_medals ); for (idx = 0; (idx < Num_medals) && (idx < num_medals); idx++) { PXO_GET_INT( pl->stats.medal_counts[idx] ); } return (int)reply_type; } return -1; }
// 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(); }
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 ); } }
void color_combo_box::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { int m_cyText = 24, z; CString strText; char ship_name[256]; // You must override DrawItem and MeasureItem for LBS_OWNERDRAWVARIABLE ASSERT((GetStyle() & (LBS_OWNERDRAWFIXED | CBS_HASSTRINGS)) == (LBS_OWNERDRAWFIXED | CBS_HASSTRINGS)); CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC); // I think we need to do a lookup by ship name here if(lpDrawItemStruct->itemID >= (uint)Num_ship_types){ z = lpDrawItemStruct->itemID; } else { memset(ship_name, 0, 256); GetLBText(lpDrawItemStruct->itemID, ship_name); z = ship_info_lookup(ship_name); } if ((z >= 0) && (lpDrawItemStruct->itemAction & (ODA_DRAWENTIRE | ODA_SELECT))) { int cyItem = GetItemHeight(z); BOOL fDisabled = !IsWindowEnabled(); COLORREF newTextColor = RGB(0x80, 0x80, 0x80); // light gray if (!fDisabled) { if (z >= Num_ship_types) newTextColor = RGB(0, 0, 0); else switch (Ship_info[z].species) { case SPECIES_TERRAN: newTextColor = RGB(0, 0, 192); break; case SPECIES_VASUDAN: newTextColor = RGB(0, 128, 0); break; case SPECIES_SHIVAN: newTextColor = RGB(192, 0, 0); break; case SPECIES_NONE: newTextColor = RGB(224, 128, 0); break; } } COLORREF oldTextColor = pDC->SetTextColor(newTextColor); COLORREF newBkColor = GetSysColor(COLOR_WINDOW); COLORREF oldBkColor = pDC->SetBkColor(newBkColor); if (newTextColor == newBkColor) newTextColor = RGB(0xC0, 0xC0, 0xC0); // dark gray if (!fDisabled && ((lpDrawItemStruct->itemState & ODS_SELECTED) != 0)) { pDC->SetTextColor(GetSysColor(COLOR_HIGHLIGHTTEXT)); pDC->SetBkColor(GetSysColor(COLOR_HIGHLIGHT)); } if (m_cyText == 0) VERIFY(cyItem >= CalcMinimumItemHeight()); if (z == Id_select_type_jump_node) strText = _T("Jump Node"); else if (z == Id_select_type_start) strText = _T("Player Start"); else if (z == Id_select_type_waypoint) strText = _T("Waypoint"); else strText = _T(Ship_info[z].name); // GetLBText(lpDrawItemStruct->itemID, strText); pDC->ExtTextOut(lpDrawItemStruct->rcItem.left, lpDrawItemStruct->rcItem.top + max(0, (cyItem - m_cyText) / 2), ETO_OPAQUE, &(lpDrawItemStruct->rcItem), strText, strText.GetLength(), NULL); pDC->SetTextColor(oldTextColor); pDC->SetBkColor(oldBkColor); } if ((lpDrawItemStruct->itemAction & ODA_FOCUS) != 0) pDC->DrawFocusRect(&(lpDrawItemStruct->rcItem)); }