summaryrefslogtreecommitdiffstats
path: root/games/naev/files/patch-src_land.c
blob: c2093607e9490b7a6119c78b2d1217d64469d01d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# Origin: https://github.com/naev/naev/commit/74b9a086a20f80f21ce2f3866b31318e651a6235
# Subject: Turn player_missions in an array of pointers
# Origin: https://github.com/naev/naev/commit/9fd2a7dcb3690bc1befe7f9a05d02e204dcfe8a1
# Subject: Avoid regenerating the land tabs over top of themselves
# Origin: https://github.com/naev/naev/commit/b9bad809027529c0b0e95d9b8a011cb880229a5d
# Subject: Fixed "buy map" button not showing up until after land hooks.

--- src/land.c.orig	2015-03-05 22:11:11 UTC
+++ src/land.c
@@ -69,6 +69,8 @@
 #define has_visited(f)        (land_visited & (f)) /**< Check if player has visited. */
 static unsigned int land_visited = 0; /**< Contains what the player visited. */
 
+/* Which tabs have been generated by their respective open functions. */
+unsigned int land_generated = 0;
 
 /*
  * land variables
@@ -187,6 +189,9 @@ static void commodity_exchange_open( uns
    char **goods;
    int w, h;
 
+   /* Mark as generated. */
+   land_tabGenerate(LAND_WINDOW_COMMODITY);
+
    /* Get window dimensions. */
    window_dimWindow( wid, &w, &h );
 
@@ -566,6 +571,9 @@ static void bar_open( unsigned int wid )
 {
    int w, h, iw, ih, bw, bh, dh, th;
 
+   /* Mark as generated. */
+   land_tabGenerate(LAND_WINDOW_BAR);
+
    /* Set window functions. */
    window_onClose( wid, bar_close );
 
@@ -822,6 +830,9 @@ static void misn_open( unsigned int wid 
    int w, h;
    int y;
 
+   /* Mark as generated. */
+   land_tabGenerate(LAND_WINDOW_MISSION);
+
    /* Get window dimensions. */
    window_dimWindow( wid, &w, &h );
 
@@ -900,7 +911,7 @@ static void misn_accept( unsigned int wi
 
    /* Make sure player can accept the mission. */
    for (i=0; i<MISSION_MAX; i++)
-      if (player_missions[i].data == NULL) break;
+      if (player_missions[i]->data == NULL) break;
    if (i >= MISSION_MAX) {
       dialogue_alert("You have too many active missions.");
       return;
@@ -1180,6 +1191,9 @@ void land_genWindows( int load, int chan
    if (land_wid > 0) {
       land_regen = 2; /* Mark we're regenning. */
       window_destroy(land_wid);
+
+      /* Mark tabs as not generated. */
+      land_generated = 0;
    }
    land_loaded = 0;
 
@@ -1255,6 +1269,9 @@ void land_genWindows( int load, int chan
    /* 1) Create main tab. */
    land_createMainTab( land_getWid(LAND_WINDOW_MAIN) );
 
+   /* Add local system map button. */
+   land_checkAddMap();
+
    /* 2) Set as landed and run hooks. */
    if (!regen) {
       landed = 1;
@@ -1274,24 +1291,34 @@ void land_genWindows( int load, int chan
    }
 
    /* 4) Create other tabs. */
+#define should_open(s, w) \
+   (planet_hasService(land_planet, s) && (!land_tabGenerated(w)))
+
+   /* Things get a bit hairy here. Hooks may have triggered a GUI reload via
+    * e.g. player.swapShip, so the land tabs may have been generated already
+    * and we need to check that before regenerating them.
+    */
+
    /* Basic - bar + missions */
-   if (planet_hasService(land_planet, PLANET_SERVICE_BAR))
+   if (should_open( PLANET_SERVICE_BAR, LAND_WINDOW_BAR ))
       bar_open( land_getWid(LAND_WINDOW_BAR) );
-   if (planet_hasService(land_planet, PLANET_SERVICE_MISSIONS))
+   if (should_open( PLANET_SERVICE_MISSIONS, LAND_WINDOW_MISSION ))
       misn_open( land_getWid(LAND_WINDOW_MISSION) );
    /* Outfits. */
-   if (planet_hasService(land_planet, PLANET_SERVICE_OUTFITS))
+   if (should_open( PLANET_SERVICE_OUTFITS, LAND_WINDOW_OUTFITS ))
       outfits_open( land_getWid(LAND_WINDOW_OUTFITS) );
    /* Shipyard. */
-   if (planet_hasService(land_planet, PLANET_SERVICE_SHIPYARD))
+   if (should_open( PLANET_SERVICE_SHIPYARD, LAND_WINDOW_SHIPYARD ))
       shipyard_open( land_getWid(LAND_WINDOW_SHIPYARD) );
    /* Equipment. */
-   if (planet_hasService(land_planet, PLANET_SERVICE_OUTFITS) ||
-         planet_hasService(land_planet, PLANET_SERVICE_SHIPYARD))
+   if ((planet_hasService(land_planet, PLANET_SERVICE_OUTFITS) ||
+         planet_hasService(land_planet, PLANET_SERVICE_SHIPYARD)) &&
+         !land_tabGenerated( LAND_WINDOW_EQUIPMENT ))
       equipment_open( land_getWid(LAND_WINDOW_EQUIPMENT) );
    /* Commodity. */
-   if (planet_hasService(land_planet, PLANET_SERVICE_COMMODITY))
+   if (should_open( PLANET_SERVICE_COMMODITY, LAND_WINDOW_COMMODITY ))
       commodity_exchange_open( land_getWid(LAND_WINDOW_COMMODITY) );
+#undef should_open
 
    if (!regen) {
       /* Reset markers if needed. */
@@ -1310,9 +1337,6 @@ void land_genWindows( int load, int chan
    if (changetab && land_windowsMap[ last_window ] != -1)
       window_tabWinSetActive( land_wid, "tabLand", land_windowsMap[ last_window ] );
 
-   /* Add local system map button. */
-   land_checkAddMap();
-
    /* Refuel if necessary. */
    land_refuel();
 
@@ -1689,6 +1713,7 @@ void land_cleanup (void)
    land_planet    = NULL;
    landed         = 0;
    land_visited   = 0;
+   land_generated = 0;
 
    /* Destroy window. */
    if (land_wid > 0)
OpenPOWER on IntegriCloud