1+ #include < stdio.h>
12#include " Core.h"
23#include < Console.h>
34
45#include < modules/Gui.h>
56
67#include " Types.h"
78
9+ #include " MemAccess.h"
810#include " df/biome_type.h"
911#include " df/inorganic_raw.h"
1012#include " df/material_flags.h"
1921
2022using df::global::world;
2123
24+ #define profile_file_name " .\\ data\\ init\\ embark_assistant_profile.txt"
25+
2226namespace embark_assist {
2327 namespace finder_ui {
2428
@@ -45,6 +49,10 @@ namespace embark_assist {
4549 evil_weather,
4650 reanimation,
4751 thralling,
52+ spire_count_min,
53+ spire_count_max,
54+ magma_min,
55+ magma_max,
4856 biome_count_min,
4957 biome_count_max,
5058 region_type_1,
@@ -136,6 +144,132 @@ namespace embark_assist {
136144
137145 // ==========================================================================================================
138146
147+ void save_profile () {
148+ color_ostream_proxy out (Core::getInstance ().getConsole ());
149+
150+ FILE * outfile = fopen (profile_file_name, " w" );
151+ fields i = first_fields;
152+
153+ while (true ) {
154+ out.print (" [%s:%i]\n " , state->finder_list [static_cast <int8_t >(i)].text .c_str (), state->ui [static_cast <int8_t >(i)]->current_value );
155+ fprintf (outfile, " [%s:%i]\n " , state->finder_list [static_cast <int8_t >(i)].text .c_str (), state->ui [static_cast <int8_t >(i)]->current_value );
156+ if (i == last_fields) {
157+ break ; // done
158+ }
159+
160+ i = static_cast <fields>(static_cast <int8_t >(i) + 1 );
161+ }
162+
163+ fclose (outfile);
164+ }
165+
166+ // ==========================================================================================================
167+
168+ void load_profile () {
169+ color_ostream_proxy out (Core::getInstance ().getConsole ());
170+ FILE * infile = fopen (profile_file_name, " r" );
171+
172+ if (!infile) {
173+ out.printerr (" No profile file found at %s\n " , profile_file_name);
174+ return ;
175+ }
176+
177+ fields i = first_fields;
178+ char line[80 ];
179+ int count = 80 ;
180+ bool found;
181+ int value;
182+
183+ while (true ) {
184+
185+ fgets (line, count, infile);
186+ if (line[0 ] != ' [' ) {
187+ out.printerr (" Failed to find token start '[' at line %i\n " , static_cast <int8_t >(i));
188+ return ;
189+ }
190+
191+ found = false ;
192+
193+ for (int k = 1 ; k < count; k++) {
194+ if (line[k] == ' :' ) {
195+ for (int l = 1 ; l < k; l++) {
196+ if (state->finder_list [static_cast <int8_t >(i)].text .c_str ()[l - 1 ] != line[l]) {
197+ out.printerr (" Token mismatch of %s vs %s\n " , line, state->finder_list [static_cast <int8_t >(i)].text .c_str ());
198+ return ;
199+ }
200+ }
201+ if (!sscanf (&line[k + 1 ], " %i]" , &value)) {
202+ out.printerr (" Value extraction failure from %s\n " , line);
203+ return ;
204+ }
205+
206+ for (int l = 0 ; l < state->ui [static_cast <int8_t >(i)]->list .size (); l++) {
207+ if (value == state->ui [static_cast <int8_t >(i)]->list [l].key ) {
208+ found = true ;
209+ break ;
210+ }
211+ }
212+
213+ if (!found) {
214+ out.printerr (" Value not found in plugin. Raw mismatch? %s\n " , line);
215+ return ;
216+ }
217+
218+ break ;
219+ }
220+ }
221+
222+ if (!found) {
223+ out.printerr (" Value delimiter not found in %s\n " , line);
224+ return ;
225+ }
226+
227+ if (i == last_fields) {
228+ break ; // done
229+ }
230+
231+ i = static_cast <fields>(static_cast <int8_t >(i) + 1 );
232+ }
233+
234+ fclose (infile);
235+
236+ // Checking done. No do the work.
237+
238+ infile = fopen (profile_file_name, " r" );
239+ i = first_fields;
240+
241+ while (true ) {
242+ fgets (line, count, infile);
243+
244+ for (int k = 1 ; k < count; k++) {
245+ if (line[k] == ' :' ) {
246+ sscanf (&line[k + 1 ], " %i]" , &value);
247+
248+ state->ui [static_cast <int8_t >(i)]->current_value = value;
249+
250+ for (int l = 0 ; l < state->ui [static_cast <int8_t >(i)]->list .size (); l++) {
251+ if (value == state->ui [static_cast <int8_t >(i)]->list [l].key ) {
252+ state->ui [static_cast <int8_t >(i)]->current_display_value = l;
253+ break ;
254+ }
255+ }
256+
257+ break ;
258+ }
259+ }
260+
261+ if (i == last_fields) {
262+ break ; // done
263+ }
264+
265+ i = static_cast <fields>(static_cast <int8_t >(i) + 1 );
266+ }
267+
268+ fclose (infile);
269+ }
270+
271+ // ==========================================================================================================
272+
139273 void ui_setup (embark_assist::defs::find_callbacks find_callback, uint16_t max_inorganic) {
140274// color_ostream_proxy out(Core::getInstance().getConsole());
141275 if (!embark_assist::finder_ui::state) {
@@ -419,6 +553,56 @@ namespace embark_assist {
419553
420554 break ;
421555
556+ case fields::spire_count_min:
557+ case fields::spire_count_max:
558+ for (int16_t k = -1 ; k <= 9 ; k++) {
559+ if (k == -1 ) {
560+ element->list .push_back ({ " N/A" , k });
561+ }
562+ else {
563+ element->list .push_back ({ std::to_string (k), k });
564+ }
565+ }
566+
567+ break ;
568+
569+ case fields::magma_min:
570+ case fields::magma_max:
571+ {
572+ embark_assist::defs::magma_ranges k = embark_assist::defs::magma_ranges::NA ;
573+ while (true ) {
574+ switch (k) {
575+ case embark_assist::defs::magma_ranges::NA :
576+ element->list .push_back ({ " N/A" , static_cast <int8_t >(k) });
577+ break ;
578+
579+ case embark_assist::defs::magma_ranges::Cavern_3:
580+ element->list .push_back ({ " 3:rd Cavern" , static_cast <int8_t >(k) });
581+ break ;
582+
583+ case embark_assist::defs::magma_ranges::Cavern_2:
584+ element->list .push_back ({ " 2:nd Cavern" , static_cast <int8_t >(k) });
585+ break ;
586+
587+ case embark_assist::defs::magma_ranges::Cavern_1:
588+ element->list .push_back ({ " 1:st Cavern" , static_cast <int8_t >(k) });
589+ break ;
590+
591+ case embark_assist::defs::magma_ranges::Volcano:
592+ element->list .push_back ({ " Volcano" , static_cast <int8_t >(k) });
593+ break ;
594+ }
595+
596+ if (k == embark_assist::defs::magma_ranges::Volcano) {
597+ break ;
598+ }
599+
600+ k = static_cast <embark_assist::defs::magma_ranges>(static_cast <int8_t >(k) + 1 );
601+ }
602+ }
603+
604+ break ;
605+
422606 case fields::biome_count_min:
423607 case fields::biome_count_max:
424608 for (int16_t k = 0 ; k < 10 ; k++) {
@@ -659,6 +843,22 @@ namespace embark_assist {
659843 state->finder_list .push_back ({ " Max Soil" , static_cast <int8_t >(i) });
660844 break ;
661845
846+ case fields::spire_count_min:
847+ state->finder_list .push_back ({ " Min Adamantine" , static_cast <int8_t >(i) });
848+ break ;
849+
850+ case fields::spire_count_max:
851+ state->finder_list .push_back ({ " Max Adamantine" , static_cast <int8_t >(i) });
852+ break ;
853+
854+ case fields::magma_min:
855+ state->finder_list .push_back ({ " Min Magma" , static_cast <int8_t >(i) });
856+ break ;
857+
858+ case fields::magma_max:
859+ state->finder_list .push_back ({ " Max Magma" , static_cast <int8_t >(i) });
860+ break ;
861+
662862 case fields::biome_count_min:
663863 state->finder_list .push_back ({ " Min Biome Count" , static_cast <int8_t >(i) });
664864 break ;
@@ -875,6 +1075,24 @@ namespace embark_assist {
8751075 static_cast <embark_assist::defs::soil_ranges>(state->ui [static_cast <uint8_t >(i)]->current_value );
8761076 break ;
8771077
1078+ case fields::spire_count_min:
1079+ finder.spire_count_min = state->ui [static_cast <uint8_t >(i)]->current_value ;
1080+ break ;
1081+
1082+ case fields::spire_count_max:
1083+ finder.spire_count_max = state->ui [static_cast <uint8_t >(i)]->current_value ;
1084+ break ;
1085+
1086+ case fields::magma_min:
1087+ finder.magma_min =
1088+ static_cast <embark_assist::defs::magma_ranges>(state->ui [static_cast <uint8_t >(i)]->current_value );
1089+ break ;
1090+
1091+ case fields::magma_max:
1092+ finder.magma_max =
1093+ static_cast <embark_assist::defs::magma_ranges>(state->ui [static_cast <uint8_t >(i)]->current_value );
1094+ break ;
1095+
8781096 case fields::biome_count_min:
8791097 finder.biome_count_min = state->ui [static_cast <uint8_t >(i)]->current_value ;
8801098 break ;
@@ -1015,17 +1233,25 @@ namespace embark_assist {
10151233 state->ui [state->finder_list_focus ]->current_index = 0 ;
10161234 }
10171235 }
1236+
10181237 } else if (input->count (df::interface_key::SELECT )) {
10191238 if (!state->finder_list_active ) {
10201239 state->ui [state->finder_list_focus ]->current_display_value = state->ui [state->finder_list_focus ]->current_index ;
10211240 state->ui [state->finder_list_focus ]->current_value = state->ui [state->finder_list_focus ]->list [state->ui [state->finder_list_focus ]->current_index ].key ;
10221241 state->finder_list_active = true ;
10231242 }
1243+
10241244 } else if (input->count (df::interface_key::CUSTOM_F )) {
10251245 input->clear ();
10261246 Screen::dismiss (this );
10271247 find ();
10281248 return ;
1249+
1250+ } else if (input->count (df::interface_key::CUSTOM_S )) { // Save
1251+ save_profile ();
1252+
1253+ } else if (input->count (df::interface_key::CUSTOM_L )) { // Load
1254+ load_profile ();
10291255 }
10301256 }
10311257
@@ -1041,15 +1267,19 @@ namespace embark_assist {
10411267 Screen::drawBorder (" Embark Assistant Site Finder" );
10421268
10431269 embark_assist::screen::paintString (lr_pen, 1 , 1 , " 4/6" );
1044- embark_assist::screen::paintString (white_pen, 4 , 1 , " :Shift list" );
1045- embark_assist::screen::paintString (lr_pen, 16 , 1 , " 8/2" );
1046- embark_assist::screen::paintString (white_pen, 19 , 1 , " :Up/down" );
1047- embark_assist::screen::paintString (lr_pen, 28 , 1 , " ENTER" );
1048- embark_assist::screen::paintString (white_pen, 33 , 1 , " :Select item" );
1049- embark_assist::screen::paintString (lr_pen, 46 , 1 , " f" );
1050- embark_assist::screen::paintString (white_pen, 47 , 1 , " :Find" );
1051- embark_assist::screen::paintString (lr_pen, 53 , 1 , " ESC" );
1052- embark_assist::screen::paintString (white_pen, 56 , 1 , " :Abort" );
1270+ embark_assist::screen::paintString (white_pen, 4 , 1 , " :<->" );
1271+ embark_assist::screen::paintString (lr_pen, 9 , 1 , " 8/2" );
1272+ embark_assist::screen::paintString (white_pen, 12 , 1 , " :Up/Down" );
1273+ embark_assist::screen::paintString (lr_pen, 21 , 1 , " ENTER" );
1274+ embark_assist::screen::paintString (white_pen, 26 , 1 , " :Select" );
1275+ embark_assist::screen::paintString (lr_pen, 34 , 1 , " f" );
1276+ embark_assist::screen::paintString (white_pen, 35 , 1 , " :Find" );
1277+ embark_assist::screen::paintString (lr_pen, 41 , 1 , " ESC" );
1278+ embark_assist::screen::paintString (white_pen, 44 , 1 , " :Abort" );
1279+ embark_assist::screen::paintString (lr_pen, 51 , 1 , " s" );
1280+ embark_assist::screen::paintString (white_pen, 52 , 1 , " :Save" );
1281+ embark_assist::screen::paintString (lr_pen, 58 , 1 , " l" );
1282+ embark_assist::screen::paintString (white_pen, 59 , 1 , " :Load" );
10531283
10541284 for (uint16_t i = 0 ; i < state->finder_list .size (); i++) {
10551285 if (i == state->finder_list_focus ) {
0 commit comments