1 #include "system/stacktrace.h"
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"
11 static struct EvalResult
12 rect_apply_force(void *param, Gc *gc, struct Scope *scope, struct Expr args)
18 Level *level = (Level*) param;
20 const char *rect_id = NULL;
21 struct Expr force = void_expr();
22 struct EvalResult result = match_list(gc, "se", args, &rect_id, &force);
23 if (result.is_error) {
27 long int force_x = 0L;
28 long int force_y = 0L;
29 result = match_list(gc, "dd", force, &force_x, &force_y);
30 if (result.is_error) {
34 Rigid_rect *rigid_rect = level_rigid_rect(level, rect_id);
35 if (rigid_rect != NULL) {
36 log_info("Found rect `%s`\n", rect_id);
37 log_info("Applying force (%ld, %ld)\n", force_x, force_y);
38 rigid_rect_apply_force(rigid_rect, vec((float) force_x, (float) force_y));
39 return eval_success(NIL(gc));
41 return eval_failure(list(gc, "qs", "unexisting-rigid-rect", rect_id));
45 static struct EvalResult
46 hide_label(void *param, Gc *gc, struct Scope *scope, struct Expr args)
52 Level *level = (Level*) param;
53 const char *label_id = NULL;
55 struct EvalResult result = match_list(gc, "s", args, &label_id);
56 if (result.is_error) {
60 level_hide_label(level, label_id);
62 return eval_success(NIL(gc));
65 void load_level_library(Gc *gc, struct Scope *scope, Level *level)
70 SYMBOL(gc, "rect-apply-force"),
71 NATIVE(gc, rect_apply_force, level));
75 SYMBOL(gc, "hide-label"),
76 NATIVE(gc, hide_label, level));