/** * @brief Sets the mission marker on the system. If no parameters are passed it * unsets the current marker. * * There are basically three different types of markers: * * - "misc" : These markers are for unique or non-standard missions. * - "cargo" : These markers are for regular cargo hauling missions. * - "rush" : These markers are for timed missions. * * @usage misn.setMarker() -- Clears the marker * @usage misn.setMarker( sys, "misc" ) -- Misc mission marker. * @usage misn.setMarker( sys, "cargo" ) -- Cargo mission marker. * @usage misn.setMarker( sys, "rush" ) -- Rush mission marker. * * @luaparam sys System to mark. Unmarks if no parameter or nil is passed. * @luaparam type Optional parameter that specifies mission type. Can be one of * "misc", "rush" or "cargo". * @luafunc setMarker( sys, type ) */ static int misn_setMarker( lua_State *L ) { const char *str; LuaSystem *sys; /* No parameter clears the marker */ if (lua_gettop(L)==0) { if (cur_mission->sys_marker != NULL) free(cur_mission->sys_marker); mission_sysMark(); /* Clear the marker */ } /* Passing in a Star System */ sys = luaL_checksystem(L,1); sys = lua_tosystem(L,1); cur_mission->sys_marker = strdup(sys->s->name); /* Get the type. */ if (lua_gettop(L) > 1) { str = luaL_checkstring(L,2); if (strcmp(str, "misc")==0) cur_mission->sys_markerType = SYSMARKER_MISC; else if (strcmp(str, "rush")==0) cur_mission->sys_markerType = SYSMARKER_RUSH; else if (strcmp(str, "cargo")==0) cur_mission->sys_markerType = SYSMARKER_CARGO; else NLUA_DEBUG("Unknown marker type: %s", str); } mission_sysMark(); /* mark the system */ return 0; }
/** * @brief Approaches guy in mission computer. */ static void bar_approach( unsigned int wid, char *str ) { (void) str; int pos, n; /* Get position. */ pos = toolkit_getImageArrayPos( wid, "iarMissions" ); /* Should never happen, but in case news is selected */ if (pos == 0) return; /* Ignore news. */ pos--; n = npc_getArraySize(); npc_approach( pos ); bar_genList( wid ); /* Always just in case. */ if (n == npc_getArraySize()) toolkit_setImageArrayPos( wid, "iarMissions", pos+1 ); /* Reset markers. */ mission_sysMark(); /* Mission forced take off. */ if (land_takeoff) takeoff(0); }
/** * @brief Aborts a mission in the mission menu. * @param str Unused. */ static void mission_menu_abort( unsigned int wid, char* str ) { (void)str; int pos; Mission* misn; int ret; if (dialogue_YesNo( "Abort Mission", "Are you sure you want to abort this mission?" )) { /* Get the mission. */ pos = toolkit_getListPos(wid, "lstMission" ); misn = &player_missions[pos]; /* We run the "abort" function if it's found. */ ret = misn_tryRun( misn, "abort" ); /* Now clean up mission. */ if (ret != 2) { mission_cleanup( misn ); memmove( misn, &player_missions[pos+1], sizeof(Mission) * (MISSION_MAX-pos-1) ); memset( &player_missions[MISSION_MAX-1], 0, sizeof(Mission) ); } /* Reset markers. */ mission_sysMark(); /* Reset claims. */ claim_activateAll(); /* Regenerate list. */ mission_menu_genList(wid ,0); } }
/** * @brief Shows a map at x, y (relative to wid) with size w,h. * * @param wid Window to show map on. * @param x X position to put map at. * @param y Y position to put map at. * @param w Width of map to open. * @param h Height of map to open. * @param zoom Default zoom to use. */ void map_show( int wid, int x, int y, int w, int h, double zoom ) { /* mark systems as needed */ mission_sysMark(); /* Set position to focus on current system. */ map_xpos = cur_system->pos.x * zoom; map_ypos = cur_system->pos.y * zoom; /* Set zoom. */ map_zoom = zoom; window_addCust( wid, x, y, w, h, "cstMap", 1, map_render, map_mouse); }
/** * @brief Accepts the selected mission. * @param wid Window of the mission computer. * @param str Unused. */ static void misn_accept( unsigned int wid, char* str ) { (void) str; char* misn_name; Mission* misn; int pos; int i, ret; misn_name = toolkit_getList( wid, "lstMission" ); /* Make sure you have missions. */ if (strcmp(misn_name,"No Missions")==0) return; /* Make sure player can accept the mission. */ for (i=0; i<MISSION_MAX; i++) if (player_missions[i].data == NULL) break; if (i >= MISSION_MAX) { dialogue_alert("You have too many active missions."); return; } if (dialogue_YesNo("Accept Mission", "Are you sure you want to accept this mission?")) { pos = toolkit_getListPos( wid, "lstMission" ); misn = &mission_computer[pos]; ret = mission_accept( misn ); if ((ret==0) || (ret==2) || (ret==-1)) { /* success in accepting the mission */ if (ret==-1) mission_cleanup( &mission_computer[pos] ); memmove( &mission_computer[pos], &mission_computer[pos+1], sizeof(Mission) * (mission_ncomputer-pos-1) ); mission_ncomputer--; /* Regenerate list. */ misn_genList(wid, 0); /* Add position persistancey after a mission has been accepted */ /* NOTE: toolkit_setListPos protects us from a bad position by clamping */ toolkit_setListPos( wid, "lstMission", pos-1 ); /*looks better without the -1, makes more sense with*/ } /* Reset markers. */ mission_sysMark(); } }
/** * @brief Moves a marker to a new system. * * @usage misn.markerMove( my_marker, system.get("Delta Pavonis") ) * * @luaparam id ID of the mission marker to move. * @luaparam sys System to move the marker to. * @luafunc markerMove( id, sys ) */ static int misn_markerMove( lua_State *L ) { int id; LuaSystem *sys; MissionMarker *marker; int i, n; Mission *cur_mission; /* Handle parameters. */ id = luaL_checkinteger( L, 1 ); sys = luaL_checksystem( L, 2 ); cur_mission = misn_getFromLua(L); /* Mission must have markers. */ if (cur_mission->markers == NULL) { NLUA_ERROR( L, "Mission has no markers set!" ); return 0; } /* Check id. */ marker = NULL; n = array_size( cur_mission->markers ); for (i=0; i<n; i++) { if (id == cur_mission->markers[i].id) { marker = &cur_mission->markers[i]; break; } } if (marker == NULL) { NLUA_ERROR( L, "Mission does not have a marker with id '%d'", id ); return 0; } /* Update system. */ marker->sys = sys->id; /* Update system markers. */ mission_sysMark(); return 0; }
/** * @brief Removes a mission system marker. * * @usage misn.markerRm( my_marker ) * * @luaparam id ID of the marker to remove. * @luafunc markerRm( id ) */ static int misn_markerRm( lua_State *L ) { int id; int i, n; MissionMarker *marker; Mission *cur_mission; /* Handle parameters. */ id = luaL_checkinteger( L, 1 ); cur_mission = misn_getFromLua(L); /* Mission must have markers. */ if (cur_mission->markers == NULL) { /* Already removed. */ return 0; } /* Check id. */ marker = NULL; n = array_size( cur_mission->markers ); for (i=0; i<n; i++) { if (id == cur_mission->markers[i].id) { marker = &cur_mission->markers[i]; break; } } if (marker == NULL) { /* Already removed. */ return 0; } /* Remove the marker. */ array_erase( &cur_mission->markers, marker, &marker[1] ); /* Update system markers. */ mission_sysMark(); return 0; }
/** * @brief Adds a new marker. * * @usage my_marker = misn.markerAdd( system.get("Gamma Polaris"), "low" ) * * Valid marker types are:<br/> * - "plot": Important plot marker.<br/> * - "high": High importance mission marker (lower than plot).<br/> * - "low": Low importance mission marker (lower than high).<br/> * - "computer": Mission computer marker.<br/> * * @luaparam sys System to mark. * @luaparam type Colouring scheme to use. * @luareturn A marker ID to be used with markerMove and markerRm. * @luafunc markerAdd( sys, type ) */ static int misn_markerAdd( lua_State *L ) { int id; LuaSystem *sys; const char *stype; SysMarker type; Mission *cur_mission; /* Check parameters. */ sys = luaL_checksystem( L, 1 ); stype = luaL_checkstring( L, 2 ); /* Handle types. */ if (strcmp(stype, "computer")==0) type = SYSMARKER_COMPUTER; else if (strcmp(stype, "low")==0) type = SYSMARKER_LOW; else if (strcmp(stype, "high")==0) type = SYSMARKER_HIGH; else if (strcmp(stype, "plot")==0) type = SYSMARKER_PLOT; else { NLUA_ERROR(L, "Unknown marker type: %s", stype); return 0; } cur_mission = misn_getFromLua(L); /* Add the marker. */ id = mission_addMarker( cur_mission, -1, sys->id, type ); /* Update system markers. */ mission_sysMark(); /* Return the ID. */ lua_pushnumber( L, id ); return 1; }
/** * @brief Shows a map at x, y (relative to wid) with size w,h. * * @param wid Window to show map on. * @param x X position to put map at. * @param y Y position to put map at. * @param w Width of map to open. * @param h Height of map to open. * @param zoom Default zoom to use. */ void map_show( int wid, int x, int y, int w, int h, double zoom ) { StarSystem *sys; /* mark systems as needed */ mission_sysMark(); /* Set position to focus on current system. */ map_xpos = cur_system->pos.x * zoom; map_ypos = cur_system->pos.y * zoom; /* Set zoom. */ map_setZoom(zoom); /* Make sure selected is sane. */ sys = system_getIndex( map_selected ); if (!(sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED)) && !sys_isKnown(sys) && !space_sysReachable(sys)) map_selectCur(); window_addCust( wid, x, y, w, h, "cstMap", 1, map_render, map_mouse, NULL ); }
/** * @brief Recreates the land windows. * * @param load Is loading game? * @param changetab Should it change to the last open tab? */ void land_genWindows( int load, int changetab ) { int i, j; const char *names[LAND_NUMWINDOWS]; int w, h; Planet *p; int regen; /* Destroy old window if exists. */ if (land_wid > 0) { land_regen = 2; /* Mark we're regenning. */ window_destroy(land_wid); } land_loaded = 0; /* Get planet. */ p = land_planet; regen = landed; /* Create window. */ if ((SCREEN_W < 1024) || (SCREEN_H < 768)) { w = -1; /* Fullscreen. */ h = -1; } else { w = 800 + 0.5 * (SCREEN_W - 800); h = 600 + 0.5 * (SCREEN_H - 600); } land_wid = window_create( p->name, -1, -1, w, h ); window_onClose( land_wid, land_cleanupWindow ); /* Set window map to invalid. */ for (i=0; i<LAND_NUMWINDOWS; i++) land_windowsMap[i] = -1; /* See what is available. */ j = 0; /* Main. */ land_windowsMap[LAND_WINDOW_MAIN] = j; names[j++] = land_windowNames[LAND_WINDOW_MAIN]; /* Bar. */ if (planet_hasService(land_planet, PLANET_SERVICE_BAR)) { land_windowsMap[LAND_WINDOW_BAR] = j; names[j++] = land_windowNames[LAND_WINDOW_BAR]; } /* Missions. */ if (planet_hasService(land_planet, PLANET_SERVICE_MISSIONS)) { land_windowsMap[LAND_WINDOW_MISSION] = j; names[j++] = land_windowNames[LAND_WINDOW_MISSION]; } /* Outfits. */ if (planet_hasService(land_planet, PLANET_SERVICE_OUTFITS)) { land_windowsMap[LAND_WINDOW_OUTFITS] = j; names[j++] = land_windowNames[LAND_WINDOW_OUTFITS]; } /* Shipyard. */ if (planet_hasService(land_planet, PLANET_SERVICE_SHIPYARD)) { land_windowsMap[LAND_WINDOW_SHIPYARD] = j; names[j++] = land_windowNames[LAND_WINDOW_SHIPYARD]; } /* Equipment. */ if (planet_hasService(land_planet, PLANET_SERVICE_OUTFITS) || planet_hasService(land_planet, PLANET_SERVICE_SHIPYARD)) { land_windowsMap[LAND_WINDOW_EQUIPMENT] = j; names[j++] = land_windowNames[LAND_WINDOW_EQUIPMENT]; } /* Commodity. */ if (planet_hasService(land_planet, PLANET_SERVICE_COMMODITY)) { land_windowsMap[LAND_WINDOW_COMMODITY] = j; names[j++] = land_windowNames[LAND_WINDOW_COMMODITY]; } /* Create tabbed window. */ land_windows = window_addTabbedWindow( land_wid, -1, -1, -1, -1, "tabLand", j, names ); /* * Order here is very important: * * 1) Create main tab - must have decent background. * 2) Set landed, play music and run land hooks - so hooks run well. * 3) Generate missions - so that campaigns are fluid. * 4) Create other tabs - lists depend on NPC and missions. */ /* 1) Create main tab. */ land_createMainTab( land_getWid(LAND_WINDOW_MAIN) ); /* 2) Set as landed and run hooks. */ if (!regen) { landed = 1; music_choose("land"); /* Must be before hooks in case hooks change music. */ if (!load) { events_trigger( EVENT_TRIGGER_LAND ); hooks_run("land"); } /* 3) Generate computer and bar missions. */ if (planet_hasService(land_planet, PLANET_SERVICE_MISSIONS)) mission_computer = missions_genList( &mission_ncomputer, land_planet->faction, land_planet->name, cur_system->name, MIS_AVAIL_COMPUTER ); if (planet_hasService(land_planet, PLANET_SERVICE_BAR)) npc_generate(); /* Generate bar npc. */ } /* 4) Create other tabs. */ /* Basic - bar + missions */ if (planet_hasService(land_planet, PLANET_SERVICE_BAR)) bar_open( land_getWid(LAND_WINDOW_BAR) ); if (planet_hasService(land_planet, PLANET_SERVICE_MISSIONS)) misn_open( land_getWid(LAND_WINDOW_MISSION) ); /* Outfits. */ if (planet_hasService(land_planet, PLANET_SERVICE_OUTFITS)) outfits_open( land_getWid(LAND_WINDOW_OUTFITS) ); /* Shipyard. */ if (planet_hasService(land_planet, PLANET_SERVICE_SHIPYARD)) shipyard_open( land_getWid(LAND_WINDOW_SHIPYARD) ); /* Equipment. */ if (planet_hasService(land_planet, PLANET_SERVICE_OUTFITS) || planet_hasService(land_planet, PLANET_SERVICE_SHIPYARD)) equipment_open( land_getWid(LAND_WINDOW_EQUIPMENT) ); /* Commodity. */ if (planet_hasService(land_planet, PLANET_SERVICE_COMMODITY)) commodity_exchange_open( land_getWid(LAND_WINDOW_COMMODITY) ); if (!regen) { /* Reset markers if needed. */ mission_sysMark(); /* Check land missions. */ if (!has_visited(VISITED_LAND)) { missions_run(MIS_AVAIL_LAND, land_planet->faction, land_planet->name, cur_system->name); visited(VISITED_LAND); } } /* Go to last open tab. */ window_tabWinOnChange( land_wid, "tabLand", land_changeTab ); if (changetab && land_windowsMap[ last_window ] != -1) window_tabWinSetActive( land_wid, "tabLand", land_windowsMap[ last_window ] ); /* Add fuel button if needed - AFTER missions pay :). */ land_checkAddRefuel(); /* Finished loading. */ land_loaded = 1; }
/** * @brief Opens the map window. */ void map_open (void) { unsigned int wid; StarSystem *cur; int w, h, x, y, rw; /* Not under manual control. */ if (pilot_isFlag( player.p, PILOT_MANUAL_CONTROL )) return; /* Destroy window if exists. */ wid = window_get(MAP_WDWNAME); if (wid > 0) { window_destroy( wid ); return; } /* set position to focus on current system */ map_xpos = cur_system->pos.x; map_ypos = cur_system->pos.y; /* mark systems as needed */ mission_sysMark(); /* Attempt to select current map if none is selected */ if (map_selected == -1) map_selectCur(); /* get the selected system. */ cur = system_getIndex( map_selected ); /* Set up window size. */ w = MAX(600, SCREEN_W - 100); h = MAX(540, SCREEN_H - 100); /* create the window. */ wid = window_create( MAP_WDWNAME, -1, -1, w, h ); window_setCancel( wid, window_close ); window_handleKeys( wid, map_keyHandler ); /* * SIDE TEXT * * $System * * Faction: * $Faction (or Multiple) * * Status: * $Status * * Planets: * $Planet1, $Planet2, ... * * Services: * $Services * * ... * [Autonav] * [ Find ] * [ Close ] */ x = -70; /* Right column X offset. */ y = -20; rw = ABS(x) + 60; /* Right column indented width maximum. */ /* System Name */ window_addText( wid, -90 + 80, y, 160, 20, 1, "txtSysname", &gl_defFont, &cDConsole, cur->name ); y -= 10; /* Faction image */ window_addImage( wid, -90 + 32, y - 32, 0, 0, "imgFaction", NULL, 0 ); y -= 64 + 10; /* Faction */ window_addText( wid, x, y, 90, 20, 0, "txtSFaction", &gl_smallFont, &cDConsole, "Faction:" ); window_addText( wid, x + 50, y-gl_smallFont.h-5, rw, 100, 0, "txtFaction", &gl_smallFont, &cBlack, NULL ); y -= 2 * gl_smallFont.h + 5 + 15; /* Standing */ window_addText( wid, x, y, 90, 20, 0, "txtSStanding", &gl_smallFont, &cDConsole, "Standing:" ); window_addText( wid, x + 50, y-gl_smallFont.h-5, rw, 100, 0, "txtStanding", &gl_smallFont, &cBlack, NULL ); y -= 2 * gl_smallFont.h + 5 + 15; /* Presence. */ window_addText( wid, x, y, 90, 20, 0, "txtSPresence", &gl_smallFont, &cDConsole, "Presence:" ); window_addText( wid, x + 50, y-gl_smallFont.h-5, rw, 100, 0, "txtPresence", &gl_smallFont, &cBlack, NULL ); y -= 2 * gl_smallFont.h + 5 + 15; /* Planets */ window_addText( wid, x, y, 90, 20, 0, "txtSPlanets", &gl_smallFont, &cDConsole, "Planets:" ); window_addText( wid, x + 50, y-gl_smallFont.h-5, rw, 150, 0, "txtPlanets", &gl_smallFont, &cBlack, NULL ); y -= 2 * gl_smallFont.h + 5 + 15; /* Services */ window_addText( wid, x, y, 90, 20, 0, "txtSServices", &gl_smallFont, &cDConsole, "Services:" ); window_addText( wid, x + 50, y-gl_smallFont.h-5, rw, 100, 0, "txtServices", &gl_smallFont, &cBlack, NULL ); y -= 2 * gl_smallFont.h + 5 + 15; /* Close button */ window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnClose", "Close", window_close ); /* Find button */ window_addButton( wid, -20 - (BUTTON_WIDTH+20), 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnFind", "Find", map_inputFind ); /* Autonav button */ window_addButton( wid, -20 - 2*(BUTTON_WIDTH+20), 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnAutonav", "Autonav", player_autonavStartWindow ); /* * Bottom stuff * * [+] [-] Nebula, Interference */ /* Zoom buttons */ window_addButton( wid, 40, 20, 30, 30, "btnZoomIn", "+", map_buttonZoom ); window_addButton( wid, 80, 20, 30, 30, "btnZoomOut", "-", map_buttonZoom ); /* Situation text */ window_addText( wid, 140, 10, w - 80 - 30 - 30, 30, 0, "txtSystemStatus", &gl_smallFont, &cBlack, NULL ); /* * The map itself. */ map_show( wid, 20, -40, w-200, h-100, 1. ); /* Reset zoom. */ map_update( wid ); /* * Disable Autonav button if player lacks fuel. */ if ((player.p->fuel < HYPERSPACE_FUEL) || pilot_isFlag( player.p, PILOT_NOJUMP)) window_disableButton( wid, "btnAutonav" ); }
/** * @brief Opens the map window. */ void map_open (void) { unsigned int wid; StarSystem *cur; int w,h; /* Destroy window if exists. */ wid = window_get(MAP_WDWNAME); if (wid > 0) { window_destroy( wid ); return; } /* set position to focus on current system */ map_xpos = cur_system->pos.x; map_ypos = cur_system->pos.y; /* mark systems as needed */ mission_sysMark(); /* Attempt to select current map if none is selected */ if (map_selected == -1) map_selectCur(); /* get the selected system. */ cur = system_getIndex( map_selected ); /* Set up window size. */ w = MAX(600, SCREEN_W - 100); h = MAX(540, SCREEN_H - 100); /* create the window. */ wid = window_create( MAP_WDWNAME, -1, -1, w, h ); window_setCancel( wid, window_close ); /* * SIDE TEXT * * $System * * Faction: * $Faction (or Multiple) * * Status: * $Status * * Planets: * $Planet1, $Planet2, ... * * Services: * $Services * * ... * * [Close] */ /* System Name */ window_addText( wid, -20, -20, 100, 20, 1, "txtSysname", &gl_defFont, &cDConsole, cur->name ); /* Faction */ window_addImage( wid, -20-64, -60-64, "imgFaction", NULL, 0 ); window_addText( wid, -20, -60, 90, 20, 0, "txtSFaction", &gl_smallFont, &cDConsole, "Faction:" ); window_addText( wid, -20, -60-gl_smallFont.h-5, 80, 100, 0, "txtFaction", &gl_smallFont, &cBlack, NULL ); /* Standing */ window_addText( wid, -20, -100, 90, 20, 0, "txtSStanding", &gl_smallFont, &cDConsole, "Standing:" ); window_addText( wid, -20, -100-gl_smallFont.h-5, 80, 100, 0, "txtStanding", &gl_smallFont, &cBlack, NULL ); /* Security. */ window_addText( wid, -20, -140, 90, 20, 0, "txtSSecurity", &gl_smallFont, &cDConsole, "Security:" ); window_addText( wid, -20, -140-gl_smallFont.h-5, 80, 100, 0, "txtSecurity", &gl_smallFont, &cBlack, NULL ); /* Planets */ window_addText( wid, -20, -180, 90, 20, 0, "txtSPlanets", &gl_smallFont, &cDConsole, "Planets:" ); window_addText( wid, -20, -180-gl_smallFont.h-5, 80, 100, 0, "txtPlanets", &gl_smallFont, &cBlack, NULL ); /* Services */ window_addText( wid, -20, -220, 90, 20, 0, "txtSServices", &gl_smallFont, &cDConsole, "Services:" ); window_addText( wid, -20, -220-gl_smallFont.h-5, 80, 100, 0, "txtServices", &gl_smallFont, &cBlack, NULL ); /* Close button */ window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnClose", "Close", window_close ); /* * Bottom stuff * * [+] [-] Nebula, Asteroids, Interference */ /* Zoom buttons */ window_addButton( wid, 40, 20, 30, 30, "btnZoomIn", "+", map_buttonZoom ); window_addButton( wid, 80, 20, 30, 30, "btnZoomOut", "-", map_buttonZoom ); /* Situation text */ window_addText( wid, 140, 10, w - 80 - 30 - 30, 30, 0, "txtSystemStatus", &gl_smallFont, &cBlack, NULL ); /* * The map itself. */ map_show( wid, 20, -40, w-150, h-100, 1. ); /* Reset zoom. */ map_update( wid ); }
/** * @brief Makes the player jettison the currently selected cargo. * @param str Unused. */ static void cargo_jettison( unsigned int wid, char* str ) { (void)str; int i, j, f, pos, ret; Mission *misn; if (player.p->ncommodities==0) return; /* No cargo, redundant check */ pos = toolkit_getListPos( wid, "lstCargo" ); /* Special case mission cargo. */ if (player.p->commodities[pos].id != 0) { if (!dialogue_YesNo( "Abort Mission", "Are you sure you want to abort this mission?" )) return; /* Get the mission. */ f = 0; for (i=0; i<MISSION_MAX; i++) { for (j=0; j<player_missions[i].ncargo; j++) { if (player_missions[i].cargo[j] == player.p->commodities[pos].id) { f = 1; break; } } if (f==1) break; } if (!f) { WARN("Cargo '%d' does not belong to any active mission.", player.p->commodities[pos].id); return; } misn = &player_missions[i]; /* We run the "abort" function if it's found. */ ret = misn_tryRun( misn, "abort" ); /* Now clean up mission. */ if (ret != 2) { mission_cleanup( misn ); memmove( misn, &player_missions[i+1], sizeof(Mission) * (MISSION_MAX-i-1) ); memset( &player_missions[MISSION_MAX-1], 0, sizeof(Mission) ); } /* Reset markers. */ mission_sysMark(); /* Reset claims. */ claim_activateAll(); /* Regenerate list. */ mission_menu_genList( info_windows[ INFO_WIN_MISN ] ,0); } else { /* Remove the cargo */ commodity_Jettison( player.p->id, player.p->commodities[pos].commodity, player.p->commodities[pos].quantity ); pilot_cargoRm( player.p, player.p->commodities[pos].commodity, player.p->commodities[pos].quantity ); } /* We reopen the menu to recreate the list now. */ ship_update( info_windows[ INFO_WIN_SHIP ] ); cargo_genList( wid ); }
/** * @brief Recreates the land windows. * * @param load Is loading game? * @param changetab Should it change to the last open tab? */ void land_genWindows( int load, int changetab ) { int i, j; const char *names[LAND_NUMWINDOWS]; int w, h; Planet *p; int regen; /* Destroy old window if exists. */ 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; /* Get planet. */ p = land_planet; regen = landed; /* Create window. */ if ((gl_screen.rw < 1024) || (gl_screen.rh < 768)) { w = -1; /* Fullscreen. */ h = -1; } else { w = 800 + 0.5 * (SCREEN_W - 800); h = 600 + 0.5 * (SCREEN_H - 600); } land_wid = window_create( p->name, -1, -1, w, h ); window_onClose( land_wid, land_cleanupWindow ); /* Set window map to invalid. */ for (i=0; i<LAND_NUMWINDOWS; i++) land_windowsMap[i] = -1; /* See what is available. */ j = 0; /* Main. */ land_windowsMap[LAND_WINDOW_MAIN] = j; names[j++] = _("Landing Main"); /* Bar. */ if (planet_hasService(land_planet, PLANET_SERVICE_BAR)) { land_windowsMap[LAND_WINDOW_BAR] = j; names[j++] = _("Spaceport Bar"); } /* Missions. */ if (planet_hasService(land_planet, PLANET_SERVICE_MISSIONS)) { land_windowsMap[LAND_WINDOW_MISSION] = j; names[j++] = _("Missions"); } /* Outfits. */ if (planet_hasService(land_planet, PLANET_SERVICE_OUTFITS)) { land_windowsMap[LAND_WINDOW_OUTFITS] = j; names[j++] = _("Outfits"); } /* Shipyard. */ if (planet_hasService(land_planet, PLANET_SERVICE_SHIPYARD)) { land_windowsMap[LAND_WINDOW_SHIPYARD] = j; names[j++] = _("Shipyard"); } /* Equipment. */ if (planet_hasService(land_planet, PLANET_SERVICE_OUTFITS) || planet_hasService(land_planet, PLANET_SERVICE_SHIPYARD)) { land_windowsMap[LAND_WINDOW_EQUIPMENT] = j; names[j++] = _("Equipment"); } /* Commodity. */ if (planet_hasService(land_planet, PLANET_SERVICE_COMMODITY)) { land_windowsMap[LAND_WINDOW_COMMODITY] = j; names[j++] = _("Commodity"); } /* Create tabbed window. */ land_windows = window_addTabbedWindow( land_wid, -1, -1, -1, -1, "tabLand", j, names, 0 ); /* * Order here is very important: * * 1) Create main tab - must have decent background. * 2) Set landed, play music and run land hooks - so hooks run well. * 3) Generate missions - so that campaigns are fluid. * 4) Create other tabs - lists depend on NPC and missions. */ /* 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; music_choose("land"); /* Must be before hooks in case hooks change music. */ if (!load) { hooks_run("land"); } events_trigger( EVENT_TRIGGER_LAND ); /* 3) Generate computer and bar missions. */ if (planet_hasService(land_planet, PLANET_SERVICE_MISSIONS)) mission_computer = missions_genList( &mission_ncomputer, land_planet->faction, land_planet->name, cur_system->name, MIS_AVAIL_COMPUTER ); if (planet_hasService(land_planet, PLANET_SERVICE_BAR)) npc_generate(); /* Generate bar npc. */ } /* 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 (should_open( PLANET_SERVICE_BAR, LAND_WINDOW_BAR )) bar_open( land_getWid(LAND_WINDOW_BAR) ); if (should_open( PLANET_SERVICE_MISSIONS, LAND_WINDOW_MISSION )) misn_open( land_getWid(LAND_WINDOW_MISSION) ); /* Outfits. */ if (should_open( PLANET_SERVICE_OUTFITS, LAND_WINDOW_OUTFITS )) outfits_open( land_getWid(LAND_WINDOW_OUTFITS) ); /* 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)) && !land_tabGenerated( LAND_WINDOW_EQUIPMENT )) equipment_open( land_getWid(LAND_WINDOW_EQUIPMENT) ); /* 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. */ mission_sysMark(); /* Check land missions. */ if (!has_visited(VISITED_LAND)) { missions_run(MIS_AVAIL_LAND, land_planet->faction, land_planet->name, cur_system->name); visited(VISITED_LAND); } } /* Go to last open tab. */ window_tabWinOnChange( land_wid, "tabLand", land_changeTab ); if (changetab && land_windowsMap[ last_window ] != -1) window_tabWinSetActive( land_wid, "tabLand", land_windowsMap[ last_window ] ); /* Refresh the map button in case the player couldn't afford it prior to * mission payment. */ land_checkAddMap(); /* Refuel if necessary. */ land_refuel(); /* Finished loading. */ land_loaded = 1; }