4 #include "ebisp/interpreter.h"
5 #include "ebisp/scope.h"
6 #include "game/level/player/rigid_rect.h"
8 #include "level_script.h"
9 #include "system/log.h"
12 hide_goal(void *param, Gc *gc, struct Scope *scope, struct Expr args)
18 /* TODO: Manually parsing args of native functions is tedious. */
20 return wrong_argument_type(gc, "listp", args);
23 if (length_of_list(args) != 1) {
26 SYMBOL(gc, "wrong-number-of-arguments"),
27 NUMBER(gc, length_of_list(args))));
30 if (!string_p(CAR(args))) {
31 return wrong_argument_type(gc, "stringp", args);
34 const char * const goal_id = CAR(args).atom->str;
35 Level * const level = (Level*)param;
37 level_hide_goal(level, goal_id);
39 return eval_success(NIL(gc));
43 show_goal(void *param, Gc *gc, struct Scope *scope, struct Expr args)
50 return wrong_argument_type(gc, "listp", args);
53 if (length_of_list(args) != 1) {
56 SYMBOL(gc, "wrong-number-of-arguments"),
57 NUMBER(gc, length_of_list(args))));
60 if (!string_p(CAR(args))) {
61 return wrong_argument_type(gc, "stringp", args);
64 const char * const goal_id = CAR(args).atom->str;
65 Level * const level = (Level*)param;
67 level_show_goal(level, goal_id);
69 return eval_success(NIL(gc));
72 struct EvalResult rect_apply_force(void *param, Gc *gc, struct Scope *scope, struct Expr args)
78 /* TODO(#401): rect_apply_force doesn't sanitize it's input */
80 Level *level = (Level*) param;
81 const char *rect_id = CAR(args).atom->str;
82 struct Expr vector_force_expr = CAR(CDR(args));
83 const float force_x = (float) CAR(vector_force_expr).atom->num;
84 const float force_y = (float) CDR(vector_force_expr).atom->num;
86 print_expr_as_sexpr(stdout, args); printf("\n");
88 Rigid_rect *rigid_rect = level_rigid_rect(level, rect_id);
89 if (rigid_rect != NULL) {
90 log_info("Found rect `%s`\n", rect_id);
91 log_info("Applying force (%f, %f)\n", force_x, force_y);
92 rigid_rect_apply_force(rigid_rect, vec(force_x, force_y));
94 log_fail("Couldn't find rigid_rect `%s`\n", rect_id);
97 return eval_success(NIL(gc));
100 void load_level_library(Gc *gc, struct Scope *scope, Level *level)
105 SYMBOL(gc, "rect-apply-force"),
106 NATIVE(gc, rect_apply_force, level));
110 SYMBOL(gc, "hide-goal"),
111 NATIVE(gc, hide_goal, level));
115 SYMBOL(gc, "show-goal"),
116 NATIVE(gc, show_goal, level));