Exemplo n.º 1
0
/**
 * @brief Changes the ownership of the planet, and adds uni state change to list
 * 
 * @param planet name of planet
 * @param faction name of faction
 * @return 0 on success
 */
int unistate_setFaction(char *planet, char *faction)
{
   
   if(!planet || !faction) return -3;
   assetStatePtr node = NULL;
   Planet *p = NULL;
   int f_id;
   //Get planet struct and faction ID. If either return errors, bail.
   if((p = planet_get(planet)) == NULL || (f_id = faction_get(faction)) == -1) 
      return -2;
   //Change the faction of the planet
   planet_setFaction(p, f_id);
   //update the universe
   space_reconstructPresences();
   //does the planet already have mods?
   if((node = unistate_getNode(planet)) != NULL)
   {
      //if a faction mod hasn't been added yet
      if(node->faction == NULL)
         node->faction = strdup(faction);
      //else wipe old entry and make new one
      else
      {
         free(node->faction);
         node->faction = strdup(faction);
      }
      return 0;
   }
   //else we need to make a new node
   else
      return unistate_addNode(planet, faction, -1, -1);
}
Exemplo n.º 2
0
/**
 * @brief Loads the state of the universe into an xml file (Used in load.c)
 * 
 * @param rootNode pointer to the root node of the game save file we are loading off of
 * @return 0 on success
 */
int unistate_load(xmlNodePtr rootNode)
{
   if(!rootNode) return -1;
   assetStatePtr cur = NULL;
   xmlNodePtr elementNode = NULL;
   Planet *p;
   int f_id;
   elementNode = rootNode->children;
   do {
      if(xml_isNode(elementNode, "uni_state"))
      {
	 //populate list
         if(!(unistateList = unistate_populateList(elementNode))) 
            return -1;
         cur = unistateList;
         while(cur != NULL)
         {
            //Get planet struct and faction ID. If either return errors, bail.
            if((p = planet_get(cur->name)) == NULL) 
            {
               WARN("Invalid planet or faction passed");
               cur = cur->next;
               continue;
            }
            //Change the faction of the planet
            if(cur->faction != NULL && (f_id = faction_get(cur->faction)) != -1) 
               planet_setFaction(p, f_id);
            //Change presence of planet
            if(cur->presence != -1)
               p->presenceAmount = (double)cur->presence;
            //Change range of presence
            if(cur->range != -1)
               p->presenceRange = (double)cur->range;
            //update the universe
            space_reconstructPresences();
            //move along
            cur = cur->next;
         }
         return 0;
      }
   } while(xml_nextNode(elementNode));
   //if it fell through to here then it didn't find what we were looking for
   return -2;
}
Exemplo n.º 3
0
/**
 * @brief Toggles the jump point for the selected systems.
 */
static void uniedit_toggleJump( StarSystem *sys )
{
   int i, j, rm;
   StarSystem *isys, *target;

   for (i=0; i<uniedit_nsys; i++) {
      isys  = uniedit_sys[i];
      rm    = 0;
      for (j=0; j<isys->njumps; j++) {
         target = isys->jumps[j].target;
         /* Target already exists, remove. */
         if (target == sys) {
            uniedit_jumpRm( isys, sys );
            uniedit_jumpRm( sys, isys );
            rm = 1;
            break;
         }
      }
      /* Target doesn't exist, add. */
      if (!rm) {
         uniedit_jumpAdd( isys, sys );
         uniedit_jumpAdd( sys, isys );
      }
   }

   /* Reconstruct jumps just in case. */
   systems_reconstructJumps();

   /* Reconstruct universe presences. */
   space_reconstructPresences();

   if (conf.devautosave) {
      dsys_saveSystem( sys );
      dsys_saveSystem( isys );
   }

   /* Update sidebar text. */
   uniedit_selectText();
}
Exemplo n.º 4
0
/**
 * @brief Changes the range of a planet's presence.
 * 
 * @param planet name of planet to be modified
 * @param presence presence rangevalue to be changed to 
 * @return 0 on success
 */
int unistate_setRange(char *planet, int range)
{
   
   if(!planet) return -3;
   assetStatePtr node = NULL;
   Planet *p = NULL;
   //Get planet struct. If it return errors, bail.
   if((p = planet_get(planet)) == NULL) 
      return -2;
   //Change the presence of the planet
   p->presenceRange = (double)range;
   //update the universe
   space_reconstructPresences();
   //does the planet already have mods?
   if((node = unistate_getNode(planet)) != NULL)
   {
      //if a faction mod hasn't been added yet
      node->range = range;
      return 0;
   }
   //else we need to make a new node
   else
      return unistate_addNode(planet, NULL, -1, range);
}
Exemplo n.º 5
0
Arquivo: unidiff.c Projeto: naev/naev
/**
 * @brief Actually applies a diff in XML node form.
 *
 *    @param parent Node containing the diff information.
 *    @return 0 on success.
 */
