| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | #ifndef _LEVELGOAL_H_ |
| 20 | #define _LEVELGOAL_H_ |
| 21 | |
| 22 | #include "object.h" |
| 23 | #include "cfile.h" |
| 24 | #include <cstdlib> |
| 25 | #include "mem.h" |
| 26 | #include "levelgoal_external.h" |
| 27 | |
| 28 | class litem { |
| 29 | public: |
| 30 | litem() { |
| 31 | m_type = LIT_OBJECT; |
| 32 | m_handle = OBJECT_HANDLE_NONE; |
| 33 | m_f_done = false; |
| 34 | }; |
| 35 | |
| 36 | char m_type; |
| 37 | int m_handle; |
| 38 | bool m_f_done; |
| 39 | }; |
| 40 | |
| 41 | class lgoal { |
| 42 | private: |
| 43 | char *m_name; |
| 44 | char *m_item_name; |
| 45 | char *m_desc; |
| 46 | char *m_completion_message; |
| 47 | |
| 48 | int m_num_items; |
| 49 | litem m_item[MAX_GOAL_ITEMS]; |
| 50 | |
| 51 | char m_g_list; |
| 52 | char m_modified; |
| 53 | bool m_goal_completed; // since flags in a multiplayer game (client) get set to 0, then |
| 54 | // reset, we need to use this to store whether the goal has |
| 55 | // been completed, else we *possibly* can complete the goal more than |
| 56 | // once. |
| 57 | int m_priority; |
| 58 | uint32_t m_flags; |
| 59 | |
| 60 | void GoalComplete(int handle, bool announce); |
| 61 | void SendMultiUpdate(int handle); |
| 62 | |
| 63 | public: |
| 64 | lgoal() { |
| 65 | m_name = NULL; |
| 66 | m_item_name = NULL; |
| 67 | m_desc = NULL; |
| 68 | m_num_items = 0; |
| 69 | m_completion_message = NULL; |
| 70 | m_priority = 0; |
| 71 | m_g_list = 0; |
| 72 | m_flags = LGF_ENABLED | LGF_TELCOM_LISTS; |
| 73 | m_modified = 0; |
| 74 | m_goal_completed = false; |
| 75 | }; |
| 76 | ~lgoal() { |
| 77 | if (m_name) |
| 78 | mem_free(m_name); |
| 79 | if (m_item_name) |
| 80 | mem_free(m_item_name); |
| 81 | if (m_desc) |
| 82 | mem_free(m_desc); |
| 83 | }; |
| 84 | |
| 85 | int AddItem(); |
| 86 | bool DeleteItem(int index); |
| 87 | bool ItemInfo(int index, char operation, char *type, int *handle, bool *done); |
| 88 | |
| 89 | void Reset(bool f_from_editor); |
| 90 | |
| 91 | bool SetName(int handle, char *name); |
| 92 | bool SetItemName(char *iname); |
| 93 | bool SetDesc(char *desc); |
| 94 | bool SetCompletionMessage(char *message); |
| 95 | |
| 96 | int GetName(char *name, int buffer_size); |
| 97 | int GetItemName(char *iname, int buffer_size); |
| 98 | int GetDesc(char *desc, int buffer_size); |
| 99 | int GetCompletionMessage(char *message, int buffer_size); |
| 100 | |
| 101 | bool Priority(int handle, char operation, int *value); |
| 102 | bool GoalList(char operation, char *value); |
| 103 | bool GetStatus(int handle, char operation, int *value, bool f_save_load = false, bool announce = true); |
| 104 | |
| 105 | void SendStateToPlayer(int index, int pnum); |
| 106 | void ResetModified(void); |
| 107 | |
| 108 | int GetNumItems(); |
| 109 | }; |
| 110 | |
| 111 | // Goals are sorted by priority and completion |
| 112 | class levelgoals { |
| 113 | private: |
| 114 | int m_num_goals; |
| 115 | lgoal m_goal[MAX_LEVEL_GOALS]; |
| 116 | int m_flags; |
| 117 | |
| 118 | int m_num_active_primaries; |
| 119 | int m_active_primaries[MAX_LEVEL_GOALS]; |
| 120 | int m_num_active_secondaries; |
| 121 | int m_active_secondaries[MAX_LEVEL_GOALS]; |
| 122 | |
| 123 | public: |
| 124 | levelgoals() { |
| 125 | m_num_goals = 0; |
| 126 | m_num_active_secondaries = 0; |
| 127 | m_num_active_primaries = 0; |
| 128 | }; |
| 129 | |
| 130 | int AddGoal(bool f_from_editor); |
| 131 | bool DeleteGoal(int index); |
| 132 | |
| 133 | int GoalAddItem(int goal_index); |
| 134 | bool GoalDeleteItem(int goal_index, int item_index); |
| 135 | bool GoalItemInfo(int goal_index, int index, char operation, char *type, int *handle, bool *done); |
| 136 | |
| 137 | bool GoalSetName(int goal_index, char *name); |
| 138 | bool GoalSetItemName(int goal_index, char *iname); |
| 139 | bool GoalSetDesc(int goal_index, char *desc); |
| 140 | bool GoalSetCompletionMessage(int goal_index, char *message); |
| 141 | |
| 142 | int GoalGetName(int goal_index, char *name, int buffer_size); |
| 143 | int GoalGetItemName(int goal_index, char *iname, int buffer_size); |
| 144 | int GoalGetDesc(int goal_index, char *desc, int buffer_size); |
| 145 | int GoalGetCompletionMessage(int goal_index, char *message, int buffer_size); |
| 146 | |
| 147 | bool GoalPriority(int goal_index, char operation, int *value); |
| 148 | bool GoalGoalList(int goal_index, char operation, char *value); |
| 149 | bool GoalStatus(int goal_index, char operation, int *value, bool announce = true); |
| 150 | |
| 151 | int GoalFindId(const char *goal_name); |
| 152 | |
| 153 | int GoalGetNumItems(int goal_index); |
| 154 | |
| 155 | int GetNumGoals(); |
| 156 | |
| 157 | bool SaveLevelGoalInfo(CFILE *fptr); |
| 158 | bool LoadLevelGoalInfo(CFILE *fptr); |
| 159 | |
| 160 | bool LGStatus(char operation, int *value); |
| 161 | |
| 162 | int GetNumActivePrimaryGoals(); |
| 163 | int GetActivePrimaryGoal(int p_index); |
| 164 | |
| 165 | int GetNumActiveSecondaryGoals(); |
| 166 | int GetActiveSecondaryGoal(int s_index); |
| 167 | |
| 168 | void DoFrame(); |
| 169 | void CleanupAfterLevel(); |
| 170 | void InitLevel(); |
| 171 | void Inform(char type, int comp_type, int handle); |
| 172 | |
| 173 | void ResetModifiedFlags(void); |
| 174 | void MultiSendChangedGoals(int pnum); |
| 175 | }; |
| 176 | |
| 177 | extern levelgoals Level_goals; |
| 178 | |
| 179 | #endif |