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 Level * const level = (Level*)param;
19 const char * const goal_id = NULL;
21 struct EvalResult result = unpack_args(gc, "s", args, &goal_id);
22 if (result.is_error) {
26 level_hide_goal(level, goal_id);
28 return eval_success(NIL(gc));
32 show_goal(void *param, Gc *gc, struct Scope *scope, struct Expr args)
39 return wrong_argument_type(gc, "listp", args);
42 if (length_of_list(args) != 1) {
43 return wrong_number_of_arguments(gc, length_of_list(args));
46 if (!string_p(CAR(args))) {
47 return wrong_argument_type(gc, "stringp", args);
50 const char * const goal_id = CAR(args).atom->str;
51 Level * const level = (Level*)param;
53 level_show_goal(level, goal_id);
55 return eval_success(NIL(gc));
58 struct EvalResult rect_apply_force(void *param, Gc *gc, struct Scope *scope, struct Expr args)
64 /* TODO(#401): rect_apply_force doesn't sanitize it's input */
66 Level *level = (Level*) param;
67 const char *rect_id = CAR(args).atom->str;
68 struct Expr vector_force_expr = CAR(CDR(args));
69 const float force_x = (float) CAR(vector_force_expr).atom->num;
70 const float force_y = (float) CDR(vector_force_expr).atom->num;
72 print_expr_as_sexpr(stdout, args); printf("\n");
74 Rigid_rect *rigid_rect = level_rigid_rect(level, rect_id);
75 if (rigid_rect != NULL) {
76 log_info("Found rect `%s`\n", rect_id);
77 log_info("Applying force (%f, %f)\n", force_x, force_y);
78 rigid_rect_apply_force(rigid_rect, vec(force_x, force_y));
80 log_fail("Couldn't find rigid_rect `%s`\n", rect_id);
83 return eval_success(NIL(gc));
86 void load_level_library(Gc *gc, struct Scope *scope, Level *level)
91 SYMBOL(gc, "rect-apply-force"),
92 NATIVE(gc, rect_apply_force, level));
96 SYMBOL(gc, "hide-goal"),
97 NATIVE(gc, hide_goal, level));
101 SYMBOL(gc, "show-goal"),
102 NATIVE(gc, show_goal, level));