]> git.lizzy.rs Git - nothing.git/blobdiff - src/game/level_script.c
Merge pull request #621 from tsoding/615
[nothing.git] / src / game / level_script.c
index d1f66552281d4dadb06feb849396a95c3b2df31e..97654e843c666204b356b540de9fe97c78cb1b60 100644 (file)
@@ -1,4 +1,4 @@
-#include <assert.h>
+#include "system/stacktrace.h"
 
 #include "ebisp/gc.h"
 #include "ebisp/interpreter.h"
 #include "system/log.h"
 
 static struct EvalResult
-hide_goal(void *param, Gc *gc, struct Scope *scope, struct Expr args)
+rect_apply_force(void *param, Gc *gc, struct Scope *scope, struct Expr args)
 {
-    assert(param);
-    assert(gc);
-    assert(scope);
+    trace_assert(gc);
+    trace_assert(scope);
+    trace_assert(param);
 
-    Level * const level = (Level*)param;
-    const char * const goal_id = NULL;
+    Level *level = (Level*) param;
 
-    struct EvalResult result = match_list(gc, "s", args, &goal_id);
+    const char *rect_id = NULL;
+    struct Expr force = void_expr();
+    struct EvalResult result = match_list(gc, "se", args, &rect_id, &force);
     if (result.is_error) {
         return result;
     }
 
-    level_hide_goal(level, goal_id);
-
-    return eval_success(NIL(gc));
-}
-
-static struct EvalResult
-show_goal(void *param, Gc *gc, struct Scope *scope, struct Expr args)
-{
-    assert(param);
-    assert(gc);
-    assert(scope);
-
-    Level * const level = (Level*)param;
-    const char *goal_id = NULL;
-
-    struct EvalResult result = match_list(gc, "s", args, &goal_id);
+    long int force_x = 0L;
+    long int force_y = 0L;
+    result = match_list(gc, "dd", force, &force_x, &force_y);
     if (result.is_error) {
         return result;
     }
 
-    level_show_goal(level, goal_id);
-
-    return eval_success(NIL(gc));
-}
-
-static struct EvalResult
-rect_apply_force(void *param, Gc *gc, struct Scope *scope, struct Expr args)
-{
-    assert(gc);
-    assert(scope);
-    assert(param);
-
-    /* TODO(#401): rect_apply_force doesn't sanitize it's input */
-
-    Level *level = (Level*) param;
-    const char *rect_id = CAR(args).atom->str;
-    struct Expr vector_force_expr = CAR(CDR(args));
-    const float force_x = (float) CAR(vector_force_expr).atom->num;
-    const float force_y = (float) CDR(vector_force_expr).atom->num;
-
-    print_expr_as_sexpr(stdout, args); printf("\n");
-
     Rigid_rect *rigid_rect = level_rigid_rect(level, rect_id);
     if (rigid_rect != NULL) {
         log_info("Found rect `%s`\n", rect_id);
-        log_info("Applying force (%f, %f)\n", force_x, force_y);
-        rigid_rect_apply_force(rigid_rect, vec(force_x, force_y));
+        log_info("Applying force (%ld, %ld)\n", force_x, force_y);
+        rigid_rect_apply_force(rigid_rect, vec((float) force_x, (float) force_y));
+        return eval_success(NIL(gc));
     } else {
-        log_fail("Couldn't find rigid_rect `%s`\n", rect_id);
+        return eval_failure(list(gc, "qs", "unexisting-rigid-rect", rect_id));
     }
-
-    return eval_success(NIL(gc));
 }
 
 static struct EvalResult
 hide_label(void *param, Gc *gc, struct Scope *scope, struct Expr args)
 {
-    assert(param);
-    assert(gc);
-    assert(scope);
-    (void) args;
-
-    /* TODO(#522): hide-label is not implemented */
-
-    return not_implemented(gc);
-}
-
-static struct EvalResult
-show_label(void *param, Gc *gc, struct Scope *scope, struct Expr args)
-{
-    assert(param);
-    assert(gc);
-    assert(scope);
-    (void) args;
+    trace_assert(param);
+    trace_assert(gc);
+    trace_assert(scope);
 
-    /* TODO(#523): show-label is not implemented */
+    Level *level = (Level*) param;
+    const char *label_id = NULL;
 
-    return not_implemented(gc);
-}
+    struct EvalResult result = match_list(gc, "s", args, &label_id);
+    if (result.is_error) {
+        return result;
+    }
 
-static struct EvalResult
-get_player_jump_count(void *param, Gc *gc, struct Scope *scope, struct Expr args)
-{
-    assert(param);
-    assert(gc);
-    assert(scope);
-    (void) args;
+    level_hide_label(level, label_id);
 
-    Level *level = (Level*)param;
-    return eval_success(
-        NUMBER(gc, level_player_jump_count(level)));
+    return eval_success(NIL(gc));
 }
 
 void load_level_library(Gc *gc, struct Scope *scope, Level *level)
@@ -123,29 +69,9 @@ void load_level_library(Gc *gc, struct Scope *scope, Level *level)
         scope,
         SYMBOL(gc, "rect-apply-force"),
         NATIVE(gc, rect_apply_force, level));
-    set_scope_value(
-        gc,
-        scope,
-        SYMBOL(gc, "hide-goal"),
-        NATIVE(gc, hide_goal, level));
-    set_scope_value(
-        gc,
-        scope,
-        SYMBOL(gc, "show-goal"),
-        NATIVE(gc, show_goal, level));
-    set_scope_value(
-        gc,
-        scope,
-        SYMBOL(gc, "show-label"),
-        NATIVE(gc, show_label, level));
     set_scope_value(
         gc,
         scope,
         SYMBOL(gc, "hide-label"),
         NATIVE(gc, hide_label, level));
-    set_scope_value(
-        gc,
-        scope,
-        SYMBOL(gc, "get-player-jump-count"),
-        NATIVE(gc, get_player_jump_count, level));
 }