/** * @brief Loads a claim. * * @param parent Parent node containing the claim data. * @return The system claim. */ SysClaim_t *claim_xmlLoad( xmlNodePtr parent ) { SysClaim_t *claim; xmlNodePtr node; StarSystem *sys; /* Create the claim. */ claim = claim_create(); /* Load the nodes. */ node = parent->xmlChildrenNode; do { if (xml_isNode(node,"sys")) { sys = system_get( xml_get(node) ); if (sys != NULL) claim_add( claim, system_index(sys) ); else WARN("System Claim trying to load system '%s' which doesn't exist.", xml_get(node)); } } while (xml_nextNode(node)); /* Activate the claim. */ claim_activate( claim ); return claim; }
/** * @brief Activates mission claims. */ void missions_activateClaims (void) { int i; for (i=0; i<MISSION_MAX; i++) if (player_missions[i]->claims != NULL) claim_activate( player_missions[i]->claims ); }
/** * @brief Activates all the active event claims. */ void event_activateClaims (void) { int i; /* Free active events. */ for (i=0; i<event_nactive; i++) if (event_active[i].claims != NULL) claim_activate( event_active[i].claims ); }
/** * @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; }
/** * @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; }