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(#507): 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) {
54 return wrong_number_of_arguments(gc, length_of_list(args));
57 if (!string_p(CAR(args))) {
58 return wrong_argument_type(gc, "stringp", args);
61 const char * const goal_id = CAR(args).atom->str;
62 Level * const level = (Level*)param;
64 level_show_goal(level, goal_id);
66 return eval_success(NIL(gc));
69 struct EvalResult rect_apply_force(void *param, Gc *gc, struct Scope *scope, struct Expr args)
75 /* TODO(#401): rect_apply_force doesn't sanitize it's input */
77 Level *level = (Level*) param;
78 const char *rect_id = CAR(args).atom->str;
79 struct Expr vector_force_expr = CAR(CDR(args));
80 const float force_x = (float) CAR(vector_force_expr).atom->num;
81 const float force_y = (float) CDR(vector_force_expr).atom->num;
83 print_expr_as_sexpr(stdout, args); printf("\n");
85 Rigid_rect *rigid_rect = level_rigid_rect(level, rect_id);
86 if (rigid_rect != NULL) {
87 log_info("Found rect `%s`\n", rect_id);
88 log_info("Applying force (%f, %f)\n", force_x, force_y);
89 rigid_rect_apply_force(rigid_rect, vec(force_x, force_y));
91 log_fail("Couldn't find rigid_rect `%s`\n", rect_id);
94 return eval_success(NIL(gc));
97 void load_level_library(Gc *gc, struct Scope *scope, Level *level)
102 SYMBOL(gc, "rect-apply-force"),
103 NATIVE(gc, rect_apply_force, level));
107 SYMBOL(gc, "hide-goal"),
108 NATIVE(gc, hide_goal, level));
112 SYMBOL(gc, "show-goal"),
113 NATIVE(gc, show_goal, level));