BOOL ShipGoalsDlg::OnInitDialog() { int i, j, z, valid[99]; object *ptr; Assert(Ai_goal_list_size <= _countof(valid)); // set up pointers to all the combo boxes to simplify things a lot m_behavior_box[0] = (CComboBox *) GetDlgItem(IDC_BEHAVIOR1); m_behavior_box[1] = (CComboBox *) GetDlgItem(IDC_BEHAVIOR2); m_behavior_box[2] = (CComboBox *) GetDlgItem(IDC_BEHAVIOR3); m_behavior_box[3] = (CComboBox *) GetDlgItem(IDC_BEHAVIOR4); m_behavior_box[4] = (CComboBox *) GetDlgItem(IDC_BEHAVIOR5); m_behavior_box[5] = (CComboBox *) GetDlgItem(IDC_BEHAVIOR6); m_behavior_box[6] = (CComboBox *) GetDlgItem(IDC_BEHAVIOR7); m_behavior_box[7] = (CComboBox *) GetDlgItem(IDC_BEHAVIOR8); m_behavior_box[8] = (CComboBox *) GetDlgItem(IDC_BEHAVIOR9); m_behavior_box[9] = (CComboBox *) GetDlgItem(IDC_BEHAVIOR10); m_object_box[0] = (CComboBox *) GetDlgItem(IDC_OBJECT1); m_object_box[1] = (CComboBox *) GetDlgItem(IDC_OBJECT2); m_object_box[2] = (CComboBox *) GetDlgItem(IDC_OBJECT3); m_object_box[3] = (CComboBox *) GetDlgItem(IDC_OBJECT4); m_object_box[4] = (CComboBox *) GetDlgItem(IDC_OBJECT5); m_object_box[5] = (CComboBox *) GetDlgItem(IDC_OBJECT6); m_object_box[6] = (CComboBox *) GetDlgItem(IDC_OBJECT7); m_object_box[7] = (CComboBox *) GetDlgItem(IDC_OBJECT8); m_object_box[8] = (CComboBox *) GetDlgItem(IDC_OBJECT9); m_object_box[9] = (CComboBox *) GetDlgItem(IDC_OBJECT10); m_subsys_box[0] = (CComboBox *) GetDlgItem(IDC_SUBSYSTEM1); m_subsys_box[1] = (CComboBox *) GetDlgItem(IDC_SUBSYSTEM2); m_subsys_box[2] = (CComboBox *) GetDlgItem(IDC_SUBSYSTEM3); m_subsys_box[3] = (CComboBox *) GetDlgItem(IDC_SUBSYSTEM4); m_subsys_box[4] = (CComboBox *) GetDlgItem(IDC_SUBSYSTEM5); m_subsys_box[5] = (CComboBox *) GetDlgItem(IDC_SUBSYSTEM6); m_subsys_box[6] = (CComboBox *) GetDlgItem(IDC_SUBSYSTEM7); m_subsys_box[7] = (CComboBox *) GetDlgItem(IDC_SUBSYSTEM8); m_subsys_box[8] = (CComboBox *) GetDlgItem(IDC_SUBSYSTEM9); m_subsys_box[9] = (CComboBox *) GetDlgItem(IDC_SUBSYSTEM10); m_dock2_box[0] = (CComboBox *) GetDlgItem(IDC_DOCK1); m_dock2_box[1] = (CComboBox *) GetDlgItem(IDC_DOCK2); m_dock2_box[2] = (CComboBox *) GetDlgItem(IDC_DOCK3); m_dock2_box[3] = (CComboBox *) GetDlgItem(IDC_DOCK4); m_dock2_box[4] = (CComboBox *) GetDlgItem(IDC_DOCK5); m_dock2_box[5] = (CComboBox *) GetDlgItem(IDC_DOCK6); m_dock2_box[6] = (CComboBox *) GetDlgItem(IDC_DOCK7); m_dock2_box[7] = (CComboBox *) GetDlgItem(IDC_DOCK8); m_dock2_box[8] = (CComboBox *) GetDlgItem(IDC_DOCK9); m_dock2_box[9] = (CComboBox *) GetDlgItem(IDC_DOCK10); m_priority_box[0] = (CComboBox *) GetDlgItem(IDC_PRIORITY1); m_priority_box[1] = (CComboBox *) GetDlgItem(IDC_PRIORITY2); m_priority_box[2] = (CComboBox *) GetDlgItem(IDC_PRIORITY3); m_priority_box[3] = (CComboBox *) GetDlgItem(IDC_PRIORITY4); m_priority_box[4] = (CComboBox *) GetDlgItem(IDC_PRIORITY5); m_priority_box[5] = (CComboBox *) GetDlgItem(IDC_PRIORITY6); m_priority_box[6] = (CComboBox *) GetDlgItem(IDC_PRIORITY7); m_priority_box[7] = (CComboBox *) GetDlgItem(IDC_PRIORITY8); m_priority_box[8] = (CComboBox *) GetDlgItem(IDC_PRIORITY9); m_priority_box[9] = (CComboBox *) GetDlgItem(IDC_PRIORITY10); // start off with all goals available for (i=0; i<Ai_goal_list_size; i++) valid[i] = 1; // disallow orders if they aren't allowed because of ship type if (self_ship >= 0) { // editing orders for just one ship for (i=0; i<Ai_goal_list_size; i++){ if (!(ai_query_goal_valid(self_ship, Ai_goal_list[i].def))){ valid[i] = 0; } } } else if (self_wing >= 0) { // editing orders for just one wing for (i=0; i<Wings[self_wing].wave_count; i++){ for (j=0; j<Ai_goal_list_size; j++){ if (!ai_query_goal_valid(Wings[self_wing].ship_index[i], Ai_goal_list[j].def)){ valid[j] = 0; } } } for (i=0; i<Ai_goal_list_size; i++){ if (Ai_goal_list[i].def == AI_GOAL_DOCK){ // a whole wing can't dock with one object.. valid[i] = 0; } } } else { // editing orders for all marked ships ptr = GET_FIRST(&obj_used_list); while (ptr != END_OF_LIST(&obj_used_list)) { if (((ptr->type == OBJ_SHIP) || (ptr->type == OBJ_START)) && (ptr->flags[Object::Object_Flags::Marked])){ for (i=0; i<Ai_goal_list_size; i++){ if (!ai_query_goal_valid(ptr->instance, Ai_goal_list[i].def)){ valid[i] = 0; } } } ptr = GET_NEXT(ptr); } } if (Waypoint_lists.empty()) { for (i=0; i<Ai_goal_list_size; i++){ switch (Ai_goal_list[i].def) { case AI_GOAL_WAYPOINTS: case AI_GOAL_WAYPOINTS_ONCE: //case AI_GOAL_WARP: valid[i] = 0; } } } z = 0; ptr = GET_FIRST(&obj_used_list); while (ptr != END_OF_LIST(&obj_used_list)) { if ((ptr->type == OBJ_SHIP) || (ptr->type == OBJ_START)) { i = ptr->instance; if ((self_ship > 0) && (self_ship != i) && ship_docking_valid(self_ship, i)){ z = 1; } } ptr = GET_NEXT(ptr); } if (!z){ for (i=0; i<Ai_goal_list_size; i++){ if (Ai_goal_list[i].def == AI_GOAL_DOCK){ valid[i] = 0; } } } // initialize the behavior boxes (they remain constant) and initialize each goal's data for (i=0; i<ED_MAX_GOALS; i++) { m_behavior_box[i] -> ResetContent(); z = m_behavior_box[i] -> AddString("None"); m_behavior_box[i] -> SetItemData(z, (DWORD) AI_GOAL_NONE); for (j=0; j<Ai_goal_list_size; j++){ if (valid[j]) { z = m_behavior_box[i] -> AddString(Ai_goal_list[j].name); m_behavior_box[i] -> SetItemData(z, (DWORD) Ai_goal_list[j].def); } } } if (self_ship >= 0){ initialize(Ai_info[Ships[self_ship].ai_index].goals, self_ship); } else if (self_wing >= 0){ initialize(Wings[self_wing].ai_goals); } else { initialize_multi(); } for (i=0; i<ED_MAX_GOALS; i++){ set_item(i, 1); } CDialog::OnInitDialog(); // restrict spin controls to a range of 0 - MAX_EDITOR_GOAL_PRIORITY ((CSpinButtonCtrl *) GetDlgItem(IDC_SPIN1)) -> SetRange(0, MAX_EDITOR_GOAL_PRIORITY); ((CSpinButtonCtrl *) GetDlgItem(IDC_SPIN2)) -> SetRange(0, MAX_EDITOR_GOAL_PRIORITY); ((CSpinButtonCtrl *) GetDlgItem(IDC_SPIN3)) -> SetRange(0, MAX_EDITOR_GOAL_PRIORITY); ((CSpinButtonCtrl *) GetDlgItem(IDC_SPIN4)) -> SetRange(0, MAX_EDITOR_GOAL_PRIORITY); ((CSpinButtonCtrl *) GetDlgItem(IDC_SPIN5)) -> SetRange(0, MAX_EDITOR_GOAL_PRIORITY); ((CSpinButtonCtrl *) GetDlgItem(IDC_SPIN6)) -> SetRange(0, MAX_EDITOR_GOAL_PRIORITY); ((CSpinButtonCtrl *) GetDlgItem(IDC_SPIN7)) -> SetRange(0, MAX_EDITOR_GOAL_PRIORITY); ((CSpinButtonCtrl *) GetDlgItem(IDC_SPIN8)) -> SetRange(0, MAX_EDITOR_GOAL_PRIORITY); ((CSpinButtonCtrl *) GetDlgItem(IDC_SPIN9)) -> SetRange(0, MAX_EDITOR_GOAL_PRIORITY); ((CSpinButtonCtrl *) GetDlgItem(IDC_SPIN10)) -> SetRange(0, MAX_EDITOR_GOAL_PRIORITY); return TRUE; }
void ShipGoalsDlg::set_item(int item, int init) { SCP_list<waypoint_list>::iterator ii; int i, t, z, num, inst; object *ptr; if (init) m_object[item] = -1; if (item >= MAX_AI_GOALS) m_behavior_box[item] -> EnableWindow(FALSE); Assert(item >= 0 && item < ED_MAX_GOALS); m_object_box[item] -> ResetContent(); if (m_behavior[item] < 1) { m_object_box[item] -> EnableWindow(FALSE); m_subsys_box[item] -> EnableWindow(FALSE); m_dock2_box[item] -> EnableWindow(FALSE); m_priority_box[item] -> EnableWindow(FALSE); m_subsys[item] = -1; m_dock2[item] = -1; return; } auto mode = m_behavior_box[item] -> GetItemData(m_behavior[item]); m_priority_box[item] -> EnableWindow(TRUE); if ((mode == AI_GOAL_CHASE_ANY) || (mode == AI_GOAL_UNDOCK) || (mode == AI_GOAL_KEEP_SAFE_DISTANCE) || (mode == AI_GOAL_PLAY_DEAD) || (mode == AI_GOAL_PLAY_DEAD_PERSISTENT) || (mode == AI_GOAL_WARP) ) { m_object_box[item] -> EnableWindow(FALSE); m_subsys_box[item] -> EnableWindow(FALSE); m_dock2_box[item] -> EnableWindow(FALSE); m_subsys[item] = -1; m_dock2[item] = -1; return; } m_object_box[item] -> EnableWindow(TRUE); // for goals that deal with waypoint paths or individual waypoints switch (mode) { case AI_GOAL_WAYPOINTS: case AI_GOAL_WAYPOINTS_ONCE: //case AI_GOAL_WARP: for (i = 0, ii = Waypoint_lists.begin(); ii != Waypoint_lists.end(); ++i, ++ii) { z = m_object_box[item] -> AddString(ii->get_name()); m_object_box[item] -> SetItemData(z, i | TYPE_PATH); if (init && (m_data[item] == (i | TYPE_PATH))) m_object[item] = z; } break; case AI_GOAL_STAY_STILL: ptr = GET_FIRST(&obj_used_list); while (ptr != END_OF_LIST(&obj_used_list)) { if (ptr->type == OBJ_WAYPOINT) { z = m_object_box[item] -> AddString(object_name(OBJ_INDEX(ptr))); m_object_box[item] -> SetItemData(z, OBJ_INDEX(ptr) | TYPE_WAYPOINT); if (init && (m_data[item] == (OBJ_INDEX(ptr) | TYPE_WAYPOINT))) m_object[item] = z; } ptr = GET_NEXT(ptr); } break; } // for goals that deal with ship classes switch (mode) { case AI_GOAL_CHASE_SHIP_CLASS: for (i = 0; i < static_cast<int>(Ship_info.size()); i++) { z = m_object_box[item] -> AddString(Ship_info[i].name); m_object_box[item] -> SetItemData(z, i | TYPE_SHIP_CLASS); if (init && (m_data[item] == (i | TYPE_SHIP_CLASS))) m_object[item] = z; } break; } // for goals that deal with individual ships switch (mode) { case AI_GOAL_DESTROY_SUBSYSTEM: case AI_GOAL_CHASE | AI_GOAL_CHASE_WING: case AI_GOAL_DOCK: case AI_GOAL_GUARD | AI_GOAL_GUARD_WING: case AI_GOAL_DISABLE_SHIP: case AI_GOAL_DISARM_SHIP: case AI_GOAL_EVADE_SHIP: case AI_GOAL_IGNORE: case AI_GOAL_IGNORE_NEW: case AI_GOAL_STAY_NEAR_SHIP: case AI_GOAL_STAY_STILL: ptr = GET_FIRST(&obj_used_list); while (ptr != END_OF_LIST(&obj_used_list)) { if ((ptr->type == OBJ_SHIP) || (ptr->type == OBJ_START)) { inst = ptr->instance; if (ptr->type == OBJ_SHIP) t = TYPE_SHIP; else t = TYPE_PLAYER; Assert(inst >= 0 && inst < MAX_SHIPS); // remove all marked ships from list if (!goalp && (ptr->flags[Object::Object_Flags::Marked])) inst = -1; // when docking, remove invalid dock targets else if (mode == AI_GOAL_DOCK) { if (self_ship < 0 || !ship_docking_valid(self_ship, inst)) inst = -1; } // disallow ship being its own target if (inst >= 0 && inst != self_ship) { z = m_object_box[item] -> AddString(Ships[inst].ship_name); m_object_box[item] -> SetItemData(z, inst | t); if (init && (m_data[item] == (inst | t))) m_object[item] = z; } } ptr = GET_NEXT(ptr); } break; } // for goals that deal with wings switch (mode) { case AI_GOAL_CHASE | AI_GOAL_CHASE_WING: case AI_GOAL_GUARD | AI_GOAL_GUARD_WING: for (i=0; i<MAX_WINGS; i++) { if (Wings[i].wave_count && i != self_wing) { z = m_object_box[item] -> AddString(Wings[i].name); m_object_box[item] -> SetItemData(z, i | TYPE_WING); if (init && (m_data[item] == (i | TYPE_WING))) m_object[item] = z; } } break; } // special cases depending on the target: subsystems and docking points if (mode == AI_GOAL_DESTROY_SUBSYSTEM) { m_subsys_box[item] -> EnableWindow(TRUE); m_dock2_box[item] -> EnableWindow(FALSE); m_dock2[item] = -1; set_object(item); if (!m_behavior[item]) set_item(item, init); } else if (mode == AI_GOAL_DOCK) { num = get_docking_list(Ship_info[Ships[cur_ship].ship_info_index].model_num); m_subsys_box[item] -> EnableWindow(TRUE); m_subsys_box[item] -> ResetContent(); for (i=0; i<num; i++) { Assert(Docking_bay_list[i]); z = m_subsys_box[item] -> AddString(Docking_bay_list[i]); m_subsys_box[item] -> SetItemDataPtr(z, Docking_bay_list[i]); } set_object(item); if (!m_behavior[item]) set_item(item, init); } else { m_subsys_box[item] -> EnableWindow(FALSE); m_dock2_box[item] -> EnableWindow(FALSE); m_subsys[item] = -1; m_dock2[item] = -1; } }
void initial_status::list_dockees(int dock_types) { int z; // enable/disable dropdown cboDockees->EnableWindow((dock_types >= 0) ? TRUE : FALSE); // clear the existing dockees cboDockees->ResetContent(); // that might be all we need to do if (dock_types < 0) return; // populate with potential dockees // add "nothing" z = cboDockees->AddString("Nothing"); cboDockees->SetItemData(z, static_cast<DWORD_PTR>(-1)); // add ships for (object *objp = GET_FIRST(&obj_used_list); objp != END_OF_LIST(&obj_used_list); objp = GET_NEXT(objp)) { if ((objp->type == OBJ_SHIP) || (objp->type == OBJ_START)) { int ship = get_ship_from_obj(objp); // mustn't be the same ship if (ship == m_ship) continue; // mustn't also be docked elsewhere bool docked_elsewhere = false; for (int i = 0; i < num_dock_points; i++) { // don't erroneously check the same point if (i == cur_docker_point) continue; // see if this ship is also on a different dockpoint if (dockpoint_array[i].dockee_shipnum == ship) { docked_elsewhere = true; break; } } if (docked_elsewhere) continue; // docking must be valid if (!ship_docking_valid(m_ship, ship) && !ship_docking_valid(ship, m_ship)) continue; // dock types must match if (!(model_get_dock_types(Ship_info[Ships[ship].ship_info_index].model_num) & dock_types)) continue; // add to list z = cboDockees->AddString(Ships[ship].ship_name); cboDockees->SetItemData(z, ship); } } }