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