naev 0.10.4
land.c
Go to the documentation of this file.
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
10#include <math.h>
11#include <stdio.h>
12#include <stdlib.h>
13#include "physfs.h"
14
15#include "naev.h"
18#include "land.h"
19
20#include "array.h"
21#include "camera.h"
22#include "conf.h"
23#include "dialogue.h"
24#include "economy.h"
25#include "equipment.h"
26#include "escort.h"
27#include "event.h"
28#include "gui.h"
29#include "gui_omsg.h"
30#include "hook.h"
31#include "land_outfits.h"
32#include "land_shipyard.h"
33#include "land_trade.h"
34#include "log.h"
35#include "map.h"
36#include "menu.h"
37#include "mission.h"
38#include "music.h"
39#include "ndata.h"
40#include "news.h"
41#include "nlua.h"
42#include "nlua_tk.h"
43#include "nluadef.h"
44#include "npc.h"
45#include "nstring.h"
46#include "ntime.h"
47#include "player.h"
48#include "player_fleet.h"
49#include "rng.h"
50#include "save.h"
51#include "shiplog.h"
52#include "toolkit.h"
53
54/*
55 * we use visited flags to not duplicate missions generated
56 */
57#define VISITED_LAND (1<<0)
58#define VISITED_COMMODITY (1<<1)
59#define VISITED_BAR (1<<2)
60#define VISITED_OUTFITS (1<<3)
61#define VISITED_SHIPYARD (1<<4)
62#define VISITED_EQUIPMENT (1<<5)
63#define VISITED_MISSION (1<<6)
64#define visited(f) (land_visited |= (f))
65#define has_visited(f) (land_visited & (f))
66static unsigned int land_visited = 0;
68/* Which tabs have been generated by their respective open functions. */
69unsigned int land_generated = 0;
70
71/*
72 * land variables
73 */
74int landed = 0;
75int land_loaded = 0;
76int land_takeoff = 0;
78unsigned int land_wid = 0;
79static int land_regen = 0;
80static int land_windowsMap[LAND_NUMWINDOWS];
81static unsigned int *land_windows = NULL;
82Spob* land_spob = NULL;
83static glTexture *gfx_exterior = NULL;
85/*
86 * mission computer stack
87 */
88static Mission* mission_computer = NULL;
89static int mission_ncomputer = 0;
91/*
92 * Bar stuff.
93 */
96/*
97 * player stuff
98 */
99static int last_window = 0;
100static int land_taboverride = 0;
102/*
103 * Error handling.
104 */
105static char errorlist[STRMAX_SHORT];
106static char errorreason[STRMAX_SHORT];
107static int errorappend;
108static char *errorlist_ptr;
109
110/*
111 * Rescue.
112 */
113static nlua_env rescue_env = LUA_NOREF;
114static void land_stranded (void);
115
116/*
117 * prototypes
118 */
119static int land_gc( void *unused );
120static int land_hasLocalMap (void);
121static void land_createMainTab( unsigned int wid );
122static void land_setupTabs (void);
123static void land_cleanupWindow( unsigned int wid, const char *name );
124static void land_changeTab( unsigned int wid, const char *wgt, int old, int tab );
125/* spaceport bar */
126static void bar_getDim( int wid, int *w, int *h, int *iw, int *ih, int *bw, int *bh );
127static void bar_open( unsigned int wid );
128static int bar_genList( unsigned int wid );
129static void bar_update( unsigned int wid, const char *str );
130static void bar_close( unsigned int wid, const char *str );
131static void bar_approach( unsigned int wid, const char *str );
132static int news_load (void);
133/* mission computer */
134static void misn_open( unsigned int wid );
135static void misn_autonav( unsigned int wid, const char *str );
136static void misn_accept( unsigned int wid, const char *str );
137static void misn_genList( unsigned int wid, int first );
138static void misn_update( unsigned int wid, const char *str );
139
144{
145 land_takeoff = 1;
146 land_takeoff_nosave = player_isFlag(PLAYER_NOSAVE);
147}
148
149void land_needsTakeoff( int delay )
150{
151 if (land_takeoff)
153}
154
155/* Maps are only offered if the spob provides fuel. */
156static int land_hasLocalMap (void)
157{
158 if (!spob_hasService( land_spob, SPOB_SERVICE_REFUEL ))
159 return 0;
160 return 1;
161}
162
166int land_canSave (void)
167{
168 /* Overrided case. */
169 if (player_isFlag( PLAYER_NOSAVE ))
170 return 0;
171
172 /* If the current landed planet is refuelable, no need to check if can land. */
173 if ((land_spob!=NULL) && spob_hasService(land_spob,SPOB_SERVICE_REFUEL))
174 return 1;
175
176 /* For other places we'll have to see if can land. */
177 for (int i=0; i<array_size(cur_system->spobs); i++) {
178 Spob *p = cur_system->spobs[i];
179 spob_updateLand( p );
180 if (spob_hasService(p,SPOB_SERVICE_REFUEL) && p->can_land)
181 return 1;
182 }
183 return 0;
184}
185
190{
191 if (landed && land_loaded)
192 return 1;
193 return 0;
194}
195
200int can_swapEquipment( const char *shipname )
201{
202 int diff;
203 Pilot *newship;
204 const PlayerShip_t *ps = player_getPlayerShip( shipname );
205
206 if (strcmp(shipname,player.p->name)==0) { /* Already onboard. */
207 land_errDialogueBuild( _("You're already onboard the %s."), shipname );
208 return 0;
209 }
210
211 /* Ship can't be piloted by player. */
212 if (ship_isFlag( ps->p->ship, SHIP_NOPLAYER )) {
213 land_errDialogueBuild( _("You can not pilot the %s! The ship can only be used as an escort."), shipname );
214 return 0;
215 }
216
217 /* Ship can't be set as an escort. */
218 if (ship_isFlag( player.p->ship, SHIP_NOESCORT )) {
219 land_errDialogueBuild( _("You can not swap ships and set %s as an escort!"), player.p->name );
220 return 0;
221 }
222
223 newship = ps->p;
224 if (ps->deployed)
225 diff = 0;
226 else
227 diff = pilot_cargoUsed(player.p) - pilot_cargoFree(newship) - (pfleet_cargoFree() - pilot_cargoFree(player.p)); /* Has to fit all the cargo. */
228 diff = MAX( diff, pilot_cargoUsedMission(player.p) - pilot_cargoFree(newship) ); /* Has to fit all mission cargo. */
229 if (diff > 0) { /* Current ship has too much cargo. */
231 "You have %d tonne more cargo than the new ship can hold.",
232 "You have %d tonnes more cargo than the new ship can hold.",
233 diff),
234 diff );
235 return 0;
236 }
237 if (pilot_hasDeployed( player.p )) {
238 if (!dialogue_YesNo(_("Recall Fighters"), _("This action will recall your deployed fighters. Is that OK?"))) {
239 land_errDialogueBuild( _("You have deployed fighters.") );
240 return 0;
241 }
242 /* Recall fighters. */
244 }
245 return 1;
246}
247
256int land_errDialogue( const char *name, const char *type )
257{
258 errorlist_ptr = NULL;
259 if (strcmp(type,"tradeShip")==0)
261 else if (strcmp(type,"buyShip")==0)
262 shipyard_canBuy( name, land_spob );
263 else if (strcmp(type,"swapEquipment")==0)
264 can_swapEquipment( name );
265 else if (strcmp(type,"swap")==0)
266 can_swap( name );
267 else if (strcmp(type,"sellShip")==0)
268 can_sell( name );
269 else if (strcmp(type,"buyOutfit")==0)
270 outfit_canBuy( name, land_spob );
271 else if (strcmp(type,"sellOutfit")==0)
272 outfit_canSell( name );
273 else if (strcmp(type,"buyCommodity")==0)
274 commodity_canBuy( commodity_get( name ) );
275 else if (strcmp(type,"sellCommodity")==0)
276 commodity_canSell( commodity_get( name ) );
277 if (errorlist_ptr != NULL) {
278 dialogue_alert( "%s", errorlist );
279 return 1;
280 }
281 return 0;
282}
283
288void land_errDialogueBuild( const char *fmt, ... )
289{
290 va_list ap;
291
292 if (fmt == NULL)
293 return;
294 else { /* get the message */
295 va_start(ap, fmt);
296 vsnprintf(errorreason, sizeof(errorreason), fmt, ap);
297 va_end(ap);
298 }
299
300 if (errorlist_ptr == NULL) /* Initialize on first run. */
301 errorappend = scnprintf( errorlist, sizeof(errorlist), "%s", errorreason );
302 else /* Append newest error to the existing list. */
303 scnprintf( &errorlist[errorappend], sizeof(errorlist)-errorappend, "\n%s", errorreason );
304 errorlist_ptr = errorlist;
305}
306
310static void bar_getDim( int wid,
311 int *w, int *h, int *iw, int *ih, int *bw, int *bh )
312{
313 /* Get window dimensions. */
314 window_dimWindow( wid, w, h );
315
316 /* Calculate dimensions of portraits. */
317 *iw = 704 + (*w - LAND_WIDTH);
318 *ih = *h - 60;
319
320 /* Calculate button dimensions. */
321 *bw = (*w - *iw - 80)/2;
322 *bh = LAND_BUTTON_HEIGHT;
323}
327static void bar_open( unsigned int wid )
328{
329 int w, h, iw, ih, bw, bh, dh, th;
330 const char *desc;
331
332 /* Mark as generated. */
333 land_tabGenerate(LAND_WINDOW_BAR);
334
335 /* Set window functions. */
337
338 /* Get dimensions. */
339 desc = (land_spob->bar_description!=NULL) ? _(land_spob->bar_description) : "(NULL)";
340 bar_getDim( wid, &w, &h, &iw, &ih, &bw, &bh );
341 dh = gl_printHeightRaw( &gl_defFont, w - iw - 60, desc );
342
343 /* Approach when pressing enter */
345
346 /* Buttons */
347 window_addButtonKey( wid, -20, 20,
348 bw, bh, "btnCloseBar",
349 _("Take Off"), land_buttonTakeoff, SDLK_t );
350 window_addButtonKey( wid, -20 - bw - 20, 20,
351 bw, bh, "btnApproach",
352 _("Approach"), bar_approach, SDLK_a );
353
354 /* Bar description. */
355 window_addText( wid, iw + 40, -40, w - iw - 60, dh, 0,
356 "txtDescription", &gl_defFont, NULL, desc );
357
358 /* Add portrait text. */
359 th = -40 - dh - 40;
360 window_addText( wid, iw + 40, th,
361 w - iw - 60, gl_defFont.h, 1,
362 "txtPortrait", &gl_defFont, NULL, NULL );
363
364 /* Add mission description text. */
365 th -= 20 + PORTRAIT_HEIGHT + 20 + 20;
366 window_addText( wid, iw + 60, th,
367 w - iw - 100, h + th - (2*bh+60), 0,
368 "txtMission", &gl_defFont, NULL, NULL );
369
370 /* Generate the mission list. */
371 bar_genList( wid );
372}
373
379static int bar_genList( unsigned int wid )
380{
381 ImageArrayCell *portraits;
382 int w, h, iw, ih, bw, bh;
383 int n, pos;
384
385 /* Validity check. */
386 if (wid == 0)
387 return 0;
388
389 /* Get dimensions. */
390 bar_getDim( wid, &w, &h, &iw, &ih, &bw, &bh );
391
392 /* Destroy widget if already exists. */
393 if (widget_exists( wid, "iarMissions" )) {
394 /* Store position. */
395 pos = toolkit_getImageArrayPos( wid, "iarMissions" );
396
397 window_destroyWidget( wid, "iarMissions" );
398 }
399 else
400 pos = -1;
401
402 /* We sort just in case. */
403 npc_sort();
404
405 /* Set up missions. */
406 if (mission_portrait == NULL)
407 mission_portrait = gl_newImage( PORTRAIT_GFX_PATH"news.webp", 0 );
408 n = npc_getArraySize();
409 if (n <= 0) {
410 n = 1;
411 portraits = calloc(1, sizeof(ImageArrayCell));
412 portraits[0].image = gl_dupTexture(mission_portrait);
413 portraits[0].caption = strdup(_("News"));
414 }
415 else {
416 n = n+1;
417 portraits = calloc(n, sizeof(ImageArrayCell));
418 portraits[0].image = gl_dupTexture(mission_portrait);
419 portraits[0].caption = strdup(_("News"));
420 for (int i=0; i<npc_getArraySize(); i++) {
421 ImageArrayCell *p = &portraits[i+1];
423 p->caption = strdup( npc_getName(i) );
424 if (bg!=NULL) {
425 p->image = gl_dupTexture( bg );
426 p->layers = gl_addTexArray( p->layers, &p->nlayers, gl_dupTexture( npc_getTexture(i) ) );
427 }
428 else
429 p->image = gl_dupTexture( npc_getTexture(i) );
430 if (npc_isImportant(i))
431 p->layers = gl_addTexArray( p->layers, &p->nlayers, gl_newImage( OVERLAY_GFX_PATH"portrait_exclamation.webp", 0 ) );
432 }
433 }
434 window_addImageArray( wid, 20, -40,
435 iw, ih, "iarMissions", 128, 96,
436 portraits, n, bar_update, bar_approach, bar_approach );
437
438 /* Restore position. */
439 toolkit_setImageArrayPos( wid, "iarMissions", pos );
440
441 /* write the outfits stuff */
442 bar_update( wid, NULL );
443
444 /* Set default keyboard focus. */
445 window_setFocus( wid, "iarMissions" );
446
447 return 0;
448}
452void bar_regen (void)
453{
454 if (!landed)
455 return;
456 if (!land_loaded)
457 return;
458 bar_genList( land_getWid(LAND_WINDOW_BAR) );
459}
465static void bar_update( unsigned int wid, const char *str )
466{
467 (void) str;
468 int pos;
469 int w, h, iw, ih, bw, bh, dh;
470
471 /* Get dimensions. */
472 bar_getDim( wid, &w, &h, &iw, &ih, &bw, &bh );
473 dh = gl_printHeightRaw( &gl_defFont, w - iw - 60, _(land_spob->bar_description) );
474
475 /* Get array. */
476 pos = toolkit_getImageArrayPos( wid, "iarMissions" );
477
478 /* See if is news. */
479 if (pos==0) { /* News selected. */
480 /* Destroy news widget if needed. */
481 if (widget_exists(wid, "cstNews"))
482 window_destroyWidget( wid, "cstNews" );
483
484 /* Destroy portrait. */
485 if (widget_exists(wid, "imgPortrait"))
486 window_destroyWidget(wid, "imgPortrait");
487 if (widget_exists(wid, "imgPortraitBG"))
488 window_destroyWidget(wid, "imgPortraitBG");
489
490 /* Disable button. */
491 window_disableButton( wid, "btnApproach" );
492
493 /* Clear text. */
494 window_modifyText( wid, "txtPortrait", NULL );
495 window_modifyText( wid, "txtMission", NULL );
496
497 /* Create news. */
498 news_widget( wid, iw + 60, -40 - (40 + dh),
499 w - iw - 100, h - 40 - (dh+20) - 40 - bh - 20 );
500 return;
501 }
502
503 /* Shift to ignore news now. */
504 pos--;
505
506 /* Destroy news widget if needed. */
507 if (widget_exists(wid, "cstNews"))
508 window_destroyWidget( wid, "cstNews" );
509
510 /* Create widgets if needed. */
511 if (!widget_exists(wid, "imgPortraitBG")) /* Must be first */
512 window_addImage( wid, iw + 40 + (w-iw-60-PORTRAIT_WIDTH)/2,
513 -(40 + dh + 40 + gl_defFont.h + 20 + PORTRAIT_HEIGHT),
514 0, 0, "imgPortraitBG", NULL, 1 );
515 if (!widget_exists(wid, "imgPortrait"))
516 window_addImage( wid, iw + 40 + (w-iw-60-PORTRAIT_WIDTH)/2,
517 -(40 + dh + 40 + gl_defFont.h + 20 + PORTRAIT_HEIGHT),
518 0, 0, "imgPortrait", NULL, 1 );
519
520 /* Enable button. */
521 window_enableButton( wid, "btnApproach" );
522
523 /* Set portrait. */
524 window_modifyText( wid, "txtPortrait", npc_getName( pos ) );
525 window_modifyImage( wid, "imgPortrait", npc_getTexture( pos ),
526 PORTRAIT_WIDTH, PORTRAIT_HEIGHT );
527 window_modifyImage( wid, "imgPortraitBG", npc_getBackground( pos ),
528 PORTRAIT_WIDTH, PORTRAIT_HEIGHT );
529
530 /* Set mission description. */
531 window_modifyText( wid, "txtMission", npc_getDesc( pos ));
532}
538static void bar_close( unsigned int wid, const char *name )
539{
540 (void) wid;
541 (void) name;
542
543 /* Must not be regenerating. */
544 if (land_regen) {
545 land_regen--;
546 return;
547 }
548
550 mission_portrait = NULL;
551}
555static void bar_approach( unsigned int wid, const char *str )
556{
557 (void) str;
558 int pos, n;
559
560 /* Get position. */
561 pos = toolkit_getImageArrayPos( wid, "iarMissions" );
562
563 /* Should never happen, but in case news is selected */
564 if (pos == 0)
565 return;
566
567 /* Ignore news. */
568 pos--;
569
570 n = npc_getArraySize();
571 npc_approach( pos );
572 /* This check is necessary if the player quits the game in the middle of an NPC approach. */
573 if (land_spob==NULL)
574 return;
575 bar_genList( wid ); /* Always just in case. */
576
577 /* Focus the news if the number of NPCs has changed. */
578 if (n != npc_getArraySize())
579 toolkit_setImageArrayPos( wid, "iarMissions", 0 );
580
581 /* Reset markers. */
583
584 /* Mission forced take off. */
585 land_needsTakeoff( 0 );
586}
592static int news_load (void)
593{
595 return 0;
596}
597
598
602static void misn_open( unsigned int wid )
603{
604 int w,h, y;
605
606 /* Mark as generated. */
607 land_tabGenerate(LAND_WINDOW_MISSION);
608
609 /* Get window dimensions. */
610 window_dimWindow( wid, &w, &h );
611
612 /* buttons */
613 window_addButtonKey( wid, -20, 20,
614 LAND_BUTTON_WIDTH,LAND_BUTTON_HEIGHT, "btnCloseMission",
615 _("Take Off"), land_buttonTakeoff, SDLK_t );
616 window_addButtonKey( wid, -20, 40+LAND_BUTTON_HEIGHT,
617 LAND_BUTTON_WIDTH,LAND_BUTTON_HEIGHT, "btnAcceptMission",
618 _("Accept Mission"), misn_accept, SDLK_a );
619 window_addButtonKey( wid, -20, 60+2*LAND_BUTTON_HEIGHT,
620 LAND_BUTTON_WIDTH,LAND_BUTTON_HEIGHT, "btnAutonavMission",
621 _("Autonav"), misn_autonav, SDLK_n );
622
623 /* text */
624 y = -60;
625 window_addText( wid, w/2 + 10, y,
626 w/2 - 30, 40, 0,
627 "txtSDate", NULL, &cFontGrey,
628 _("Date:\n"
629 "Free Space:"));
630 window_addText( wid, w/2 + 110, y,
631 w/2 - 130, 40, 0,
632 "txtDate", NULL, NULL, NULL );
633 y -= 2 * gl_defFont.h + 30;
634 window_addText( wid, w/2 + 10, y,
635 w/2 - 30, 50, 0,
636 "txtHeader", &gl_defFont, NULL, NULL );
637 y -= 50;
638 window_addText( wid, w/2 + 10, y,
639 w/2 - 30, y - 40 + h - 2*LAND_BUTTON_HEIGHT, 0,
640 "txtDesc", &gl_defFont, NULL, NULL );
641
642 /* map */
643 map_show( wid, 20, 20, w/2 - 30, h/2 - 35, 0.75, 0., 0. );
644
645 misn_genList(wid, 1);
646 space_clearComputerMarkers(); /* Don't want markers at the beginning. */
647}
653static void misn_autonav( unsigned int wid, const char *str )
654{
655 Mission* misn;
656 const StarSystem *sys;
657 (void) str;
658
659 /* Makes sure current mission has system */
660 misn = &mission_computer[ toolkit_getListPos( wid, "lstMission" ) ];
661 sys = mission_sysComputerMark( misn );
662 if (sys==NULL)
663 return;
664
665 /* Select mission's target system */
666 map_select( sys,0 );
667
668 /* Autonav to target system */
671}
677static void misn_accept( unsigned int wid, const char *str )
678{
679 (void) str;
680 const char* misn_name;
681 Mission* misn;
682 int pos, ret;
683
684 misn_name = toolkit_getList( wid, "lstMission" );
685
686 /* Make sure you have missions. */
687 if (strcmp(misn_name,_("No Missions"))==0)
688 return;
689
690 if (dialogue_YesNo( _("Accept Mission"),
691 _("Are you sure you want to accept this mission?"))) {
692 int changed = 0;
693 pos = toolkit_getListPos( wid, "lstMission" );
694 misn = &mission_computer[pos];
695 ret = mission_accept( misn );
696 if (ret==-1) { /* Errored out. */
698 changed = 1;
699 }
700 if ((ret==2) || (ret==3)) /* Deleted or accepted. */
701 changed = 1;
702
703 if (changed) {
704 memmove( &mission_computer[pos], &mission_computer[pos+1],
705 sizeof(Mission) * (mission_ncomputer-pos-1) );
707
708 /* Regenerate list. */
709 misn_genList(wid, 0);
710 /* Add position persistancey after a mission has been accepted */
711 /* NOTE: toolkit_setListPos protects us from a bad position by clamping */
712 toolkit_setListPos( wid, "lstMission", pos-1 ); /*looks better without the -1, makes more sense with*/
713 }
714
715 /* Reset markers. */
717 }
718}
724static void misn_genList( unsigned int wid, int first )
725{
726 char** misn_names;
727 int j, w,h;
728
729 if (!first)
730 window_destroyWidget( wid, "lstMission" );
731
732 /* Get window dimensions. */
733 window_dimWindow( wid, &w, &h );
734
735 /* list */
736 j = 1; /* make sure we don't accidentally free the memory twice. */
737 misn_names = NULL;
738 if (mission_ncomputer > 0) { /* there are missions */
739 misn_names = malloc(sizeof(char*) * mission_ncomputer);
740 j = 0;
741 for (int i=0; i<mission_ncomputer; i++)
742 if (mission_computer[i].title != NULL)
743 misn_names[j++] = strdup(mission_computer[i].title);
744 }
745 if ((misn_names==NULL) || (mission_ncomputer==0) || (j==0)) { /* no missions. */
746 if (j==0)
747 free(misn_names);
748 misn_names = malloc(sizeof(char*));
749 misn_names[0] = strdup(_("No Missions"));
750 j = 1;
751 }
752 window_addList( wid, 20, -40,
753 w/2 - 30, h/2 - 35,
754 "lstMission", misn_names, j, 0, misn_update, misn_accept );
755
756 /* Set default keyboard focus. */
757 window_setFocus( wid, "lstMission" );
758}
764static void misn_update( unsigned int wid, const char *str )
765{
766 (void) str;
767 const char *active_misn;
768 Mission* misn;
769 const StarSystem *sys;
770 char txt[STRMAX_SHORT], *buf;
771
772 /* Clear computer markers. */
774
775 /* Update date stuff. */
776 buf = ntime_pretty( 0, 2 );
777 snprintf( txt, sizeof(txt), n_(
778 "%s\n%d Tonne", "%s\n%d Tonnes", player.p->cargo_free),
779 buf, player.p->cargo_free );
780 free(buf);
781 window_modifyText( wid, "txtDate", txt );
782
783 active_misn = toolkit_getList( wid, "lstMission" );
784 if (strcmp(active_misn,_("No Missions"))==0) {
785 window_modifyText( wid, "txtHeader", NULL );
786 window_modifyText( wid, "txtDesc",
787 _("There are no missions available here.") );
788 window_disableButton( wid, "btnAcceptMission" );
789 window_disableButton( wid, "btnAutonavMission" );
790 return;
791 }
792
793 misn = &mission_computer[ toolkit_getListPos( wid, "lstMission" ) ];
794 sys = mission_sysComputerMark( misn );
795 if (sys!=NULL)
796 map_center( wid, sys->name );
797 snprintf( txt, sizeof(txt), _("%s\n#nReward:#0 %s"), misn->title, misn->reward );
798 window_modifyText( wid, "txtHeader", txt );
799 window_modifyText( wid, "txtDesc", misn->desc );
800 window_enableButton( wid, "btnAcceptMission" );
801 window_enableButton( wid, "btnAutonavMission" );
802}
803
807void land_refuel (void)
808{
809 unsigned int w;
810
811 /* Full fuel. */
812 if (player.p->fuel >= player.p->fuel_max)
813 return;
814
815 /* No refuel service. */
816 if (!spob_hasService(land_spob, SPOB_SERVICE_REFUEL))
817 return;
818
820
821 w = land_getWid( LAND_WINDOW_EQUIPMENT );
822 if (w > 0)
823 equipment_updateShips( w, NULL ); /* Must update counter. */
824}
825
829static void spaceport_buyMap( unsigned int wid, const char *str )
830{
831 (void) wid;
832 (void) str;
833 const Outfit *o;
834 unsigned int w;
835
836 /* Make sure the map isn't already known, etc. */
837 if (land_errDialogue( LOCAL_MAP_NAME, "buyOutfit" ))
838 return;
839
840 o = outfit_get( LOCAL_MAP_NAME );
841 if (o == NULL) {
842 WARN( _("Outfit '%s' does not exist!"), LOCAL_MAP_NAME);
843 return;
844 }
845
847 player_addOutfit(o, 1);
848
849 /* Disable the button. */
850 window_disableButtonSoft( land_windows[0], "btnMap" );
851
852 /* Update map quantity in outfitter. */
853 w = land_getWid( LAND_WINDOW_OUTFITS );
854 if (w > 0)
855 outfits_regenList( w, NULL );
856
857 /* Update main tab. */
859}
860
865{
866 char buf[STRMAX], cred[ECON_CRED_STRLEN], tons[STRMAX_SHORT];
867 size_t l = 0;
868 const Outfit *o;
869
870 /* Update credits. */
871 tonnes2str( tons, player.p->cargo_free );
872 credits2str( cred, player.p->credits, 2 );
873 l += scnprintf( &buf[l], sizeof(buf)-l, _("%s (%s system)"), spob_name(land_spob), _(cur_system->name) );
874 l += scnprintf( &buf[l], sizeof(buf)-l, "\n%s", "" );
875 l += scnprintf( &buf[l], sizeof(buf)-l, _("%s (%s-class)"), spob_getClassName(land_spob->class), _(land_spob->class) );
876 l += scnprintf( &buf[l], sizeof(buf)-l, "\n%s",
878 l += scnprintf( &buf[l], sizeof(buf)-l, "\n%s", "" );
879 l += scnprintf( &buf[l], sizeof(buf)-l, _("roughly %s"), space_populationStr( land_spob->population ) );
880 l += scnprintf( &buf[l], sizeof(buf)-l, "\n\n%s", tons );
881 l += scnprintf( &buf[l], sizeof(buf)-l, "\n%s", cred );
882 /* Show tags. */
883 if (conf.devmode) {
884 l += scnprintf( &buf[l], sizeof(buf)-l, "\n%s", "" );
885 for (int i=0; i<array_size(land_spob->tags); i++)
886 l += scnprintf( &buf[l], sizeof(buf)-l, "%s%s", ((i>0) ? _(", ") : ""), _(land_spob->tags[i]) );
887 }
888
889 window_modifyText( land_windows[0], "txtDInfo", buf );
890
891 /* Make sure maps are available. */
892 if (!land_hasLocalMap())
893 return;
894
895 o = outfit_get( LOCAL_MAP_NAME );
896 if (o == NULL) {
897 WARN( _("Outfit '%s' does not exist!"), LOCAL_MAP_NAME);
898 return;
899 }
900
901 /* Just enable button if it exists. */
902 if (widget_exists( land_windows[0], "btnMap" ))
903 window_enableButton( land_windows[0], "btnMap");
904 /* Else create it. */
905 else {
906 /* Refuel button. */
907 credits2str( cred, o->price, 0 );
908 snprintf( buf, sizeof(buf), _("Buy Local Map (%s)"), cred );
909 window_addButtonKey( land_windows[0], -20, 20 + (LAND_BUTTON_HEIGHT + 20),
910 LAND_BUTTON_WIDTH, LAND_BUTTON_HEIGHT, "btnMap",
911 buf, spaceport_buyMap, SDLK_b );
912 }
913
914 /* Make sure player can click it. */
915 if (!outfit_canBuy(LOCAL_MAP_NAME, land_spob))
916 window_disableButtonSoft( land_windows[0], "btnMap" );
917}
918
925void land_buttonTakeoff( unsigned int wid, const char *unused )
926{
927 (void) wid;
928 (void) unused;
929 /* We'll want the time delay. */
930 takeoff( 1, player_isFlag(PLAYER_NOSAVE) );
931}
932
939static void land_cleanupWindow( unsigned int wid, const char *name )
940{
941 (void) wid;
942 (void) name;
943
944 /* Must not be regenerating. */
945 if (land_regen) {
946 land_regen--;
947 return;
948 }
949
950 /* Clean up possible stray graphic. */
951 if (gfx_exterior != NULL) {
953 gfx_exterior = NULL;
954 }
955}
956
963unsigned int land_getWid( int window )
964{
965 if (land_windowsMap[window] == -1)
966 return 0;
967 return land_windows[ land_windowsMap[window] ];
968}
969
973static void land_setupTabs (void)
974{
975 int j;
976 const char *names[LAND_NUMWINDOWS];
977
978 /* Destroy if exists. */
979 if (widget_exists( land_wid, "tabLand" ))
980 window_destroyWidget( land_wid, "tabLand" );
981
982 /* Set window map to invalid. */
983 for (int i=0; i<LAND_NUMWINDOWS; i++)
984 land_windowsMap[i] = -1;
985
986 /* See what is available. */
987 j = 0;
988 /* Main. */
989 land_windowsMap[LAND_WINDOW_MAIN] = j;
990 names[j++] = _("Landing Main");
991 /* Bar. */
992 if (spob_hasService(land_spob, SPOB_SERVICE_BAR)) {
993 land_windowsMap[LAND_WINDOW_BAR] = j;
994 names[j++] = _("Spaceport Bar");
995 }
996 /* Missions. */
997 if (spob_hasService(land_spob, SPOB_SERVICE_MISSIONS)) {
998 land_windowsMap[LAND_WINDOW_MISSION] = j;
999 names[j++] = _("Missions");
1000 }
1001 /* Outfits. */
1002 if (spob_hasService(land_spob, SPOB_SERVICE_OUTFITS)) {
1003 land_windowsMap[LAND_WINDOW_OUTFITS] = j;
1004 names[j++] = _("Outfits");
1005 }
1006 /* Shipyard. */
1007 if (spob_hasService(land_spob, SPOB_SERVICE_SHIPYARD)) {
1008 land_windowsMap[LAND_WINDOW_SHIPYARD] = j;
1009 names[j++] = _("Shipyard");
1010 }
1011 /* Equipment. */
1012 if (spob_hasService(land_spob, SPOB_SERVICE_OUTFITS) ||
1013 spob_hasService(land_spob, SPOB_SERVICE_SHIPYARD)) {
1014 land_windowsMap[LAND_WINDOW_EQUIPMENT] = j;
1015 names[j++] = p_("service", "Equipment");
1016 }
1017 /* Commodity. */
1018 if (spob_hasService(land_spob, SPOB_SERVICE_COMMODITY)) {
1019 land_windowsMap[LAND_WINDOW_COMMODITY] = j;
1020 names[j++] = _("Commodity");
1021 }
1022
1023 land_windows = window_addTabbedWindow( land_wid, -1, -1, -1, -1, "tabLand", j, names, 0 );
1024}
1025
1032void land_genWindows( int load, int changetab )
1033{
1034 int w, h;
1035 Spob *p;
1036 int regen;
1037 unsigned int pntservices;
1038
1039 /* Destroy old window if exists. */
1040 if (land_wid > 0) {
1041 land_regen = 2; /* Mark we're regenning. */
1043
1044 /* Mark tabs as not generated. */
1045 land_generated = 0;
1046 }
1047 land_loaded = 0;
1048 land_taboverride = 0; /* Can get overwritten later. */
1049
1050 /* Get spob. */
1051 p = land_spob;
1052 regen = landed;
1053 pntservices = p->services;
1054
1055 /* Create window. */
1056 if (SCREEN_W < LAND_WIDTH || SCREEN_H < LAND_HEIGHT) {
1057 w = -1; /* Fullscreen. */
1058 h = -1;
1059 }
1060 else {
1061 w = LAND_WIDTH + 0.5 * (SCREEN_W - LAND_WIDTH);
1062 h = LAND_HEIGHT + 0.5 * (SCREEN_H - LAND_HEIGHT);
1063 }
1064 land_wid = window_create( "wdwLand", spob_name(p), -1, -1, w, h );
1066
1067 /* Create tabbed window. */
1069
1070 /*
1071 * Order here is very important:
1072 *
1073 * 1) Create main tab - must have decent background.
1074 * 2) Set landed, play music and run land hooks - so hooks run well.
1075 * 3) Generate missions - so that campaigns are fluid.
1076 * 4) Create other tabs - lists depend on NPC and missions.
1077 */
1078 /* 1) Create main tab. */
1079 land_createMainTab( land_getWid(LAND_WINDOW_MAIN) );
1080
1081 /* Add local system map button. */
1083
1084 /* 2) Set as landed and run hooks. */
1085 if (!regen) {
1086 landed = 1;
1087 music_choose("land"); /* Must be before hooks in case hooks change music. */
1088
1089 /* We don't run the "land" hook when loading. If you want to have it do stuff when loading, use the "load" hook.
1090 * Note that you can use the same function for both hooks. */
1091 if (!load)
1092 hooks_run("land");
1093 else
1094 hooks_run("load"); /* Should be run before generating missions, so if the load hook cancels a mission, it can reappear. */
1095 events_trigger( EVENT_TRIGGER_LAND );
1096
1097 /* An event, hook or the likes made Naev quit. */
1098 if (naev_isQuit())
1099 return;
1100
1101 /* Make sure services didn't change or we have to do the tab window. */
1102 if (land_spob->services != pntservices) {
1104 land_createMainTab( land_getWid(LAND_WINDOW_MAIN) );
1106 }
1107
1108 /* 3) Generate computer and bar missions. */
1109 /* Generate bar missions first for claims. */
1110 if (spob_hasService(land_spob, SPOB_SERVICE_BAR))
1111 npc_generateMissions(); /* Generate bar npc. */
1112 if (spob_hasService(land_spob, SPOB_SERVICE_MISSIONS))
1115 MIS_AVAIL_COMPUTER );
1116 }
1117
1118 /* 4) Create other tabs. */
1119#define should_open(s, w) \
1120 (spob_hasService(land_spob, s) && (!land_tabGenerated(w)))
1121
1122 /* Things get a bit hairy here. Hooks may have triggered a GUI reload via
1123 * e.g. player.swapShip, so the land tabs may have been generated already
1124 * and we need to check that before regenerating them.
1125 */
1126
1127 /* Basic - bar + missions */
1128 if (should_open( SPOB_SERVICE_BAR, LAND_WINDOW_BAR ))
1129 bar_open( land_getWid(LAND_WINDOW_BAR) );
1130 if (should_open( SPOB_SERVICE_MISSIONS, LAND_WINDOW_MISSION ))
1131 misn_open( land_getWid(LAND_WINDOW_MISSION) );
1132 /* Outfits. */
1133 if (should_open( SPOB_SERVICE_OUTFITS, LAND_WINDOW_OUTFITS ))
1134 outfits_open( land_getWid(LAND_WINDOW_OUTFITS), NULL );
1135 /* Shipyard. */
1136 if (should_open( SPOB_SERVICE_SHIPYARD, LAND_WINDOW_SHIPYARD ))
1137 shipyard_open( land_getWid(LAND_WINDOW_SHIPYARD) );
1138 /* Equipment. */
1139 if ((spob_hasService(land_spob, SPOB_SERVICE_OUTFITS) ||
1140 spob_hasService(land_spob, SPOB_SERVICE_SHIPYARD)) &&
1141 !land_tabGenerated( LAND_WINDOW_EQUIPMENT ))
1142 equipment_open( land_getWid(LAND_WINDOW_EQUIPMENT) );
1143 /* Commodity. */
1144 if (should_open( SPOB_SERVICE_COMMODITY, LAND_WINDOW_COMMODITY ))
1145 commodity_exchange_open( land_getWid(LAND_WINDOW_COMMODITY) );
1146#undef should_open
1147
1148 if (!regen) {
1149 /* Reset markers if needed. */
1151
1152 /* Check land missions. */
1153 if (!has_visited(VISITED_LAND)) {
1154 missions_run(MIS_AVAIL_LAND, land_spob->presence.faction,
1157 }
1158 }
1159
1160 /* Go to last open tab. */
1161 window_tabWinOnChange( land_wid, "tabLand", land_changeTab );
1162 if ((land_taboverride || changetab) && land_windowsMap[ last_window ] != -1)
1163 window_tabWinSetActive( land_wid, "tabLand", land_windowsMap[ last_window ] );
1164
1165 /* Refresh the map button in case the player couldn't afford it prior to
1166 * mission payment. */
1168
1169 /* Refuel if necessary. */
1170 land_refuel();
1171
1172 /* Finished loading. */
1173 land_loaded = 1;
1174
1175 /* Necessary if player.land() was run in an abort() function. */
1176 if (!load)
1178}
1179
1186int land_setWindow( int window )
1187{
1188 if (land_windowsMap[ window ] < 0)
1189 return -1;
1190 last_window = window;
1191 land_taboverride = 1;
1192 window_tabWinSetActive( land_wid, "tabLand", land_windowsMap[window] );
1193 return 0;
1194}
1195
1201void land( Spob* p, int load )
1202{
1203 /* Do not land twice. */
1204 if (landed)
1205 return;
1206
1207 /* Incrcement times player landed. */
1208 if (!load) {
1211 }
1212
1213 /* Clear some unnecessary flags. */
1214 pilot_rmFlag( player.p, PILOT_COOLDOWN_BRAKE);
1215 pilot_rmFlag( player.p, PILOT_COOLDOWN );
1216
1217 /* Resets the player's heat. */
1219
1220 /* Heal the player so GUI shows player at full everything. */
1222
1223 player_addEscorts(); /* TODO only regenerate fleet if planet has a shipyard */
1224
1225 /* Stop player sounds. */
1227
1228 /* Clear message stuff. */
1229 free( player.p->comm_msg );
1230 player.p->comm_msg = NULL;
1231
1232 /* Clear some target stuff. */
1233 player.p->nav_spob = -1;
1234 gui_setNav();
1235
1236 /* Load stuff */
1237 land_spob = p;
1238 gfx_exterior = gl_newImage( p->gfx_exterior, 0 );
1239
1240 /* Run outfits as necessary. */
1242
1243 /* Generate the news. */
1244 if (spob_hasService(land_spob, SPOB_SERVICE_BAR))
1245 news_load();
1246
1247 /* Average economy prices that player has seen */
1248 economy_averageSeenPrices( p );
1249
1250 /* Clear the NPC. */
1251 npc_clear();
1252
1253 /* Create all the windows. */
1254 land_genWindows( load, 0 );
1255
1256 /* Just in case? */
1257 bar_regen();
1258
1259 /* Don't do a fade in. */
1260 if (load)
1261 window_setFade( land_wid, NULL, 0. );
1262
1263 /* Do a lua collection pass. Run in a hook since land can be called indirectly from Lua. */
1264 hook_addFunc( land_gc, NULL, "safe" );
1265
1266 /* Mission forced take off. */
1267 land_needsTakeoff( 0 );
1268}
1269
1273static int land_gc( void *unused )
1274{
1275 (void) unused;
1276 lua_gc( naevL, LUA_GCCOLLECT, 0 );
1277 return 0;
1278}
1279
1285static void land_createMainTab( unsigned int wid )
1286{
1287 const glTexture *logo;
1288 int offset;
1289 int w, h, y, logow, logoh, th;
1290 char buf[STRMAX_SHORT];
1291 size_t l = 0;
1292
1293 /* Get window dimensions. */
1294 window_dimWindow( wid, &w, &h );
1295
1296 /*
1297 * Faction logo.
1298 */
1299 offset = 20;
1300 if (land_spob->presence.faction != -1) {
1302 if (logo != NULL) {
1303 logow = logo->w * (double)FACTION_LOGO_SM / MAX( logo->w, logo->h );
1304 logoh = logo->h * (double)FACTION_LOGO_SM / MAX( logo->w, logo->h );
1305 window_addImage( wid, 440 + (w-460-logow)/2, -20,
1306 logow, logoh, "imgFaction", logo, 0 );
1307 offset += FACTION_LOGO_SM;
1308 }
1309 }
1310
1311 /*
1312 * Pretty display.
1313 */
1314 window_addImage( wid, 20, -40, 400, 400, "imgSpob", gfx_exterior, 1 );
1315 if (land_spob->description != NULL)
1316 window_addText( wid, 440, -20-offset,
1317 w-460, h-20-offset-60-LAND_BUTTON_HEIGHT*2, 0,
1318 "txtSpobDesc", &gl_defFont, NULL, _(land_spob->description) );
1319
1320 /* Player stats. */
1321 l += scnprintf( &buf[l], sizeof(buf)-l, "#n%s", _("Stationed at:") );
1322 l += scnprintf( &buf[l], sizeof(buf)-l, "\n%s", _("Class:") );
1323 l += scnprintf( &buf[l], sizeof(buf)-l, "\n%s", _("Faction:") );
1324 l += scnprintf( &buf[l], sizeof(buf)-l, "\n%s", _("Population:") );
1325 l += scnprintf( &buf[l], sizeof(buf)-l, "\n\n%s", _("Free Space:") );
1326 l += scnprintf( &buf[l], sizeof(buf)-l, "\n%s", _("Money:") );
1327 if (conf.devmode)
1328 l += scnprintf( &buf[l], sizeof(buf)-l, "\n%s", _("Tags:") );
1329 th = gl_printHeightRaw( &gl_defFont, 200, buf );
1330 window_addText( wid, 20, 20, 200, th,
1331 0, "txtSInfo", &gl_defFont, NULL, buf );
1332 window_addText( wid, 20+120, 20, w - 20 - (20+200) - LAND_BUTTON_WIDTH,
1333 th, 0, "txtDInfo", &gl_defFont, NULL, NULL );
1334
1335 /*
1336 * buttons
1337 */
1338 /* first column */
1339 window_addButtonKey( wid, -20, 20,
1340 LAND_BUTTON_WIDTH, LAND_BUTTON_HEIGHT, "btnTakeoff",
1341 _("Take Off"), land_buttonTakeoff, SDLK_t );
1342
1343 /* Additional notices if necessary. */
1344 l = 0;
1345 buf[0] = '\0';
1346 y = 20 + (LAND_BUTTON_HEIGHT + 20) + 20;
1347 if (land_hasLocalMap())
1348 y += LAND_BUTTON_HEIGHT + 20;
1349 /* Add "no refueling" notice if needed. */
1350 if (!spob_hasService(land_spob, SPOB_SERVICE_REFUEL))
1351 l += scnprintf( &buf[l], sizeof(buf)-l, _("No refueling services.") );
1352 if (!land_canSave()) {
1353 if (l > 0)
1354 l += scnprintf( &buf[l], sizeof(buf)-l, "\n" );
1355 l += scnprintf( &buf[l], sizeof(buf)-l, "#r%s#0", _("Game will not be saved.") );
1356 }
1357 if (l>0) {
1358 th = gl_printHeightRaw( &gl_defFont, 200, buf );
1359 window_addText( land_windows[0], -20, y, 200, th, 0,
1360 "txtPlayer", &gl_defFont, NULL, buf );
1361 }
1362}
1363
1372static void land_changeTab( unsigned int wid, const char *wgt, int old, int tab )
1373{
1374 (void) wid;
1375 (void) wgt;
1376 (void) old;
1377 unsigned int w;
1378 /* Safe defaults. */
1379 const char *torun_hook = NULL;
1380 unsigned int to_visit = 0;
1381
1382 /* Clear markers when not open. */
1383 if (last_window == LAND_WINDOW_MISSION)
1385
1386 /* Find what switched. */
1387 for (int i=0; i<LAND_NUMWINDOWS; i++) {
1388 if (land_windowsMap[i] != tab)
1389 continue;
1390 last_window = i;
1391 w = land_getWid( i );
1392
1393 /* Must regenerate outfits. */
1394 switch (i) {
1395 case LAND_WINDOW_MAIN:
1397 break;
1398 case LAND_WINDOW_OUTFITS:
1399 outfits_update( w, NULL );
1400 to_visit = VISITED_OUTFITS;
1401 torun_hook = "outfits";
1402 break;
1403 case LAND_WINDOW_SHIPYARD:
1404 shipyard_update( w, NULL );
1405 to_visit = VISITED_SHIPYARD;
1406 torun_hook = "shipyard";
1407 break;
1408 case LAND_WINDOW_BAR:
1409 bar_update( w, NULL );
1410 to_visit = VISITED_BAR;
1411 torun_hook = "bar";
1412 break;
1413 case LAND_WINDOW_MISSION:
1414 misn_update( w, NULL );
1415 to_visit = VISITED_MISSION;
1416 torun_hook = "mission";
1417 break;
1418 case LAND_WINDOW_COMMODITY:
1419 commodity_update( w, NULL );
1420 to_visit = VISITED_COMMODITY;
1421 torun_hook = "commodity";
1422 break;
1423 case LAND_WINDOW_EQUIPMENT:
1424 equipment_updateShips( w, NULL );
1425 equipment_updateOutfits( w, NULL );
1426 to_visit = VISITED_EQUIPMENT;
1427 torun_hook = "equipment";
1428 break;
1429
1430 default:
1431 break;
1432 }
1433
1434 /* Clear markers if closing Mission Computer. */
1435 if (i != LAND_WINDOW_MISSION)
1437
1438 break;
1439 }
1440
1441 /* Check land missions - always run hooks. */
1442 /*if ((to_visit != 0) && !has_visited(to_visit)) {*/
1443 {
1444 /* Run hooks, run after music in case hook wants to change music. */
1445 if (torun_hook != NULL)
1446 if (hooks_run( torun_hook ) > 0)
1447 bar_genList( land_getWid(LAND_WINDOW_BAR) );
1448
1449 visited(to_visit);
1450
1451 land_needsTakeoff( 1 );
1452 }
1453}
1454
1461void takeoff( int delay, int nosave )
1462{
1463 int h, stu;
1464 char *nt;
1465 double a, r;
1466
1467 if (!landed)
1468 return;
1469
1470 /* Check to see if player fleet is ok. */
1471 if (player.fleet_capacity > 0) {
1472 char badfleet_ships[STRMAX_SHORT];
1473 int l = 0;
1474 int badfleet = 0;
1475 int nships = 0;
1476 const PlayerShip_t *pships = player_getShipStack();
1477
1478 /* Check to see if player's fleet is OK and count ships. */
1479 pfleet_update();
1480 badfleet_ships[0] = '\0';
1481 for (int i=0; i<array_size(pships); i++) {
1482 const PlayerShip_t *pe = &pships[i];
1483 if (!pe->deployed)
1484 continue;
1485 if (!pilot_isSpaceworthy(pe->p)) {
1486 badfleet = 1;
1487 l += scnprintf( &badfleet_ships[l], sizeof(badfleet_ships)-l, "\n%s", pe->p->name );
1488 }
1489 nships++;
1490 }
1491 /* Only care if the player has a fleet deployed. */
1492 if (nships > 0) {
1494 if (!spob_hasService(land_spob, SPOB_SERVICE_SHIPYARD)) {
1495 land_stranded(); /* Needs rescuing. */
1496 return;
1497 }
1498 else {
1499 dialogue_msgRaw( _("Fleet not fit for flight"), _("You lack the fleet capacity to take off with all selected ships.") );
1500 return;
1501 }
1502 }
1503 if (badfleet) {
1504 if (!dialogue_YesNo( _("Fleet not fit for flight"), "%s\n%s", _("The following ships in your fleet are not space worthy, are you sure you want to take off without them?"), badfleet_ships ))
1505 return;
1506 }
1507 }
1508 }
1509
1510 /* Player's ship is not able to fly. */
1512 char message[STRMAX_SHORT];
1513 pilot_reportSpaceworthy( player.p, message, sizeof(message) );
1514 dialogue_msgRaw( _("Ship not fit for flight"), message );
1515
1516 /* Check whether the player needs rescuing. */
1517 land_stranded();
1518
1519 return;
1520 }
1521
1522 /* Clear queued takeoff. */
1523 land_takeoff = 0;
1525
1526 /* Refuel if needed. */
1527 land_refuel();
1528
1529 /* In case we had paused messy sounds. */
1530 sound_stopAll();
1531
1532 /* ze music */
1533 music_choose("takeoff");
1534
1535 /* to randomize the takeoff a bit */
1536 a = RNGF() * 2. * M_PI;
1537 r = RNGF() * land_spob->radius;
1538
1539 /* no longer authorized to land */
1540 player_rmFlag(PLAYER_LANDACK);
1541 pilot_rmFlag(player.p,PILOT_LANDING); /* No longer landing. */
1542
1543 /* set player to another position with random facing direction and no vel */
1544 player_warp( land_spob->pos.x + r * cos(a), land_spob->pos.y + r * sin(a) );
1545 vec2_pset( &player.p->solid->vel, 0., 0. );
1546 player.p->solid->dir = RNGF() * 2. * M_PI;
1548
1549 /* Clear spob target. Allows for easier autonav out of the system. */
1551
1552 /* Clear pilots other than player. */
1553 pilots_clean(1);
1554
1555 /* Clear omsg. */
1556 omsg_cleanup();
1557
1558 /* initialize the new space */
1559 h = player.p->nav_hyperspace;
1560 space_init( NULL, 1 );
1561 player.p->nav_hyperspace = h;
1562
1563 /* Only save when the player shouldn't get stranded. */
1564 if (!nosave && land_canSave() && (save_all() < 0)) /* must be before cleaning up spob */
1565 dialogue_alert( _("Failed to save game! You should exit and check the log to see what happened and then file a bug report!") );
1566
1567 /* time goes by, triggers hook before takeoff */
1568 if (delay) {
1569 /* TODO should this depend on something else? */
1570 stu = (int)(NT_PERIOD_SECONDS * player.p->stats.land_delay);
1571 ntime_inc( ntime_create( 0, 0, stu ) );
1572 }
1573 nt = ntime_pretty( 0, 2 );
1574 player_message( _("#oTaking off from %s on %s."), spob_name(land_spob), nt);
1575 free(nt);
1576
1577 /* Hooks and stuff. */
1578 land_cleanup(); /* Cleanup stuff */
1579 hooks_run("takeoff"); /* Must be run after cleanup since we don't want the
1580 missions to think we are landed. */
1582 return;
1583
1584 /* Add escorts and heal up. */
1585 player_addEscorts(); /* TODO only regenerate fleet if planet has a shipyard */
1588
1589 hooks_run("enter");
1591 return;
1592 events_trigger( EVENT_TRIGGER_ENTER );
1593 missions_run( MIS_AVAIL_ENTER, -1, NULL, NULL );
1595 return;
1596
1597 /* Clear effects of all surviving pilots. */
1598 Pilot*const* plts = pilot_getAll();
1599 for (int i=0; i<array_size(plts); i++) {
1600 Pilot *p = plts[i];
1601 if (pilot_isFlag(p,PILOT_DELETE))
1602 continue;
1603
1604 effect_clear( &p->effects );
1605 pilot_calcStats( p );
1606
1607 /* Update lua stuff. */
1609
1610 /* Normal pilots stop here. */
1611 if (!pilot_isWithPlayer( p ))
1612 continue;
1613
1615
1616 /* Set take off stuff. */
1617 p->landing_delay = PILOT_TAKEOFF_DELAY * player_dt_default();
1618 p->ptimer = p->landing_delay;
1619 pilot_setFlag( p, PILOT_TAKEOFF );
1620 pilot_setThrust( p, 0. );
1621 pilot_setTurn( p, 0. );
1622 }
1623
1624 /* Reset speed */
1626}
1627
1631static void land_stranded (void)
1632{
1633 /* Nothing to do if there's no rescue script. */
1634 if (!PHYSFS_exists(RESCUE_PATH))
1635 return;
1636
1637 if (rescue_env == LUA_NOREF) {
1638 char *buf;
1639 size_t bufsize;
1640
1641 rescue_env = nlua_newEnv();
1644
1645 buf = ndata_read( RESCUE_PATH, &bufsize );
1646 if (buf == NULL) {
1647 WARN( _("File '%s' not found!"), RESCUE_PATH );
1648 return;
1649 }
1650 if (nlua_dobufenv(rescue_env, buf, bufsize, RESCUE_PATH) != 0) {
1651 WARN( _("Error loading file: %s\n"
1652 "%s\n"
1653 "Most likely Lua file has improper syntax, please check"),
1654 RESCUE_PATH, lua_tostring(naevL,-1));
1655 free(buf);
1656 return;
1657 }
1658 free(buf);
1659 }
1660
1661 /* Run Lua. */
1662 nlua_getenv(naevL,rescue_env,"rescue");
1663 if (nlua_pcall(rescue_env, 0, 0)) { /* error has occurred */
1664 WARN( _("Rescue: 'rescue' : '%s'"), lua_tostring(naevL,-1));
1665 lua_pop(naevL,1);
1666 }
1667}
1668
1672void land_cleanup (void)
1673{
1674 /* Clean up default stuff. */
1675 land_regen = 0;
1676 land_spob = NULL;
1677 landed = 0;
1678 land_visited = 0;
1679 land_generated = 0;
1680
1681 /* Destroy window. */
1682 if (land_wid > 0)
1684 land_wid = 0;
1685
1686 /* Clean up possible stray graphic. */
1687 if (gfx_exterior != NULL)
1689 gfx_exterior = NULL;
1690
1691 /* Remove computer markers just in case. */
1693
1694 /* Clean up mission computer. */
1695 for (int i=0; i<mission_ncomputer; i++)
1697 free(mission_computer);
1698 mission_computer = NULL;
1700
1701 /* Clean up bar missions. */
1702 npc_clear();
1703
1704 /* Clean up shipyard. */
1706
1707 /* Clean up rescue Lua. */
1708 nlua_freeEnv(rescue_env);
1709 rescue_env = LUA_NOREF;
1710
1711 /* Deselect stuff. */
1712 equipment_slotDeselect( NULL );
1713}
1714
1718void land_exit (void)
1719{
1720 land_cleanup();
1723 commodity_exchange_cleanup();
1724}
Provides macros to work with dynamic arrays.
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
Definition: array.h:168
void cam_setTargetPilot(unsigned int follow, int soft_over)
Sets the target to follow.
Definition: camera.c:145
void dialogue_alert(const char *fmt,...)
Displays an alert popup with only an ok button and a message.
Definition: dialogue.c:132
void dialogue_msgRaw(const char *caption, const char *msg)
Opens a dialogue window with an ok button and a fixed message.
Definition: dialogue.c:261
int dialogue_YesNo(const char *caption, const char *fmt,...)
Runs a dialogue with both yes and no options.
Definition: dialogue.c:344
void effect_clear(Effect **efxlist)
Clears an effect list, removing all active effects.
Definition: effect.c:387
void equipment_slotDeselect(CstSlotWidget *wgt)
Deselects equipment stuff.
Definition: equipment.c:2414
void equipment_cleanup(void)
Cleans up after the equipment stuff.
Definition: equipment.c:2396
void equipment_updateOutfits(unsigned int wid, const char *str)
Updates the player's outfit list.
Definition: equipment.c:1913
void equipment_updateShips(unsigned int wid, const char *str)
Updates the player's ship window.
Definition: equipment.c:1698
void equipment_open(unsigned int wid)
Opens the player's equipment window.
Definition: equipment.c:298
int escort_clearDeployed(Pilot *p)
Clears deployed escorts of a pilot.
Definition: escort.c:229
void events_trigger(EventTrigger_t trigger)
Runs all the events matching a trigger.
Definition: event.c:314
const glTexture * faction_logo(int f)
Gets the faction's logo (ideally 256x256).
Definition: faction.c:451
const char * faction_name(int f)
Gets a factions "real" (internal) name.
Definition: faction.c:304
int gl_printHeightRaw(const glFont *ft_font, const int width, const char *text)
Gets the height of a non-formatted string.
Definition: font.c:1026
glFont gl_defFont
Definition: font.c:153
void gui_setNav(void)
Player just changed their nav computer target.
Definition: gui.c:1749
void player_message(const char *fmt,...)
Adds a mesg to the queue to be displayed on screen.
Definition: gui.c:330
int hooks_run(const char *stack)
Runs all the hooks of stack.
Definition: hook.c:987
unsigned int hook_addFunc(int(*func)(void *), void *data, const char *stack)
Adds a function hook to be run.
Definition: hook.c:582
void bar_regen(void)
Regenerates the bar list.
Definition: land.c:452
static void land_changeTab(unsigned int wid, const char *wgt, int old, int tab)
Saves the last place the player was.
Definition: land.c:1372
void land_queueTakeoff(void)
Queue a takeoff.
Definition: land.c:143
int land_takeoff_nosave
Definition: land.c:77
static int land_windowsMap[LAND_NUMWINDOWS]
Definition: land.c:80
static int last_window
Definition: land.c:99
#define visited(f)
Definition: land.c:64
void takeoff(int delay, int nosave)
Makes the player take off if landed.
Definition: land.c:1461
static void misn_autonav(unsigned int wid, const char *str)
Autonav to selected mission.
Definition: land.c:653
static void land_cleanupWindow(unsigned int wid, const char *name)
Cleans up the land window.
Definition: land.c:939
static void bar_close(unsigned int wid, const char *str)
Closes the mission computer window.
Definition: land.c:538
int can_swapEquipment(const char *shipname)
Makes sure it's valid to change ships in the equipment view.
Definition: land.c:200
#define VISITED_EQUIPMENT
Definition: land.c:62
unsigned int land_wid
Definition: land.c:78
void land_genWindows(int load, int changetab)
Recreates the land windows.
Definition: land.c:1032
static unsigned int * land_windows
Definition: land.c:81
static void bar_update(unsigned int wid, const char *str)
Updates the missions in the spaceport bar.
Definition: land.c:465
static int mission_ncomputer
Definition: land.c:89
#define VISITED_MISSION
Definition: land.c:63
int land_setWindow(int window)
Sets the land window tab.
Definition: land.c:1186
static void bar_approach(unsigned int wid, const char *str)
Approaches guy in mission computer.
Definition: land.c:555
unsigned int land_getWid(int window)
Gets the WID of a window by type.
Definition: land.c:963
static void land_stranded(void)
Runs the rescue script if players are stuck.
Definition: land.c:1631
static int land_regen
Definition: land.c:79
static void spaceport_buyMap(unsigned int wid, const char *str)
Buys a local system map.
Definition: land.c:829
#define VISITED_COMMODITY
Definition: land.c:58
#define VISITED_LAND
Definition: land.c:57
int land_loaded
Definition: land.c:75
static void misn_open(unsigned int wid)
Opens the mission computer window.
Definition: land.c:602
void land_cleanup(void)
Cleans up some land-related variables.
Definition: land.c:1672
static Mission * mission_computer
Definition: land.c:88
#define VISITED_BAR
Definition: land.c:59
int landed
Definition: land.c:74
int land_doneLoading(void)
Check to see if finished loading.
Definition: land.c:189
int land_takeoff
Definition: land.c:76
void land(Spob *p, int load)
Opens up all the land dialogue stuff.
Definition: land.c:1201
static int bar_genList(unsigned int wid)
Generates the mission list for the bar.
Definition: land.c:379
void land_errDialogueBuild(const char *fmt,...)
Generates error dialogues used by several landing tabs.
Definition: land.c:288
int land_errDialogue(const char *name, const char *type)
Generates error dialogues used by several landing tabs.
Definition: land.c:256
static int news_load(void)
Loads the news.
Definition: land.c:592
static int land_taboverride
Definition: land.c:100
void land_exit(void)
Exits all the landing stuff.
Definition: land.c:1718
static void bar_getDim(int wid, int *w, int *h, int *iw, int *ih, int *bw, int *bh)
Gets the dimensions of the spaceport bar window.
Definition: land.c:310
void land_updateMainTab(void)
Adds the "Buy Local Map" button if needed and updates info.
Definition: land.c:864
static unsigned int land_visited
Definition: land.c:66
Spob * land_spob
Definition: land.c:82
static void bar_open(unsigned int wid)
Opens the spaceport bar window.
Definition: land.c:327
int land_canSave(void)
Whether or not the player can save.
Definition: land.c:166
static glTexture * mission_portrait
Definition: land.c:94
static void land_setupTabs(void)
Sets up the tabs for the window.
Definition: land.c:973
#define VISITED_SHIPYARD
Definition: land.c:61
void land_buttonTakeoff(unsigned int wid, const char *unused)
Wrapper for takeoff mission button.
Definition: land.c:925
void land_refuel(void)
Refuels the player's current ship, if possible.
Definition: land.c:807
#define VISITED_OUTFITS
Definition: land.c:60
static glTexture * gfx_exterior
Definition: land.c:83
static void misn_update(unsigned int wid, const char *str)
Updates the mission list.
Definition: land.c:764
#define has_visited(f)
Definition: land.c:65
static int land_gc(void *unused)
Runs Lua garbage collection.
Definition: land.c:1273
static void misn_accept(unsigned int wid, const char *str)
Accepts the selected mission.
Definition: land.c:677
static void land_createMainTab(unsigned int wid)
Creates the main tab.
Definition: land.c:1285
static void misn_genList(unsigned int wid, int first)
Generates the mission list.
Definition: land.c:724
static nlua_env rescue_env
Definition: land.c:113
void outfits_regenList(unsigned int wid, const char *str)
Regenerates the outfit list.
Definition: land_outfits.c:217
void outfits_cleanup(void)
Cleans up outfit globals.
void outfits_open(unsigned int wid, const Outfit **outfits)
Opens the outfit exchange center window.
Definition: land_outfits.c:117
void outfits_update(unsigned int wid, const char *str)
Updates the outfits in the outfit window.
Definition: land_outfits.c:405
int outfit_canSell(const char *name)
Checks to see if the player can sell the selected outfit.
Definition: land_outfits.c:935
int outfit_canBuy(const char *name, const Spob *spob)
Checks to see if the player can buy the outfit.
Definition: land_outfits.c:794
void shipyard_open(unsigned int wid)
Opens the shipyard window.
Definition: land_shipyard.c:58
int can_sell(const char *shipname)
Makes sure it's valid to sell a ship.
int shipyard_canBuy(const char *shipname, const Spob *spob)
Makes sure it's valid to buy a ship.
int can_swap(const char *shipname)
Makes sure it's valid to change ships.
void shipyard_cleanup(void)
Cleans up shipyard data.
int shipyard_canTrade(const char *shipname, const Spob *spob)
Makes sure it's valid to buy a ship, trading the old one in simultaneously.
void shipyard_update(unsigned int wid, const char *str)
Updates the ships in the shipyard window.
int commodity_canBuy(const Commodity *com)
Checks to see if the player can buy a commodity.
Definition: land_trade.c:282
void commodity_exchange_open(unsigned int wid)
Opens the local market window.
Definition: land_trade.c:45
int commodity_canSell(const Commodity *com)
Checks to see if a player can sell a commodity.
Definition: land_trade.c:320
void commodity_update(unsigned int wid, const char *str)
Updates the commodity window.
Definition: land_trade.c:183
Handles the important game menus.
#define MENU_MAIN
Definition: menu.h:9
#define menu_isOpen(f)
Definition: menu.h:16
int mission_accept(Mission *mission)
Small wrapper for misn_run.
Definition: mission.c:199
Mission * missions_genList(int *n, int faction, const Spob *pnt, const StarSystem *sys, MissionAvailability loc)
Generates a mission list. This runs create() so won't work with all missions.
Definition: mission.c:846
void mission_cleanup(Mission *misn)
Cleans up a mission.
Definition: mission.c:677
const StarSystem * mission_sysComputerMark(const Mission *misn)
Marks the system of the computer mission to reflect where it will head to.
Definition: mission.c:541
void mission_sysMark(void)
Marks all active systems that need marking.
Definition: mission.c:516
void missions_run(MissionAvailability loc, int faction, const Spob *pnt, const StarSystem *sys)
Runs missions matching location, all Lua side and one-shot.
Definition: mission.c:301
int music_choose(const char *situation)
Actually runs the music stuff, based on situation.
Definition: music.c:413
int naev_isQuit(void)
Get if Naev is trying to quit.
Definition: naev.c:155
Header file with generic functions and naev-specifics.
#define MAX(x, y)
Definition: naev.h:39
void * ndata_read(const char *path, size_t *filesize)
Reads a file from the ndata (will be NUL terminated).
Definition: ndata.c:154
int * generate_news(int faction)
Generates news from newslist from specific faction AND Generic news.
Definition: news.c:209
void news_widget(unsigned int wid, int x, int y, int w, int h)
Creates a news widget.
Definition: news.c:277
static char buf[NEWS_MAX_LENGTH]
Definition: news.c:45
int nlua_loadStandard(nlua_env env)
Loads the standard Naev Lua API.
Definition: nlua.c:760
int nlua_loadTk(nlua_env env)
Loads the Toolkit Lua library.
Definition: nlua_tk.c:90
const char * npc_getDesc(int i)
Gets the NPC description.
Definition: npc.c:542
void npc_generateMissions(void)
Generates the bar missions.
Definition: npc.c:364
glTexture * npc_getTexture(int i)
Get the texture of an NPC.
Definition: npc.c:530
int npc_approach(int i)
Approaches the NPC.
Definition: npc.c:601
void npc_clear(void)
Cleans up the spaceport bar NPC.
Definition: npc.c:469
int npc_getArraySize(void)
Get the size of the npc array.
Definition: npc.c:495
glTexture * npc_getBackground(int i)
Get the background of an NPC.
Definition: npc.c:515
int npc_isImportant(int i)
Checks to see if the NPC is important or not.
Definition: npc.c:554
const char * npc_getName(int i)
Get the name of an NPC.
Definition: npc.c:503
void npc_sort(void)
Sorts the NPCs.
Definition: npc.c:355
int scnprintf(char *text, size_t maxlen, const char *fmt,...)
Like snprintf(), but returns the number of characters ACTUALLY "printed" into the buffer....
Definition: nstring.c:178
ntime_t ntime_create(int scu, int stp, int stu)
Creates a time structure.
Definition: ntime.c:94
char * ntime_pretty(ntime_t t, int d)
Gets the time in a pretty human readable format.
Definition: ntime.c:173
void ntime_inc(ntime_t t)
Sets the time relatively.
Definition: ntime.c:236
glTexture * gl_dupTexture(const glTexture *texture)
Duplicates a texture.
Definition: opengl_tex.c:809
glTexture ** gl_addTexArray(glTexture **tex, int *n, glTexture *t)
Adds an element to a texture array.
Definition: opengl_tex.c:934
glTexture * gl_newImage(const char *path, const unsigned int flags)
Loads an image as a texture.
Definition: opengl_tex.c:570
void gl_freeTexture(glTexture *texture)
Frees a texture.
Definition: opengl_tex.c:755
const Outfit * outfit_get(const char *name)
Gets an outfit by name.
Definition: outfit.c:118
void pilot_setThrust(Pilot *p, double thrust)
Sets the pilot's thrust.
Definition: pilot.c:632
void pilots_clean(int persist)
Cleans up the pilot stack - leaves the player.
Definition: pilot.c:3555
void pilot_setTurn(Pilot *p, double turn)
Sets the pilot's turn.
Definition: pilot.c:640
Pilot *const * pilot_getAll(void)
Gets the pilot stack.
Definition: pilot.c:83
int pilot_cargoFree(const Pilot *p)
Gets the pilot's free cargo space.
Definition: pilot_cargo.c:51
int pilot_cargoUsedMission(const Pilot *p)
Gets how much mission cargo ship has on board.
Definition: pilot_cargo.c:203
int pilot_cargoUsed(const Pilot *p)
Gets how much cargo ship has on board.
Definition: pilot_cargo.c:189
void pilot_heatReset(Pilot *p)
Resets a pilot's heat.
Definition: pilot_heat.c:110
int pilot_hasDeployed(Pilot *p)
Checks to see if the pilot has deployed ships.
Definition: pilot_outfit.c:251
void pilot_healLanded(Pilot *pilot)
Cures the pilot as if he was landed.
void pilot_outfitLOntakeoff(Pilot *pilot)
Runs Lua outfits when pilot takes off from a spob.
void pilot_calcStats(Pilot *pilot)
Recalculates the pilot's stats based on his outfits.
Definition: pilot_outfit.c:877
int pilot_reportSpaceworthy(const Pilot *p, char *buf, int bufSize)
Pilot safety report - makes sure stats are safe.
Definition: pilot_outfit.c:541
void pilot_outfitLOnland(Pilot *pilot)
Runs Lua outfits when pilot lands on a spob.
int pilot_isSpaceworthy(const Pilot *p)
Pilot safety check - makes sure stats are safe.
Definition: pilot_outfit.c:528
void pilot_outfitLInitAll(Pilot *pilot)
Runs the pilot's Lua outfits init script.
int player_addOutfit(const Outfit *o, int quantity)
Adds an outfit to the player outfit stack.
Definition: player.c:2803
void player_warp(double x, double y)
Warps the player to the new position.
Definition: player.c:907
const PlayerShip_t * player_getShipStack(void)
Gets the array (array.h) of the player's ships.
Definition: player.c:2623
void player_hyperspacePreempt(int preempt)
Enables or disables jump points preempting spobs in autoface and target clearing.
Definition: player.c:1851
PlayerShip_t * player_getPlayerShip(const char *shipname)
Gets a specific ship.
Definition: player.c:2682
double player_dt_default(void)
Returns the player's total default time delta based on time dilation stuff.
Definition: player.c:1871
int player_addEscorts(void)
Adds the player's escorts.
Definition: player.c:3074
void player_soundStop(void)
Stops playing player sounds.
Definition: player.c:866
credits_t player_modCredits(credits_t amount)
Modifies the amount of credits the player has.
Definition: player.c:947
void player_targetSpobSet(int id)
Sets the player's target spob.
Definition: player.c:1453
Player_t player
Definition: player.c:73
void player_autonavResetSpeed(void)
Resets the game speed.
void player_autonavStart(void)
Starts autonav.
int pfleet_cargoFree(void)
Gets the total amount of free cargo space in the player's fleet.
Definition: player_fleet.c:255
void pfleet_update(void)
Updates the used fleet capacity of the player.
Definition: player_fleet.c:24
static const double a[]
Definition: rng.c:247
int save_all(void)
Saves the current game.
Definition: save.c:94
void sound_stopAll(void)
Stops all the playing voices.
Definition: sound.c:1052
void space_init(const char *sysname, int do_simulate)
Initializes the system.
Definition: space.c:1501
StarSystem * cur_system
Definition: space.c:105
void spob_updateLand(Spob *p)
Updates the land possibilities of a spob.
Definition: space.c:1896
const char * space_populationStr(uint64_t population)
Gets the population in an approximated string. Note this function changes the string value each call,...
Definition: space.c:4332
const char * spob_name(const Spob *p)
Gets the translated name of a spob.
Definition: space.c:1705
const char * spob_getClassName(const char *class)
Gets the long class name for a spob.
Definition: space.c:213
void space_clearComputerMarkers(void)
Clears all the system computer markers.
Definition: space.c:3672
Represents an active mission.
Definition: mission.h:79
char * reward
Definition: mission.h:86
char * desc
Definition: mission.h:85
char * title
Definition: mission.h:84
A ship outfit, depends radically on the type.
Definition: outfit.h:304
credits_t price
Definition: outfit.h:322
The representation of an in-game pilot.
Definition: pilot.h:210
Solid * solid
Definition: pilot.h:220
ShipStats stats
Definition: pilot.h:286
unsigned int id
Definition: pilot.h:211
credits_t credits
Definition: pilot.h:317
int nav_hyperspace
Definition: pilot.h:337
const Ship * ship
Definition: pilot.h:219
double fuel_max
Definition: pilot.h:252
double fuel
Definition: pilot.h:253
char * name
Definition: pilot.h:212
int cargo_free
Definition: pilot.h:319
int nav_spob
Definition: pilot.h:336
Effect * effects
Definition: pilot.h:289
char * comm_msg
Definition: pilot.h:352
int devmode
Definition: conf.h:158
Player ship.
Definition: player.h:73
int deployed
Definition: player.h:80
unsigned int landed_times
Definition: player.h:92
Pilot * p
Definition: player.h:74
Pilot * p
Definition: player.h:101
PlayerShip_t ps
Definition: player.h:102
int fleet_used
Definition: player.h:130
int fleet_capacity
Definition: player.h:131
unsigned int landed_times
Definition: player.h:143
double land_delay
Definition: shipstats.h:237
vec2 vel
Definition: physics.h:21
double dir
Definition: physics.h:19
int faction
Definition: space.h:66
Represents a Space Object (SPOB), including and not limited to planets, stations, wormholes,...
Definition: space.h:88
unsigned int services
Definition: space.h:113
double radius
Definition: space.h:94
char * bar_description
Definition: space.h:112
char * description
Definition: space.h:111
char * class
Definition: space.h:98
char ** tags
Definition: space.h:126
uint64_t population
Definition: space.h:99
vec2 pos
Definition: space.h:93
SpobPresence presence
Definition: space.h:102
int h
Definition: font.h:18
Abstraction for rendering sprite sheets.
Definition: opengl_tex.h:34
double w
Definition: opengl_tex.h:38
double h
Definition: opengl_tex.h:39
double y
Definition: vec2.h:34
double x
Definition: vec2.h:33
unsigned int window_create(const char *name, const char *displayname, const int x, const int y, const int w, const int h)
Creates a window.
Definition: toolkit.c:696
void window_setFade(unsigned int wid, const SimpleShader *shd, double length)
Sets the fade-in behaviour of a window.
Definition: toolkit.c:646
void window_setFocus(unsigned int wid, const char *wgtname)
Sets the focused widget in a window.
Definition: toolkit.c:2460
void window_setAccept(unsigned int wid, void(*accept)(unsigned int, const char *))
Sets the default accept function of the window.
Definition: toolkit.c:879
void window_dimWindow(unsigned int wid, int *w, int *h)
Gets the dimensions of a window.
Definition: toolkit.c:371
void window_destroyWidget(unsigned int wid, const char *wgtname)
Destroys a widget in a window.
Definition: toolkit.c:1162
void window_lower(unsigned int wid)
Lowers a window (causes all other windows to appear above it).
Definition: toolkit.c:2548
void window_onCleanup(unsigned int wid, void(*fptr)(unsigned int, const char *))
Sets the cleanup function of the window.
Definition: toolkit.c:858
int widget_exists(unsigned int wid, const char *wgtname)
Checks to see if a widget exists.
Definition: toolkit.c:1139
void window_destroy(unsigned int wid)
Kills the window.
Definition: toolkit.c:1042