2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
4 * All source code herein is the property of Volition, Inc. You may not sell
5 * or otherwise commercially exploit the source or things you created based on
15 //#define MAX_SEXP_TREE_SIZE 500
16 #define MAX_SEXP_TREE_SIZE 1050
19 #define SEXPT_UNUSED 0x0000
20 #define SEXPT_UNINIT 0x0001
21 #define SEXPT_UNKNOWN 0x0002
23 #define SEXPT_VALID 0x1000
24 #define SEXPT_TYPE_MASK 0X00ff
25 #define SEXPT_TYPE(X) (SEXPT_TYPE_MASK & X)
27 #define SEXPT_OPERATOR 0x0010
28 #define SEXPT_NUMBER 0x0020
29 #define SEXPT_STRING 0x0040
30 #define SEXPT_VARIABLE 0X0080
33 #define NOT_EDITABLE 0X00
39 #define BITMAP_OPERATOR 0
41 #define BITMAP_VARIABLE 2
43 #define BITMAP_ROOT_DIRECTIVE 4
44 #define BITMAP_CHAIN 5
45 #define BITMAP_CHAIN_DIRECTIVE 6
46 #define BITMAP_GREEN_DOT 7
47 #define BITMAP_BLACK_DOT 8
48 #define BITMAP_BLUE_DOT BITMAP_ROOT
49 #define BITMAP_RED_DOT BITMAP_ROOT_DIRECTIVE
53 // tree behavior modes (or tree subtype)
54 #define ST_LABELED_ROOT 0x10000
55 #define ST_ROOT_DELETABLE 0x20000
56 #define ST_ROOT_EDITABLE 0x40000
58 #define MODE_GOALS (1 | ST_LABELED_ROOT | ST_ROOT_DELETABLE)
59 #define MODE_EVENTS (2 | ST_LABELED_ROOT | ST_ROOT_DELETABLE | ST_ROOT_EDITABLE)
60 #define MODE_CAMPAIGN (3 | ST_LABELED_ROOT | ST_ROOT_DELETABLE)
62 // various tree operations notification codes (to be handled by derived class)
63 #define ROOT_DELETED 1
64 #define ROOT_RENAMED 2
66 #define SEXP_ITEM_F_DUP (1<<0)
69 * Notes: An sexp_tree_item is basically a node in a tree. The sexp_tree is an array of
77 int parent; // pointer to parent of this item
78 int child; // pointer to first child of this item
79 int next; // pointer to next sibling
81 char text[2 * TOKEN_LENGTH + 2];
94 sexp_list_item() : flags(0), next(NULL) {}
95 void set_op(int op_num);
96 void set_data(char *str, int t = (SEXPT_STRING | SEXPT_VALID));
97 void add_op(int op_num);
98 void add_data(char *str, int t = (SEXPT_STRING | SEXPT_VALID));
99 void add_data_dup(char *str, int t = (SEXPT_STRING | SEXPT_VALID));
100 void add_list(sexp_list_item *list);
104 class sexp_tree : public CTreeCtrl
107 int sexp_tree::find_text(char *text, int *find);
108 int query_restricted_opf_range(int opf);
109 void verify_and_fix_arguments(int node);
111 void update_help(HTREEITEM h);
112 char *help(int code);
113 HTREEITEM insert(LPCTSTR lpszItem, int image = BITMAP_ROOT, int sel_image = BITMAP_ROOT, HTREEITEM hParent = TVI_ROOT, HTREEITEM hInsertAfter = TVI_LAST);
114 HTREEITEM handle(int node);
115 int get_type(HTREEITEM h);
116 void setup(CEdit *ptr = NULL);
117 int query_false(int node = -1);
118 int add_default_operator(int op, int argnum);
119 int get_default_value(sexp_list_item *item, int op, int i);
120 int query_default_argument_available(int op);
121 int query_default_argument_available(int op, int i);
122 void swap_roots(HTREEITEM one, HTREEITEM two);
123 void move_branch(int source, int parent = -1);
124 HTREEITEM move_branch(HTREEITEM source, HTREEITEM parent = TVI_ROOT, HTREEITEM after = TVI_LAST);
125 void copy_branch(HTREEITEM source, HTREEITEM parent = TVI_ROOT, HTREEITEM after = TVI_LAST);
126 void setup_selected(HTREEITEM h = NULL);
127 void add_or_replace_operator(int op, int replace_flag = 0);
128 void replace_one_arg_operator(char *op, char *data, int type);
129 void replace_operator(char *op);
130 void replace_data(char *data, int type);
131 void replace_variable_data(int var_idx, int type);
132 void link_modified(int *ptr);
134 void ensure_visible(int node);
135 int node_error(int node, char *msg, int *bypass);
136 void expand_branch(HTREEITEM h);
137 void expand_operator(int node);
138 void merge_operator(int node);
139 int end_label_edit(HTREEITEM h, char *str);
140 int edit_label(HTREEITEM h);
141 int identify_arg_type(int node);
142 int count_args(int node);
143 void right_clicked(int mode = 0);
145 virtual void build_tree();
146 void set_node(int index, int type, char *text);
147 void free_node(int node, int cascade = 0);
148 int allocate_node(int parent, int after = -1);
150 void clear_tree(char *op = NULL);
151 void reset_handles();
152 int save_tree(int node = -1);
153 void load_tree(int index, char *deflt = "true");
154 void add_one_arg_operator(char *op, char *data, int type);
155 void add_operator(char *op, HTREEITEM h = TVI_ROOT);
156 int add_data(char *data, int type);
157 int add_variable_data(char *data, int type);
158 void add_sub_tree(int node, HTREEITEM root);
159 void hilite_item(int node);
160 int check_operator_validity(int op, int type);
161 char *match_closest_operator(char *str, int node);
162 void delete_sexp_tree_variable(const char *var_name);
163 void modify_sexp_tree_variable(const char *old_name, int sexp_var_index);
164 int get_item_index_to_var_index();
165 int get_tree_name_to_sexp_variable_index(const char *tree_name);
166 int get_modify_variable_first_arg_index();
167 int get_ambiguous_type(int parent);
168 int get_modify_variable_type();
169 int get_variable_count(const char *var_name);
172 sexp_list_item *get_listing_opf(int opf, int parent_node, int arg_index);
173 sexp_list_item *get_listing_opf_null();
174 sexp_list_item *get_listing_opf_bool(int parent_node = -1);
175 sexp_list_item *get_listing_opf_positive();
176 sexp_list_item *get_listing_opf_number();
177 sexp_list_item *get_listing_opf_ship(int parent_node = -1);
178 sexp_list_item *get_listing_opf_wing();
179 sexp_list_item *get_listing_opf_subsystem(int parent_node, int arg_index);
180 sexp_list_item *get_listing_opf_point();
181 sexp_list_item *get_listing_opf_iff();
182 sexp_list_item *get_listing_opf_ai_goal(int parent_node);
183 sexp_list_item *get_listing_opf_docker_point(int parent_node);
184 sexp_list_item *get_listing_opf_dockee_point(int parent_node);
185 sexp_list_item *get_listing_opf_message();
186 sexp_list_item *get_listing_opf_who_from();
187 sexp_list_item *get_listing_opf_priority();
188 sexp_list_item *get_listing_opf_waypoint_path();
189 sexp_list_item *get_listing_opf_ship_point();
190 sexp_list_item *get_listing_opf_ship_wing_point();
191 sexp_list_item *get_listing_opf_mission_name();
192 sexp_list_item *get_listing_opf_goal_name(int parent_node);
193 sexp_list_item *get_listing_opf_ship_wing();
194 sexp_list_item *get_listing_opf_ship_type();
195 sexp_list_item *get_listing_opf_keypress();
196 sexp_list_item *get_listing_opf_event_name(int parent_node);
197 sexp_list_item *get_listing_opf_ai_order();
198 sexp_list_item *get_listing_opf_skill_level();
199 sexp_list_item *get_listing_opf_medal_name();
200 sexp_list_item *get_listing_opf_weapon_name();
201 sexp_list_item *get_listing_opf_ship_class_name();
202 sexp_list_item *get_listing_opf_hud_gauge_name();
203 sexp_list_item *get_listing_opf_huge_weapon();
204 sexp_list_item *get_listing_opf_ship_not_player();
205 sexp_list_item *get_listing_opf_jump_nodes();
206 sexp_list_item *get_listing_opf_variable_names();
207 sexp_list_item *get_listing_opf_variable_type();
211 int select_sexp_node; // used to select an sexp item on dialog box open.
215 CImageList *m_p_image_list;
219 // ClassWizard generated virtual function overrides
220 //{{AFX_VIRTUAL(sexp_tree)
222 virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);
225 // Generated message map functions
227 //{{AFX_MSG(sexp_tree)
228 afx_msg void OnBegindrag(NMHDR* pNMHDR, LRESULT* pResult);
229 afx_msg void OnMouseMove(UINT nFlags, CPoint point);
230 afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
231 afx_msg void OnDestroy();
232 afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
233 afx_msg void OnKeydown(NMHDR* pNMHDR, LRESULT* pResult);
236 void load_branch(int index, int parent);
237 int save_branch(int cur, int at_root = 0);
238 void free_node2(int node);
242 sexp_tree_item nodes[MAX_SEXP_TREE_SIZE];
244 HTREEITEM item_handle;
246 // these 2 variables are used to help location data sources. Sometimes looking up
247 // valid data can require complex code just to get to an index that is required to
248 // locate data. These are set up in right_clicked() to try and short circuit having
249 // to do the lookup again in the code that actually does the adding or replacing of
250 // the data if it's selected.
251 int add_instance; // a source reference index indicator for adding data
252 int replace_instance; // a source reference index indicator for replacing data
254 DECLARE_MESSAGE_MAP()