static int diff_patch( xmlNodePtr parent )
{
   int i, univ_update;
   UniDiff_t *diff;
   UniHunk_t *fail;
   xmlNodePtr node;
   char *target;

   /* Prepare it. */
   diff = diff_newDiff();
   memset(diff, 0, sizeof(UniDiff_t));
   xmlr_attr(parent,"name",diff->name);

   /* Whether or not we need to update the universe. */
   univ_update = 0;

   node = parent->xmlChildrenNode;
   do {
      xml_onlyNodes(node);
      if (xml_isNode(node,"system")) {
         univ_update = 1;
         diff_patchSystem( diff, node );
      }
      else if (xml_isNode(node, "tech"))
         diff_patchTech( diff, node );
      else if (xml_isNode(node, "asset")) {
         univ_update = 1;
         diff_patchAsset( diff, node );
      }
      else if (xml_isNode(node, "faction")) {
         univ_update = 1;
         diff_patchFaction( diff, node );
      }
      else
         WARN(_("Unidiff '%s' has unknown node '%s'."), diff->name, node->name);
   } while (xml_nextNode(node));

   if (diff->nfailed > 0) {
      WARN(_("Unidiff '%s' failed to apply %d hunks."), diff->name, diff->nfailed);
      for (i=0; i<diff->nfailed; i++) {
         fail   = &diff->failed[i];
         target = fail->target.u.name;
         switch (fail->type) {
            case HUNK_TYPE_ASSET_ADD:
               WARN(_("   [%s] asset add: '%s'"), target, fail->u.name);
               break;
            case HUNK_TYPE_ASSET_REMOVE:
               WARN(_("   [%s] asset remove: '%s'"), target, fail->u.name);
               break;
            case HUNK_TYPE_ASSET_BLACKMARKET:
               WARN(_("   [%s] asset blackmarket: '%s'"), target, fail->u.name);
               break;
            case HUNK_TYPE_ASSET_LEGALMARKET:
               WARN(_("   [%s] asset legalmarket: '%s'"), target, fail->u.name);
               break;
            case HUNK_TYPE_JUMP_ADD:
               WARN(_("   [%s] jump add: '%s'"), target, fail->u.name);
               break;
            case HUNK_TYPE_JUMP_REMOVE:
               WARN(_("   [%s] jump remove: '%s'"), target, fail->u.name);
               break;
            case HUNK_TYPE_TECH_ADD:
               WARN(_("   [%s] tech add: '%s'"), target,
                     fail->u.name );
               break;
            case HUNK_TYPE_TECH_REMOVE:
               WARN(_("   [%s] tech remove: '%s'"), target,
                     fail->u.name );
               break;
            case HUNK_TYPE_ASSET_FACTION:
               WARN(_("   [%s] asset faction: '%s'"), target,
                     fail->u.name );
               break;
            case HUNK_TYPE_ASSET_FACTION_REMOVE:
               WARN(_("   [%s] asset faction removal: '%s'"), target,
                     fail->u.name );
               break;
            case HUNK_TYPE_FACTION_VISIBLE:
               WARN(_("   [%s] faction visible: '%s'"), target,
                     fail->u.name );
               break;
            case HUNK_TYPE_FACTION_INVISIBLE:
               WARN(_("   [%s] faction invisible: '%s'"), target,
                     fail->u.name );
               break;
            case HUNK_TYPE_FACTION_ALLY:
               WARN(_("   [%s] faction set ally: '%s'"), target,
                     fail->u.name );
               break;
            case HUNK_TYPE_FACTION_ENEMY:
               WARN(_("   [%s] faction set enemy: '%s'"), target,
                     fail->u.name );
               break;
            case HUNK_TYPE_FACTION_NEUTRAL:
               WARN(_("   [%s] faction set neutral: '%s'"), target,
                     fail->u.name );
               break;
            case HUNK_TYPE_FACTION_REALIGN:
               WARN(_("   [%s] faction alignment reset: '%s'"), target,
                     fail->u.name );
               break;

            default:
               WARN(_("   unknown hunk '%d'"), fail->type);
               break;
         }
      }
   }

   /* Prune presences if necessary. */
   if (univ_update)
      space_reconstructPresences();

   /* Update overlay map just in case. */
   ovr_refresh();
   return 0;
}