Example #1
0
/**
 * @brief Tries to claim systems.
 *
 * Claiming systems is a way to avoid mission collisions preemptively.
 *
 * Note it does not actually claim the systems if it fails to claim. It also
 *  does not work more then once.
 *
 * @usage if not misn.claim( { system.get("Gamma Polaris") } ) then misn.finish( false ) end
 * @usage if not misn.claim( system.get("Gamma Polaris") ) then misn.finish( false ) end
 *
 *    @luaparam systems Table of systems to claim or a single system.
 *    @luareturn true if was able to claim, false otherwise.
 * @luafunc claim( systems )
 */
static int misn_claim( lua_State *L )
{
   int i, l;
   LuaSystem *ls;
   SysClaim_t *claim;
   Mission *cur_mission;

   /* Get mission. */
   cur_mission = misn_getFromLua(L);

   /* Check to see if already claimed. */
   if (cur_mission->claims != NULL) {
      NLUA_ERROR(L, "Mission trying to claim but already has.");
      return 0;
   }

   /* Create the claim. */
   claim = claim_create();

   if (lua_istable(L,1)) {
      /* Iterate over table. */
      l = lua_objlen(L,1);
      for (i=0; i<l; i++) {
         lua_pushnumber(L,i+1);
         lua_gettable(L,1);
         if (lua_issystem(L,-1)) {
            ls = lua_tosystem( L, -1 );
            claim_add( claim, ls->id );
         }
         lua_pop(L,1);
      }
   }
   else if (lua_issystem(L, 1)) {
      ls = lua_tosystem( L, 1 );
      claim_add( claim, ls->id );
   }
   else
      NLUA_INVALID_PARAMETER(L);

   /* Test claim. */
   if (claim_test( claim )) {
      claim_destroy( claim );
      lua_pushboolean(L,0);
      return 1;
   }

   /* Set the claim. */
   cur_mission->claims = claim;
   claim_activate( claim );
   lua_pushboolean(L,1);
   return 1;
}
Example #2
0
/**
 * @brief Tries to claim systems.
 *
 * Claiming systems is a way to avoid mission/event collisions preemptively.
 *
 * Note it does not actually claim the systems if it fails to claim. It also
 *  does not work more then once.
 *
 * @usage if not evt.claim( { system.get("Gamma Polaris") } ) then evt.finish( false ) end
 * @usage if not evt.claim( system.get("Gamma Polaris") ) then evt.finish( false ) end
 *
 *    @luaparam systems Table of systems to claim or a single system.
 *    @luareturn true if was able to claim, false otherwise.
 * @luafunc claim( systems )
 */
static int evt_claim( lua_State *L )
{
    LuaSystem *ls;
    SysClaim_t *claim;
    Event_t *cur_event;

    /* Get current event. */
    cur_event = event_getFromLua(L);

    /* Check to see if already claimed. */
    if (cur_event->claims != NULL) {
        NLUA_ERROR(L, "Event trying to claim but already has.");
        return 0;
    }

    /* Create the claim. */
    claim = claim_create();

    /* Handle parameters. */
    if (lua_istable(L,1)) {
        /* Iterate over table. */
        lua_pushnil(L);
        while (lua_next(L, 1) != 0) {
            if (lua_issystem(L,-1)) {
                ls = lua_tosystem( L, -1 );
                claim_add( claim, ls->id );
            }
            lua_pop(L,1);
        }
    }
    else if (lua_issystem(L, 1)) {
        ls = lua_tosystem( L, 1 );
        claim_add( claim, ls->id );
    }
    else
        NLUA_INVALID_PARAMETER(L);

    /* Test claim. */
    if (claim_test( claim )) {
        claim_destroy( claim );
        lua_pushboolean(L,0);
        return 1;
    }

    /* Set the claim. */
    cur_event->claims = claim;
    claim_activate( claim );
    lua_pushboolean(L,1);
    return 1;
}
Example #3
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) );
}
Example #4
0
/**
 * @brief Cleans up an event.
 *
 *    @param ev Event to clean up.
 */
static void event_cleanup( Event_t *ev )
{
   /* Destroy Lua. */
   lua_close(ev->L);

   /* Free hooks. */
   hook_rmEventParent(ev->id);

   /* Free NPC. */
   npc_rm_parentEvent(ev->id);

   /* Free claims. */
   if (ev->claims != NULL)
      claim_destroy( ev->claims );
}
Example #5
0
File: event.c Project: naev/naev
/**
 * @brief Cleans up an event.
 *
 *    @param ev Event to clean up.
 */
static void event_cleanup( Event_t *ev )
{
   /* Free lua env. */
   nlua_freeEnv(ev->env);

   /* Free hooks. */
   hook_rmEventParent(ev->id);

   /* Free NPC. */
   npc_rm_parentEvent(ev->id);

   /* Free claims. */
   if (ev->claims != NULL)
      claim_destroy( ev->claims );
}