updated URL of forum and table in readme file
[neverball] / share / solid.c
index 558fcb3..467da87 100644 (file)
@@ -180,10 +180,11 @@ static void sol_load_body(FILE *fin, struct s_body *bp)
     get_index(fin, &bp->gc);
 }
 
-static void sol_load_coin(FILE *fin, struct s_coin *cp)
+static void sol_load_item(FILE *fin, struct s_item *hp)
 {
-    get_array(fin,  cp->p, 3);
-    get_index(fin, &cp->n);
+    get_array(fin,  hp->p, 3);
+    get_index(fin, &hp->t);
+    get_index(fin, &hp->n);
 }
 
 static void sol_load_goal(FILE *fin, struct s_goal *zp)
@@ -264,7 +265,7 @@ static int sol_load_file(FILE *fin, struct s_file *fp)
     get_index(fin, &fp->nc);
     get_index(fin, &fp->pc);
     get_index(fin, &fp->bc);
-    get_index(fin, &fp->cc);
+    get_index(fin, &fp->hc);
     get_index(fin, &fp->zc);
     get_index(fin, &fp->jc);
     get_index(fin, &fp->xc);
@@ -295,8 +296,8 @@ static int sol_load_file(FILE *fin, struct s_file *fp)
         fp->pv = (struct s_path *) calloc(fp->pc, sizeof (struct s_path));
     if (fp->bc)
         fp->bv = (struct s_body *) calloc(fp->bc, sizeof (struct s_body));
-    if (fp->cc)
-        fp->cv = (struct s_coin *) calloc(fp->cc, sizeof (struct s_coin));
+    if (fp->hc)
+        fp->hv = (struct s_item *) calloc(fp->hc, sizeof (struct s_item));
     if (fp->zc)
         fp->zv = (struct s_goal *) calloc(fp->zc, sizeof (struct s_goal));
     if (fp->jc)
@@ -325,7 +326,7 @@ static int sol_load_file(FILE *fin, struct s_file *fp)
     for (i = 0; i < fp->nc; i++) sol_load_node(fin, fp->nv + i);
     for (i = 0; i < fp->pc; i++) sol_load_path(fin, fp->pv + i);
     for (i = 0; i < fp->bc; i++) sol_load_body(fin, fp->bv + i);
-    for (i = 0; i < fp->cc; i++) sol_load_coin(fin, fp->cv + i);
+    for (i = 0; i < fp->hc; i++) sol_load_item(fin, fp->hv + i);
     for (i = 0; i < fp->zc; i++) sol_load_goal(fin, fp->zv + i);
     for (i = 0; i < fp->jc; i++) sol_load_jump(fin, fp->jv + i);
     for (i = 0; i < fp->xc; i++) sol_load_swch(fin, fp->xv + i);
@@ -361,7 +362,7 @@ static int sol_load_head(FILE *fin, struct s_file *fp)
     get_index(fin, &fp->nc);
     get_index(fin, &fp->pc);
     get_index(fin, &fp->bc);
-    get_index(fin, &fp->cc);
+    get_index(fin, &fp->hc);
     get_index(fin, &fp->zc);
     get_index(fin, &fp->jc);
     get_index(fin, &fp->xc);
@@ -497,10 +498,11 @@ static void sol_stor_body(FILE *fout, struct s_body *bp)
     put_index(fout, &bp->gc);
 }
 
-static void sol_stor_coin(FILE *fout, struct s_coin *cp)
+static void sol_stor_item(FILE *fout, struct s_item *hp)
 {
-    put_array(fout,  cp->p, 3);
-    put_index(fout, &cp->n);
+    put_array(fout,  hp->p, 3);
+    put_index(fout, &hp->t);
+    put_index(fout, &hp->n);
 }
 
 static void sol_stor_goal(FILE *fout, struct s_goal *zp)
@@ -578,7 +580,7 @@ static void sol_stor_file(FILE *fin, struct s_file *fp)
     put_index(fin, &fp->nc);
     put_index(fin, &fp->pc);
     put_index(fin, &fp->bc);
-    put_index(fin, &fp->cc);
+    put_index(fin, &fp->hc);
     put_index(fin, &fp->zc);
     put_index(fin, &fp->jc);
     put_index(fin, &fp->xc);
@@ -598,7 +600,7 @@ static void sol_stor_file(FILE *fin, struct s_file *fp)
     for (i = 0; i < fp->nc; i++) sol_stor_node(fin, fp->nv + i);
     for (i = 0; i < fp->pc; i++) sol_stor_path(fin, fp->pv + i);
     for (i = 0; i < fp->bc; i++) sol_stor_body(fin, fp->bv + i);
-    for (i = 0; i < fp->cc; i++) sol_stor_coin(fin, fp->cv + i);
+    for (i = 0; i < fp->hc; i++) sol_stor_item(fin, fp->hv + i);
     for (i = 0; i < fp->zc; i++) sol_stor_goal(fin, fp->zv + i);
     for (i = 0; i < fp->jc; i++) sol_stor_jump(fin, fp->jv + i);
     for (i = 0; i < fp->xc; i++) sol_stor_swch(fin, fp->xv + i);
@@ -636,7 +638,7 @@ void sol_free(struct s_file *fp)
     if (fp->nv) free(fp->nv);
     if (fp->pv) free(fp->pv);
     if (fp->bv) free(fp->bv);
-    if (fp->cv) free(fp->cv);
+    if (fp->hc) free(fp->hv);
     if (fp->zv) free(fp->zv);
     if (fp->jv) free(fp->jv);
     if (fp->xv) free(fp->xv);
@@ -1311,33 +1313,31 @@ float sol_step(struct s_file *fp, const float *g, float dt, int ui, int *m)
 
 /*---------------------------------------------------------------------------*/
 
-int sol_coin_test(struct s_file *fp, float *p, float coin_r)
+struct s_item *sol_item_test(struct s_file *fp, float *p, float item_r)
 {
     const float *ball_p = fp->uv->p;
     const float  ball_r = fp->uv->r;
-    int ci, n;
 
-    for (ci = 0; ci < fp->cc; ci++)
+    int hi;
+
+    for (hi = 0; hi < fp->hc; hi++)
     {
         float r[3];
 
-        r[0] = ball_p[0] - fp->cv[ci].p[0];
-        r[1] = ball_p[1] - fp->cv[ci].p[1];
-        r[2] = ball_p[2] - fp->cv[ci].p[2];
+        r[0] = ball_p[0] - fp->hv[hi].p[0];
+        r[1] = ball_p[1] - fp->hv[hi].p[1];
+        r[2] = ball_p[2] - fp->hv[hi].p[2];
 
-        if (fp->cv[ci].n > 0 && v_len(r) < ball_r + coin_r)
+        if (fp->hv[hi].t != ITEM_NONE && v_len(r) < ball_r + item_r)
         {
-            p[0] = fp->cv[ci].p[0];
-            p[1] = fp->cv[ci].p[1];
-            p[2] = fp->cv[ci].p[2];
-
-            n = fp->cv[ci].n;
-            fp->cv[ci].n = 0;
+            p[0] = fp->hv[hi].p[0];
+            p[1] = fp->hv[hi].p[1];
+            p[2] = fp->hv[hi].p[2];
 
-            return n;
+            return &fp->hv[hi];
         }
     }
-    return 0;
+    return NULL;
 }
 
 struct s_goal *sol_goal_test(struct s_file *fp, float *p, int ui)