/** * @brief Creates a mission OSD. * * @note You can index elements by using '\t' as first character of an element. * * @usage misn.osdCreate( "My OSD", {"Element 1", "Element 2"}) * * @luaparam title Title to give the OSD. * @luaparam list List of elements to put in the OSD. * @luafunc osdCreate( title, list ) */ static int misn_osdCreate( lua_State *L ) { const char *title; int nitems; char **items; int i; Mission *cur_mission; cur_mission = misn_getFromLua(L); /* Must be accepted. */ if (!cur_mission->accepted) { WARN("Can't create an OSD on an unaccepted mission!"); return 0; } /* Check parameters. */ title = luaL_checkstring(L,1); luaL_checktype(L,2,LUA_TTABLE); nitems = lua_objlen(L,2); /* Destroy OSD if already exists. */ if (cur_mission->osd != 0) { osd_destroy( cur_mission->osd ); cur_mission->osd = 0; } /* Allocate items. */ items = calloc( nitems, sizeof(char *) ); /* Get items. */ for (i=0; i<nitems; i++) { lua_pushnumber(L,i+1); lua_gettable(L,2); if (!lua_isstring(L,-1)) { free(items); luaL_typerror(L, -1, "string"); return 0; } items[i] = strdup( lua_tostring(L, -1) ); lua_pop(L,1); } /* Create OSD. */ cur_mission->osd = osd_create( title, nitems, (const char**) items, cur_mission->data->avail.priority ); cur_mission->osd_set = 1; /* OSD was explicitly set. */ /* Free items. */ for (i=0; i<nitems; i++) free(items[i]); free(items); return 0; }
/** * @brief Destroys the mission OSD. * * @luafunc osdDestroy() */ static int misn_osdDestroy( lua_State *L ) { Mission *cur_mission; cur_mission = misn_getFromLua(L); if (cur_mission->osd != 0) { osd_destroy( cur_mission->osd ); cur_mission->osd = 0; } return 0; }
/** * @brief Cleans up a mission. * * @param misn Mission to clean up. */ void mission_cleanup( Mission* misn ) { int i, ret; /* Hooks and missions. */ if (misn->id != 0) { hook_rmMisnParent( misn->id ); /* remove existing hooks */ npc_rm_parentMission( misn ); /* remove existing npc */ } /* Cargo. */ if (misn->cargo != NULL) { for (i=0; i<misn->ncargo; i++) { /* must unlink all the cargo */ if (player.p != NULL) { /* Only remove if player exists. */ ret = pilot_rmMissionCargo( player.p, misn->cargo[i], 0 ); if (ret) WARN("Failed to remove mission cargo '%d' for mission '%s'.", misn->cargo[i], misn->title); } } free(misn->cargo); } if (misn->osd > 0) osd_destroy(misn->osd); if (misn->L) lua_close(misn->L); /* Data. */ if (misn->title != NULL) free(misn->title); if (misn->desc != NULL) free(misn->desc); if (misn->reward != NULL) free(misn->reward); if (misn->portrait != NULL) gl_freeTexture(misn->portrait); if (misn->npc != NULL) free(misn->npc); /* Markers. */ if (misn->markers != NULL) array_free( misn->markers ); /* Claims. */ if (misn->claims != NULL) claim_destroy( misn->claims ); /* Clear the memory. */ memset( misn, 0, sizeof(Mission) ); }
/** * @brief Destroys all the OSD. */ void osd_exit (void) { while (osd_list != NULL) osd_destroy(osd_list->id); }