1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046
|
/*
* Copyright (C) Volition, Inc. 1999. All rights reserved.
*
* All source code herein is the property of Volition, Inc. You may not sell
* or otherwise commercially exploit the source or things you created based on the
* source.
*
*/
#include "stdafx.h"
#include "FRED.h"
#include "FREDDoc.h"
#include "PlayerStartEditor.h"
#include "mission/missionparse.h"
#include "object/object.h"
#include "Management.h"
#include "weapon/weapon.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// player_start_editor dialog
player_start_editor::player_start_editor(CWnd* pParent) : CDialog(player_start_editor::IDD, pParent)
{
//{{AFX_DATA_INIT(player_start_editor)
m_delay = 0;
m_weapon_pool = 0;
m_ship_pool = 0;
//}}AFX_DATA_INIT
selected_team = 0;
autobalance = false;
previous_team = -1;
dlg_inited = 0;
}
void player_start_editor::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(player_start_editor)
DDX_Control(pDX, IDC_POOL_SPIN, m_pool_spin);
DDX_Control(pDX, IDC_DELAY_SPIN, m_delay_spin);
DDX_Control(pDX, IDC_SPIN1, m_spin1);
DDX_Control(pDX, IDC_SHIP_LIST, m_ship_list);
DDX_Control(pDX, IDC_WEAPON_LIST, m_weapon_list);
DDX_Control(pDX, IDC_SHIP_VARIABLES_LIST, m_ship_variable_list);
DDX_Control(pDX, IDC_WEAPON_VARIABLES_LIST, m_weapon_variable_list);
DDX_Control(pDX, IDC_SHIP_VARIABLES_COMBO, m_ship_quantity_variable);
DDX_Control(pDX, IDC_WEAPON_VARIABLES_COMBO, m_weapon_quantity_variable);
DDX_Control(pDX, IDC_WINGS_SHP_COUNT, m_ships_used_in_wings);
DDX_Control(pDX, IDC_WINGS_WPN_COUNT, m_weapons_used_in_wings);
DDX_Text(pDX, IDC_DELAY, m_delay);
DDX_Text(pDX, IDC_SHIP_POOL, m_ship_pool);
DDX_Text(pDX, IDC_WEAPON_POOL, m_weapon_pool);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(player_start_editor, CDialog)
//{{AFX_MSG_MAP(player_start_editor)
ON_WM_INITMENU()
ON_LBN_SELCHANGE(IDC_SHIP_LIST, OnSelchangeShipList)
ON_LBN_SELCHANGE(IDC_WEAPON_LIST, OnSelchangeWeaponList)
ON_EN_UPDATE(IDC_SHIP_POOL, OnUpdateShipPool)
ON_EN_UPDATE(IDC_WEAPON_POOL, OnUpdateWeaponPool)
ON_LBN_SELCHANGE(IDC_SHIP_VARIABLES_LIST, OnSelchangeShipVariablesList)
ON_LBN_SELCHANGE(IDC_WEAPON_VARIABLES_LIST, OnSelchangeWeaponVariablesList)
ON_CBN_SELCHANGE(IDC_SHIP_VARIABLES_COMBO, OnSelchangeShipVariablesCombo)
ON_WM_CLOSE()
ON_CBN_SELCHANGE(IDC_WEAPON_VARIABLES_COMBO, OnSelchangeWeaponVariablesCombo)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// player_start_editor message handlers
BOOL player_start_editor::OnInitDialog()
{
int i, j;
int idx;
// initialize ship pool data
memset(static_ship_pool, -1, sizeof(int) * MAX_TVT_TEAMS * MAX_SHIP_CLASSES);
memset(dynamic_ship_pool, -1, sizeof(int) * MAX_TVT_TEAMS * MAX_SEXP_VARIABLES);
memset(static_ship_variable_pool, -1, sizeof(int) * MAX_TVT_TEAMS * MAX_SHIP_CLASSES);
memset(dynamic_ship_variable_pool, -1, sizeof(int) * MAX_TVT_TEAMS * MAX_SEXP_VARIABLES);
for(i=0; i<MAX_TVT_TEAMS; i++){
for(idx=0; idx<Team_data[i].num_ship_choices; idx++)
{
// do we have a variable for this entry? if we don't....
if (!strlen(Team_data[i].ship_list_variables[idx]))
{
// This pool is set to hold the number of ships available at an index corresponding to the Ship_info array.
static_ship_pool[i][Team_data[i].ship_list[idx]] = Team_data[i].ship_count[idx];
// This pool is set to hold whether a ship at a Ship_info index has been set by a variable (and the
// variables index in Sexp_variables) if it has).
if (strlen(Team_data[i].ship_count_variables[idx])) {
static_ship_variable_pool[i][Team_data[i].ship_list[idx]] = get_index_sexp_variable_name(Team_data[i].ship_count_variables[idx]);
}
else {
static_ship_variable_pool[i][Team_data[i].ship_list[idx]] = -1;
}
}
// if we do....
else
{
// This pool is set to hold the number of ships available at an index corresponding to the Sexp_variables array
dynamic_ship_pool[i][get_index_sexp_variable_name(Team_data[i].ship_list_variables[idx])] = Team_data[i].ship_count[idx];
// This pool is set to hold whether a ship at a Ship_info index has been set by a variable (and the
// variables index in Sexp_variables) if it has).
if (strlen(Team_data[i].ship_count_variables[idx])) {
dynamic_ship_variable_pool[i][get_index_sexp_variable_name(Team_data[i].ship_list_variables[idx])] = get_index_sexp_variable_name(Team_data[i].ship_count_variables[idx]);
}
else {
dynamic_ship_variable_pool[i][get_index_sexp_variable_name(Team_data[i].ship_list_variables[idx])] = -1;
}
}
}
}
// initialize weapon pool data
memset(static_weapon_pool, -1, sizeof(int) * MAX_TVT_TEAMS * MAX_WEAPON_TYPES);
memset(dynamic_weapon_pool, -1, sizeof(int) * MAX_TVT_TEAMS * MAX_SEXP_VARIABLES);
memset(static_weapon_variable_pool, -1, sizeof(int) * MAX_TVT_TEAMS * MAX_WEAPON_TYPES);
memset(dynamic_weapon_variable_pool, -1, sizeof(int) * MAX_TVT_TEAMS * MAX_SEXP_VARIABLES);
for(i=0; i<MAX_TVT_TEAMS; i++){
for(idx=0; idx<Team_data[i].num_weapon_choices; idx++)
{
// do we have a variable for this entry?
if (!strlen(Team_data[i].weaponry_pool_variable[idx]))
{
static_weapon_pool[i][Team_data[i].weaponry_pool[idx]] = Team_data[i].weaponry_count[idx];
if (strlen(Team_data[i].weaponry_amount_variable[idx])) {
static_weapon_variable_pool[i][Team_data[i].weaponry_pool[idx]] = get_index_sexp_variable_name(Team_data[i].weaponry_amount_variable[idx]);
}
else {
static_weapon_variable_pool[i][Team_data[i].weaponry_pool[idx]] = -1;
}
}
// if we do....
else
{
dynamic_weapon_pool[i][get_index_sexp_variable_name(Team_data[i].weaponry_pool_variable[idx])] = Team_data[i].weaponry_count[idx];
if (strlen(Team_data[i].weaponry_amount_variable[idx])) {
dynamic_weapon_variable_pool[i][get_index_sexp_variable_name(Team_data[i].weaponry_pool_variable[idx])] = get_index_sexp_variable_name(Team_data[i].weaponry_amount_variable[idx]);
}
else {
dynamic_weapon_variable_pool[i][get_index_sexp_variable_name(Team_data[i].weaponry_pool_variable[idx])] = -1;
}
}
}
}
// initialise the ship and weapon usage list
memset(ship_usage, 0, sizeof(int) * MAX_TVT_TEAMS * MAX_SHIP_CLASSES);
memset(weapon_usage, 0, sizeof(int) * MAX_TVT_TEAMS * MAX_WEAPON_TYPES);
if (The_mission.game_type & MISSION_TYPE_MULTI_TEAMS) {
for (i=0; i<MAX_TVT_TEAMS; i++) {
for (j=0; j<MAX_TVT_WINGS_PER_TEAM; j++) {
generate_ship_usage_list(ship_usage[i], TVT_wings[(i*MAX_TVT_WINGS_PER_TEAM) + j]);
generate_weaponry_usage_list(weapon_usage[i], TVT_wings[(i*MAX_TVT_WINGS_PER_TEAM) + j]);
}
}
}
else {
for (i=0; i<MAX_STARTING_WINGS; i++) {
generate_ship_usage_list(ship_usage[0], Starting_wings[i]);
generate_weaponry_usage_list(weapon_usage[0], Starting_wings[i]);
}
}
// entry delay time
m_delay = f2i(Entry_delay_time);
// misc window crap
CDialog::OnInitDialog();
theApp.init_window(&Player_wnd_data, this);
m_spin1.SetRange(0, 99);
m_pool_spin.SetRange(0, 9999);
m_delay_spin.SetRange(0, 30);
// regenerate all the controls
reset_controls();
dlg_inited = 1;
return TRUE;
}
// regenerate all controls
void player_start_editor::reset_controls()
{
int i;
int ct;
char buff[TOKEN_LENGTH + TOKEN_LENGTH + 2]; // VariableName[VariableValue]
if (autobalance && (previous_team != -1) && (previous_team != selected_team)) {
// copy across all the ship stuff
for (i=0; i<MAX_SHIP_CLASSES; i++) {
static_ship_pool[selected_team][i] = static_ship_pool[previous_team][i];
static_ship_variable_pool[selected_team][i] = static_ship_variable_pool[previous_team][i];
}
// copy across weapon stuff
for (i=0; i<MAX_WEAPON_TYPES; i++) {
static_weapon_pool[selected_team][i] = static_weapon_pool[previous_team][i];
static_weapon_variable_pool[selected_team][i] = static_weapon_variable_pool[previous_team][i];
}
// copy across variable stuff
for (i=0; i<MAX_SEXP_VARIABLES; i++) {
dynamic_ship_pool[selected_team][i] = dynamic_ship_pool[previous_team][i];
dynamic_ship_variable_pool[selected_team][i] = dynamic_ship_variable_pool[previous_team][i];
dynamic_weapon_pool[selected_team][i] = dynamic_weapon_pool[previous_team][i];
dynamic_weapon_variable_pool[selected_team][i] = dynamic_weapon_variable_pool[previous_team][i];
}
}
m_ship_variable_list.ResetContent();
m_ship_quantity_variable.ResetContent();
m_weapon_variable_list.ResetContent();
m_weapon_quantity_variable.ResetContent();
// Add the default entry to both variable quantity ComboBoxes
m_ship_quantity_variable.AddString("Don't Use Variables");
m_weapon_quantity_variable.AddString("Don't Use Variables");
int current_entry = 0;
int num_sexp_variables = sexp_variable_count();
for (i=0; i < num_sexp_variables; i++)
{
if (Sexp_variables[i].type & SEXP_VARIABLE_STRING)
{
sprintf(buff, "%s [%s]", Sexp_variables[i].variable_name, Sexp_variables[i].text);
m_ship_variable_list.AddString(buff);
m_weapon_variable_list.AddString(buff);
// Now we set the checkbox for ships
if((dynamic_ship_pool[selected_team][i] > 0) ||
(dynamic_ship_variable_pool[selected_team][i] != -1))
{
m_ship_variable_list.SetCheck(current_entry, TRUE);
}
else
{
m_ship_variable_list.SetCheck(current_entry, FALSE);
}
// and now for weapons
if((dynamic_weapon_pool[selected_team][i] > 0) ||
(dynamic_weapon_variable_pool[selected_team][i] != -1))
{
m_weapon_variable_list.SetCheck(current_entry, TRUE);
}
else
{
m_weapon_variable_list.SetCheck(current_entry, FALSE);
}
current_entry++;
}
// Since we're looping through Sexp_variables amyway we might as well fill the number variable combo boxes
else if (Sexp_variables[i].type & SEXP_VARIABLE_NUMBER)
{
m_ship_quantity_variable.AddString(Sexp_variables[i].variable_name);
m_weapon_quantity_variable.AddString(Sexp_variables[i].variable_name);
}
}
// create a checklistbox for each "player" ship type
m_ship_list.ResetContent();
ct = 0;
for (i=0; i<Num_ship_classes; i++) {
if (Ship_info[i].flags & SIF_PLAYER_SHIP) {
m_ship_list.AddString(Ship_info[i].name);
// if the ship currently has pool entries or was set by a variable, check it
if((static_ship_pool[selected_team][i] > 0) || (static_ship_variable_pool[selected_team][i] != -1)) {
m_ship_list.SetCheck(ct, TRUE);
} else {
m_ship_list.SetCheck(ct, FALSE);
}
// next
ct++;
}
}
// create a checklistbox for each weapon ship type
m_weapon_list.ResetContent();
ct = 0;
for (i=0; i<Num_weapon_types; i++) {
if (Weapon_info[i].wi_flags & WIF_PLAYER_ALLOWED) {
m_weapon_list.AddString(Weapon_info[i].name);
// if the ship currently has pool entries or was set by a variable, check it
if((static_weapon_pool[selected_team][i] > 0) || (static_weapon_variable_pool[selected_team][i] != -1)){
m_weapon_list.SetCheck(ct, TRUE);
} else {
m_weapon_list.SetCheck(ct, FALSE);
}
ct++;
} else if (static_weapon_pool[selected_team][i] > 0 || (static_weapon_variable_pool[selected_team][i] != -1)) {
// not sure if this should be a verbal warning or not, so I'm adding both and making it verbal for now
Warning(LOCATION, "Weapon '%s' in weapon pool isn't allowed on player loadout! Resetting count to 0...\n", Weapon_info[i].name);
static_weapon_pool[selected_team][i] = 0;
static_weapon_variable_pool[selected_team][i] = -1;
}
}
// be sure that nothing is selected
m_ship_list.SetCurSel(-1);
m_ship_variable_list.SetCurSel(-1);
m_ship_quantity_variable.SetCurSel(-1);
m_weapon_list.SetCurSel(-1);
m_weapon_variable_list.SetCurSel(-1);
m_weapon_quantity_variable.SetCurSel(-1);
UpdateData(FALSE);
}
void player_start_editor::OnInitMenu(CMenu* pMenu)
{
int i;
CMenu *m;
// disable any items we should disable
m = pMenu->GetSubMenu(0);
// uncheck all menu items
for (i = 0; i < Num_teams; i++ ){
m->CheckMenuItem(i, MF_BYPOSITION | MF_UNCHECKED);
}
for ( i = Num_teams; i < MAX_TVT_TEAMS; i++ ){
m->EnableMenuItem(i, MF_BYPOSITION | MF_GRAYED);
}
// put a check next to the currently selected item
m->CheckMenuItem(selected_team, MF_BYPOSITION | MF_CHECKED);
m = pMenu->GetSubMenu(1);
if (Num_teams > 1) {
m->CheckMenuItem(ID_AUTOBALANCE, autobalance ? MF_CHECKED : MF_UNCHECKED);
}
else {
m->EnableMenuItem(ID_AUTOBALANCE, MF_GRAYED);
}
CDialog::OnInitMenu(pMenu);
}
// switch between active teams
BOOL player_start_editor::OnCommand(WPARAM wParam, LPARAM lParam)
{
int id;
// select a team
id = LOWORD(wParam);
switch(id){
case ID_TEAM_1:
previous_team = selected_team;
selected_team = 0;
reset_controls();
break;
case ID_TEAM_2:
previous_team = selected_team;
selected_team = 1;
reset_controls();
break;
case ID_AUTOBALANCE:
autobalance = !autobalance;
break;
}
// low level stuff
return CDialog::OnCommand(wParam, lParam);
}
// 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);
}
// ship variable list changed
void player_start_editor::OnSelchangeShipVariablesList()
{
int selection;
// If the variable list is selected the ship list should be deselected
m_ship_list.SetCurSel(-1);
//Have we selected something?
selection = m_ship_variable_list.GetCurSel();
if (selection != -1) {
int sexp_index = get_nth_variable_index(selection+1, SEXP_VARIABLE_STRING);
if (sexp_index > -1) {
Assert(selection == sexp_variable_typed_count(sexp_index, SEXP_VARIABLE_STRING));
// Is this item checked?
if (m_ship_variable_list.GetCheck(selection)) {
if (dynamic_ship_variable_pool[selected_team][sexp_index] == -1) {
if (dynamic_ship_pool[selected_team][sexp_index] <= 0) {
dynamic_ship_pool[selected_team][sexp_index] = 5;
}
m_ship_pool = dynamic_ship_pool[selected_team][sexp_index];
m_ship_quantity_variable.SetCurSel(0);
}
else {
Assert (Sexp_variables[dynamic_ship_variable_pool[selected_team][sexp_index]].type & SEXP_VARIABLE_NUMBER);
m_ship_pool = atoi(Sexp_variables[dynamic_ship_variable_pool[selected_team][sexp_index]].text);
int selected_variable = sexp_variable_typed_count(dynamic_ship_variable_pool[selected_team][sexp_index], SEXP_VARIABLE_NUMBER);
m_ship_quantity_variable.SetCurSel(selected_variable + 1);
}
}
// We've unselected the tickbox, reset everything
else {
dynamic_ship_pool[selected_team][sexp_index] = -1;
dynamic_ship_variable_pool[selected_team][sexp_index] = -1;
m_ship_pool = 0;
m_ship_quantity_variable.SetCurSel(0);
}
// It might be nice to have FRED work out if any ships of the class represented by the variable are in the wings
// but for now just set it to zero
m_ships_used_in_wings.SetWindowText("0");
}
else {
Int3();
}
}
// update stuff
UpdateData(FALSE);
}
void player_start_editor::OnSelchangeShipVariablesCombo()
{
// Get the new selection
char variable_name[TOKEN_LENGTH];
bool update_static_pool = false;
bool update_dynamic_pool = false;
m_ship_quantity_variable.GetLBText(m_ship_quantity_variable.GetCurSel(), variable_name);
int sexp_index = get_index_sexp_variable_name(variable_name);
Assert ((sexp_index > -1) || (!strcmp("Don't Use Variables", variable_name)));
// See if the ship_list was selected
int ship_index = GetSelectedShipListIndex();
if (ship_index >= 0) {
static_ship_variable_pool[selected_team][ship_index] = sexp_index;
update_static_pool = true;
}
// Maybe it's the ship_variables_list that is actually selected
int ship_variable_index = GetSelectedShipVariableListIndex();
if (ship_variable_index >= 0 ) {
dynamic_ship_variable_pool[selected_team][ship_variable_index] = sexp_index;
update_dynamic_pool = true;
}
// Somethings gone wrong if they're both marked as true
Assert (! (update_static_pool && update_dynamic_pool));
// Update the ship_pool
if (update_static_pool || update_dynamic_pool) {
int new_quantity = 5;
if (sexp_index > -1) {
Assert (Sexp_variables[sexp_index].type & SEXP_VARIABLE_NUMBER);
new_quantity = atoi(Sexp_variables[sexp_index].text);
}
if (update_static_pool) {
static_ship_pool[selected_team][ship_index] = new_quantity;
}
else {
dynamic_ship_pool[selected_team][ship_variable_index] = new_quantity;
}
m_ship_pool = new_quantity;
}
// update stuff
UpdateData(FALSE);
}
// 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);
}
void player_start_editor::OnSelchangeWeaponVariablesList()
{
int selection;
// deselect the other list
m_weapon_list.SetCurSel(-1);
//Have we selected something?
selection = m_weapon_variable_list.GetCurSel();
if (selection != -1) {
int sexp_index = get_nth_variable_index(selection+1, SEXP_VARIABLE_STRING);
if (sexp_index > -1) {
Assert(selection == sexp_variable_typed_count(sexp_index, SEXP_VARIABLE_STRING));
// Is this item checked?
if (m_weapon_variable_list.GetCheck(selection)) {
if (dynamic_weapon_variable_pool[selected_team][sexp_index] == -1) {
if (dynamic_weapon_pool[selected_team][sexp_index] <= 0) {
dynamic_weapon_pool[selected_team][sexp_index] = 5;
}
m_weapon_pool = dynamic_weapon_pool[selected_team][sexp_index];
m_weapon_quantity_variable.SetCurSel(0);
}
else {
Assert (Sexp_variables[dynamic_weapon_variable_pool[selected_team][sexp_index]].type & SEXP_VARIABLE_NUMBER);
m_weapon_pool = atoi(Sexp_variables[dynamic_weapon_variable_pool[selected_team][sexp_index]].text);
int selected_variable = sexp_variable_typed_count(dynamic_weapon_variable_pool[selected_team][sexp_index], SEXP_VARIABLE_NUMBER);
m_weapon_quantity_variable.SetCurSel(selected_variable + 1);
}
}
// We've unselected the tickbox, reset everything
else {
dynamic_weapon_pool[selected_team][sexp_index] = -1;
dynamic_weapon_variable_pool[selected_team][sexp_index] = -1;
m_weapon_pool = 0;
m_weapon_quantity_variable.SetCurSel(0);
}
// It might be nice to have FRED work out if any weapons of this type are in the wings
// but for now just set it to zero
m_weapons_used_in_wings.SetWindowText("0");
}
else {
Int3();
}
}
// update stuff
UpdateData(FALSE);
}
void player_start_editor::OnSelchangeWeaponVariablesCombo()
{
// Get the new selection
char variable_name[TOKEN_LENGTH];
bool update_static_pool = false;
bool update_dynamic_pool = false;
m_weapon_quantity_variable.GetLBText(m_weapon_quantity_variable.GetCurSel(), variable_name);
int sexp_index = get_index_sexp_variable_name(variable_name);
Assert ((sexp_index > -1) || (!strcmp("Don't Use Variables", variable_name)));
// See if the weapon_list was selected
int weapon_index = GetSelectedWeaponListIndex();
if (weapon_index >= 0) {
static_weapon_variable_pool[selected_team][weapon_index] = sexp_index;
update_static_pool = true;
}
// Maybe it's the weapon_variables_list that is actually selected
int weapon_variable_index = GetSelectedWeaponVariableListIndex();
if (weapon_variable_index >= 0 ) {
dynamic_weapon_variable_pool[selected_team][weapon_variable_index] = sexp_index;
update_dynamic_pool = true;
}
// Somethings gone wrong if they're both marked as true
Assert (! (update_static_pool && update_dynamic_pool));
// Update the weapon_pool
if (update_static_pool || update_dynamic_pool) {
int new_quantity = 100;
if (sexp_index > -1) {
Assert (Sexp_variables[sexp_index].type & SEXP_VARIABLE_NUMBER);
new_quantity = atoi(Sexp_variables[sexp_index].text);
}
if (update_static_pool) {
static_weapon_pool[selected_team][weapon_index] = new_quantity;
}
else {
dynamic_weapon_pool[selected_team][weapon_variable_index] = new_quantity;
}
m_weapon_pool = new_quantity;
}
// update stuff
UpdateData(FALSE);
}
// cancel
void player_start_editor::OnCancel()
{
theApp.record_window_data(&Player_wnd_data, this);
CDialog::OnCancel();
}
// 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
if (idx != -1) {
Assert (idx < MAX_SEXP_VARIABLES);
strcpy_s(Team_data[i].ship_list_variables[num_choices], Sexp_variables[idx].variable_name);
}
else {
strcpy_s(Team_data[i].ship_list_variables[num_choices], "");
}
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];
strcpy_s(Team_data[i].ship_count_variables[num_choices], "");
}
else {
Assert (Sexp_variables[dynamic_ship_variable_pool[i][idx]].type & SEXP_VARIABLE_NUMBER);
strcpy_s(Team_data[i].ship_count_variables[num_choices], Sexp_variables[dynamic_ship_variable_pool[i][idx]].variable_name);
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;
strcpy_s(Team_data[i].ship_list_variables[num_choices], "");
// 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];
strcpy_s(Team_data[i].ship_count_variables[num_choices], "");
}
else {
Assert (Sexp_variables[static_ship_variable_pool[i][idx]].type & SEXP_VARIABLE_NUMBER);
strcpy_s(Team_data[i].ship_count_variables[num_choices], Sexp_variables[static_ship_variable_pool[i][idx]].variable_name);
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
strcpy_s(Team_data[i].weaponry_pool_variable[num_choices], Sexp_variables[idx].variable_name);
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];
strcpy_s(Team_data[i].weaponry_amount_variable[num_choices], "");
}
else
{
Assert (Sexp_variables[dynamic_weapon_variable_pool[i][idx]].type & SEXP_VARIABLE_NUMBER);
strcpy_s(Team_data[i].weaponry_amount_variable[num_choices], Sexp_variables[dynamic_weapon_variable_pool[i][idx]].variable_name);
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;
strcpy_s(Team_data[i].weaponry_pool_variable[num_choices], "");
// 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];
strcpy_s(Team_data[i].weaponry_amount_variable[num_choices], "");
}
else
{
Assert (Sexp_variables[static_weapon_variable_pool[i][idx]].type & SEXP_VARIABLE_NUMBER);
strcpy_s(Team_data[i].weaponry_amount_variable[num_choices], Sexp_variables[static_weapon_variable_pool[i][idx]].variable_name);
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();
}
// 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;
}
// 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;
}
// Returns the Sexp_variables index of the selected and checked ship_variables_list item or -1 if nothing is checked
// or the ship is invalid
int player_start_editor::GetSelectedShipVariableListIndex()
{
// Try the ship_variables_list
int selected = m_ship_variable_list.GetCurSel();
if((selected != -1) && m_ship_variable_list.GetCheck(selected))
{
//lookup the variable
return get_nth_variable_index(selected+1, SEXP_VARIABLE_STRING);
}
return -1;
}
// Returns the Sexp_variables index of the selected and checked weapon_variables_list item or -1 if nothing is checked
// or the weapon is invalid
int player_start_editor::GetSelectedWeaponVariableListIndex()
{
// Try the ship_variables_list
int selected = m_weapon_variable_list.GetCurSel();
if((selected != -1) && m_weapon_variable_list.GetCheck(selected))
{
return get_nth_variable_index(selected+1, SEXP_VARIABLE_STRING);
}
return -1;
}
// Updates the Sexp_variable in a variable combobox to the value supplied
void player_start_editor::UpdateQuantityVariable(CComboBox *variable_list, int pool_value)
{
char variable_name[TOKEN_LENGTH];
variable_list->GetLBText(variable_list->GetCurSel(), variable_name);
int variable_index = get_index_sexp_variable_name(variable_name);
if (variable_index > -1)
{
char variable_value[TOKEN_LENGTH];
sprintf(variable_value, "%d", pool_value);
Assert (Sexp_variables[variable_index].type & SEXP_VARIABLE_NUMBER);
sexp_fred_modify_variable(variable_value, variable_name, variable_index, SEXP_VARIABLE_NUMBER);
}
}
// ship pool count change
void player_start_editor::OnUpdateShipPool()
{
int si_index;
if (!dlg_inited){
return;
}
UpdateData(TRUE);
si_index = GetSelectedShipListIndex();
// Update the pool if we have a valid ship type
if(si_index >= 0)
{
static_ship_pool[selected_team][si_index] = m_ship_pool;
// If this value came from a variable we should update its value
UpdateQuantityVariable(&m_ship_quantity_variable, m_ship_pool);
return ;
}
// Maybe it's the ship_variables_list that is actually selected
int sexp_index = GetSelectedShipVariableListIndex();
// if we have a valid sexp_variable
if(sexp_index >= 0)
{
dynamic_ship_pool[selected_team][sexp_index] = m_ship_pool;
UpdateQuantityVariable(&m_ship_quantity_variable, m_ship_pool);
}
}
// weapon pool count change
void player_start_editor::OnUpdateWeaponPool()
{
int wi_index;
if (!dlg_inited){
return;
}
UpdateData(TRUE);
wi_index = GetSelectedWeaponListIndex();
// Update the pool if we have a valid weapon type
if(wi_index >= 0)
{
static_weapon_pool[selected_team][wi_index] = m_weapon_pool;
// If this value came from a variable we should update its value
UpdateQuantityVariable(&m_weapon_quantity_variable, m_weapon_pool);
return ;
}
// Maybe it's the ship_variables_list that is actually selected
int sexp_index = GetSelectedWeaponVariableListIndex();
// if we have a valid sexp_variable
if(sexp_index >= 0)
{
dynamic_weapon_pool[selected_team][sexp_index] = m_weapon_pool;
UpdateQuantityVariable(&m_weapon_quantity_variable, m_weapon_pool);
}
}
|