Browse files

* Reworked the jump point unidiff format.

** All jump point parameters are now attributes, not subnodes, in keeping with the existing unidiff syntax.
** x and y parameters are optional, if omitted the jump point will be auto-positioned.
** hide parameter is optional.
** type parameter is optional and can be either "hidden" or "exitonly".
  • Loading branch information...
1 parent 23a82d3 commit 8fb57f34410054d54c86eff1a896dfb9ee0160c2 BTAxis committed Sep 21, 2012
Showing with 39 additions and 60 deletions.
  1. +2 −7 dat/unidiff.xml
  2. +0 −2 src/dev_sysedit.c
  3. +2 −0 src/dev_sysedit.h
  4. +0 −4 src/dev_uniedit.c
  5. +4 −0 src/dev_uniedit.h
  6. +30 −46 src/space.c
  7. +1 −1 src/unidiff.c
View
9 dat/unidiff.xml
@@ -59,15 +59,10 @@
</unidiff>
<unidiff name="test">
<system name="Hakoi">
- <jump target="Gamma Polaris" type="add">
- <autopos/>
- </jump>
+ <jump target="Gamma Polaris" x="10" y="10" hide="0">add</jump>
</system>
<system name="Gamma Polaris">
- <jump target="Hakoi" type="add">
- <autopos/>
- <type>1</type>
- </jump>
+ <jump target="Hakoi" type="exitonly">add</jump>
</system>
</unidiff>
</unidiffs>
View
2 src/dev_sysedit.c
@@ -30,8 +30,6 @@
#include "npng.h"
-#define HIDE_DEFAULT_PLANET 0.25 /**< Default hide value for new planets. */
-
#define BUTTON_WIDTH 90 /**< Map button width. */
#define BUTTON_HEIGHT 30 /**< Map button height. */
View
2 src/dev_sysedit.h
@@ -11,6 +11,8 @@
#include "space.h"
+#define HIDE_DEFAULT_PLANET 0.25 /**< Default hide value for new planets. */
+
void sysedit_open( StarSystem *sys );
void sysedit_sysScale( StarSystem *sys, double factor );
View
4 src/dev_uniedit.c
@@ -29,10 +29,6 @@
#include "nstring.h"
-#define HIDE_DEFAULT_JUMP 1.25 /**< Default hide value for new jumps. */
-#define RADIUS_DEFAULT 10000 /**< Default radius for new systems. */
-#define STARS_DENSITY_DEFAULT 400 /**< Default stars density for new systems. */
-
#define BUTTON_WIDTH 80 /**< Map button width. */
#define BUTTON_HEIGHT 30 /**< Map button height. */
View
4 src/dev_uniedit.h
@@ -7,6 +7,10 @@
#ifndef DEV_UNIEDIT_H
# define DEV_UNIEDIT_H
+#define HIDE_DEFAULT_JUMP 1.25 /**< Default hide value for new jumps. */
+#define RADIUS_DEFAULT 10000 /**< Default radius for new systems. */
+#define STARS_DENSITY_DEFAULT 400 /**< Default stars density for new systems. */
+
void uniedit_open( unsigned int wid_unused, char *unused );
void uniedit_selectText (void);
View
76 src/space.c
@@ -50,6 +50,7 @@
#include "map.h"
#include "damagetype.h"
#include "hook.h"
+#include "dev_uniedit.h"
#define XML_PLANET_TAG "asset" /**< Individual planet xml tag. */
@@ -2464,10 +2465,8 @@ static int system_parseJumpPoint( const xmlNodePtr node, StarSystem *sys )
{
JumpPoint *j;
char *buf;
- xmlNodePtr cur;
double x, y;
StarSystem *target;
- int pos;
/* Get target. */
xmlr_attr( node, "target", buf );
@@ -2500,56 +2499,41 @@ static int system_parseJumpPoint( const xmlNodePtr node, StarSystem *sys )
j = &sys->jumps[ sys->njumps ];
memset( j, 0, sizeof(JumpPoint) );
+ /* Handle jump point position. We want both x and y, or we autoposition the jump point. */
+ xmlr_attr( node, "x", buf );
+ if (buf == NULL)
+ jp_setFlag(j,JP_AUTOPOS);
+ else
+ x = atof(buf);
+ xmlr_attr( node, "y", buf );
+ if (buf == NULL)
+ jp_setFlag(j,JP_AUTOPOS);
+ else
+ y = atof(buf);
+
+ /* Handle jump point type. */
+ xmlr_attr( node, "type", buf );
+ if (buf == NULL);
+ else if (!strcmp(buf, "hidden"))
+ jp_setFlag(j,JP_HIDDEN);
+ else if (!strcmp(buf, "exitonly"))
+ jp_setFlag(j,JP_EXITONLY);
+
+ /* Handle jump point hide. */
+ xmlr_attr( node, "hide", buf );
+ if (buf == NULL)
+ j->hide = HIDE_DEFAULT_JUMP;
+ else
+ j->hide = atoi(buf);
+
/* Set some stuff. */
j->target = target;
free(buf);
j->targetid = j->target->id;
j->radius = 200.;
- pos = 0;
-
- /* Parse data. */
- cur = node->xmlChildrenNode;
- do {
- xmlr_float( cur, "radius", j->radius );
-
- /* Handle position. */
- if (xml_isNode(cur,"pos")) {
- pos = 1;
- xmlr_attr( cur, "x", buf );
- if (buf==NULL) {
- WARN("JumpPoint for system '%s' has position node missing 'x' position, using 0.", sys->name);
- x = 0.;
- }
- else {
- x = atof(buf);
- free(buf);
- }
- xmlr_attr( cur, "y", buf );
- if (buf==NULL) {
- WARN("JumpPoint for system '%s' has position node missing 'y' position, using 0.", sys->name);
- y = 0.;
- }
- else {
- y = atof(buf);
- free(buf);
- }
-
- /* Set position. */
- vect_cset( &j->pos, x, y );
- }
- else if (xml_isNode(cur,"autopos"))
- jp_setFlag(j,JP_AUTOPOS);
- else if (xml_isNode(cur,"hidden"))
- jp_setFlag(j,JP_HIDDEN);
- else if (xml_isNode(cur,"exitonly"))
- jp_setFlag(j,JP_EXITONLY);
- else if (xml_isNode(cur,"hide")) {
- xmlr_float( cur,"hide", j->hide );
- }
- } while (xml_nextNode(cur));
- if (!jp_isFlag(j,JP_AUTOPOS) && !pos)
- WARN("JumpPoint in system '%s' is missing pos element but does not have autopos flag.", sys->name);
+ if (!jp_isFlag(j,JP_AUTOPOS))
+ vect_cset( &j->pos, x, y );
/* Square to allow for linear multiplication with squared distances. */
j->hide = pow2(j->hide);
View
2 src/unidiff.c
@@ -293,7 +293,7 @@ static int diff_patchSystem( UniDiff_t *diff, xmlNodePtr node )
xmlr_attr(cur,"target",hunk.u.name);
/* Get the type. */
- xmlr_attr(cur,"type",buf);
+ buf = xml_get(cur);
if (buf==NULL) {
WARN("Unidiff '%s': Null hunk type.", diff->name);
continue;

0 comments on commit 8fb57f3

Please sign in to comment.