diff --git a/data/ingame.ogg b/data/ingame.ogg new file mode 100644 index 0000000..5a69344 Binary files /dev/null and b/data/ingame.ogg differ diff --git a/data/walk.wav b/data/walk.wav new file mode 100644 index 0000000..27fd545 Binary files /dev/null and b/data/walk.wav differ diff --git a/source/actor.cpp b/source/actor.cpp index 9cba612..c295ae2 100644 --- a/source/actor.cpp +++ b/source/actor.cpp @@ -3,6 +3,7 @@ #include "jinput.h" #include "jfile.h" #include "jutil.h" +#include "jaudio.h" #include "room.h" #include "editor.h" #include "debug.h" @@ -16,20 +17,22 @@ namespace actor {0, 1, 0, 2}, {0, 1, 2, 3}, {0, 1, 2, 0}, - {0, 1, 0, 1} - }; + {0, 1, 0, 1}}; actor_t *first = nullptr; actor_t *dirty = nullptr; actor_t *selected = nullptr; actor_t *picked = nullptr; static bool room_changed = false; - int brilli_brilli=0; - draw::surface *brilli; - + int brilli_brilli = 0; + draw::surface *brilli; + int current_tag = 0; bool floating_editing = false; + audio::sound *walk = nullptr; + int walk_channel = -1; + void resetTag() { current_tag = 0; @@ -42,9 +45,11 @@ namespace actor actor_t *getLast() { - if (!first) return nullptr; + if (!first) + return nullptr; actor_t *last = first; - while(last->next) last = last->next; + while (last->next) + last = last->next; return last; } @@ -68,18 +73,18 @@ namespace actor actor_t *createEmptyActor() { - actor_t *act = (actor_t*)malloc(sizeof(actor_t)); + actor_t *act = (actor_t *)malloc(sizeof(actor_t)); act->tag = current_tag++; act->pos = {0, 0, 0}; - act->size = {8,8,8}; - act->bmp_rect = {0,0,32,32}; - act->bmp_offset = {0,0}; + act->size = {8, 8, 8}; + act->bmp_rect = {0, 0, 32, 32}; + act->bmp_offset = {0, 0}; act->anim_cycle = act->orient = act->movement = 0; act->push = act->mov_push = PUSH_NONE; act->below = act->above = nullptr; act->prev = act->next = nullptr; act->anim_wait = act->anim_wait_count = 0; - act->anim_frame=0; + act->anim_frame = 0; act->react_mask = act->react_push = 0; act->flags = FLAG_NONE; act->template_category = 0; @@ -90,7 +95,7 @@ namespace actor { actor_t *new_act = createEmptyActor(); actor::templates::copy(new_act, act); - //new_act->surface = draw::getSurface(new_act->bmp); + // new_act->surface = draw::getSurface(new_act->bmp); new_act->prev = new_act->next = new_act->above = new_act->below = nullptr; return new_act; } @@ -98,7 +103,8 @@ namespace actor actor_t *createFromTemplate(const char *name) { actor_t *templ = actor::templates::getByName(name); - if (!templ) return nullptr; + if (!templ) + return nullptr; return duplicate(templ); } @@ -109,71 +115,99 @@ namespace actor actor_t *t = createEmptyActor(); while (**buffer != 0) { - const char* key = file::readString(buffer); + const char *key = file::readString(buffer); - if (util::strcomp(key, "name:")) { + if (util::strcomp(key, "name:")) + { const char *val = file::readString(buffer); strcpy(t->name, val); - } else if (util::strcomp(key, "bmp:")) { + } + else if (util::strcomp(key, "bmp:")) + { const char *val = file::readString(buffer); strcpy(t->bmp, val); t->surface = draw::getSurface(t->bmp); - } else if (util::strcomp(key, "bmp-rect:")) { + } + else if (util::strcomp(key, "bmp-rect:")) + { t->bmp_rect.x = file::readInt(buffer); t->bmp_rect.y = file::readInt(buffer); t->bmp_rect.w = file::readInt(buffer); t->bmp_rect.h = file::readInt(buffer); - } else if (util::strcomp(key, "bmp-offset:")) { + } + else if (util::strcomp(key, "bmp-offset:")) + { t->bmp_offset.x = file::readInt(buffer); t->bmp_offset.y = file::readInt(buffer); - } else if (util::strcomp(key, "pos:")) { + } + else if (util::strcomp(key, "pos:")) + { t->pos.x = file::readInt(buffer); t->pos.y = file::readInt(buffer); t->pos.z = file::readInt(buffer); - } else if (util::strcomp(key, "size:")) { + } + else if (util::strcomp(key, "size:")) + { t->size.x = file::readInt(buffer); t->size.y = file::readInt(buffer); t->size.z = file::readInt(buffer); - } else if (util::strcomp(key, "orient:")) { + } + else if (util::strcomp(key, "orient:")) + { t->orient = util::stringToInt(file::readString(buffer), {"none", "xp", "xn", "yp", "yn", "zp", "zn"}, {0, 1, 2, 4, 8, 16, 32}); - } else if (util::strcomp(key, "movement:")) { - t->movement = util::stringToInt(file::readString(buffer), {"none", "x", "y", "z", "cw", "ccw", "rand", "randv", "hunt", "randj"},{MOV_NONE, MOV_X, MOV_Y, MOV_Z, MOV_CW, MOV_CCW, MOV_RAND, MOV_RANDV, MOV_HUNT, MOV_RANDJ}); - } else if (util::strcomp(key, "anim-cycle:")) { - t->anim_cycle = util::stringToInt(file::readString(buffer), {"walk", "seq", "min", "duo"},{0, 1, 2, 3}); - } else if (util::strcomp(key, "anim-wait:")) { + } + else if (util::strcomp(key, "movement:")) + { + t->movement = util::stringToInt(file::readString(buffer), {"none", "x", "y", "z", "cw", "ccw", "rand", "randv", "hunt", "randj"}, {MOV_NONE, MOV_X, MOV_Y, MOV_Z, MOV_CW, MOV_CCW, MOV_RAND, MOV_RANDV, MOV_HUNT, MOV_RANDJ}); + } + else if (util::strcomp(key, "anim-cycle:")) + { + t->anim_cycle = util::stringToInt(file::readString(buffer), {"walk", "seq", "min", "duo"}, {0, 1, 2, 3}); + } + else if (util::strcomp(key, "anim-wait:")) + { t->anim_wait = file::readInt(buffer); - } else if (util::strcomp(key, "flags:")) { + } + else if (util::strcomp(key, "flags:")) + { const char *str = file::readString(buffer, true); int value = 0; while (str) { - value |= util::stringToInt(str, { "none", "hero", "pushable", "reactive", "moving", "animated", "orientable", "deadly", "gravity", "pickable", "special", "noeditor", "inertia", "disappear" },{ FLAG_NONE, FLAG_HERO, FLAG_PUSHABLE, FLAG_REACTIVE, FLAG_MOVING, FLAG_ANIMATED, FLAG_ORIENTABLE, FLAG_DEADLY, FLAG_GRAVITY, FLAG_PICKABLE, FLAG_SPECIAL, FLAG_NOEDITOR, FLAG_INERTIA, FLAG_DISAPPEAR }); + value |= util::stringToInt(str, {"none", "hero", "pushable", "reactive", "moving", "animated", "orientable", "deadly", "gravity", "pickable", "special", "noeditor", "inertia", "disappear"}, {FLAG_NONE, FLAG_HERO, FLAG_PUSHABLE, FLAG_REACTIVE, FLAG_MOVING, FLAG_ANIMATED, FLAG_ORIENTABLE, FLAG_DEADLY, FLAG_GRAVITY, FLAG_PICKABLE, FLAG_SPECIAL, FLAG_NOEDITOR, FLAG_INERTIA, FLAG_DISAPPEAR}); str = file::readString(buffer, true); } t->flags = value; - } else if (util::strcomp(key, "react-push:")) { + } + else if (util::strcomp(key, "react-push:")) + { const char *str = file::readString(buffer, true); int value = 0; while (str) { - value |= util::stringToInt(str, { "none", "xp", "xn", "yp", "yn", "zp", "zn" }, { PUSH_NONE, PUSH_XP, PUSH_XN, PUSH_YP, PUSH_YN, PUSH_ZP, PUSH_ZN }); + value |= util::stringToInt(str, {"none", "xp", "xn", "yp", "yn", "zp", "zn"}, {PUSH_NONE, PUSH_XP, PUSH_XN, PUSH_YP, PUSH_YN, PUSH_ZP, PUSH_ZN}); str = file::readString(buffer, true); } t->react_push = value; - } else if (util::strcomp(key, "react-mask:")) { + } + else if (util::strcomp(key, "react-mask:")) + { const char *str = file::readString(buffer, true); int value = 0; while (str) { - value |= util::stringToInt(str, { "none", "xp", "xn", "yp", "yn", "zp", "zn" }, { PUSH_NONE, PUSH_XP, PUSH_XN, PUSH_YP, PUSH_YN, PUSH_ZP, PUSH_ZN }); + value |= util::stringToInt(str, {"none", "xp", "xn", "yp", "yn", "zp", "zn"}, {PUSH_NONE, PUSH_XP, PUSH_XN, PUSH_YP, PUSH_YN, PUSH_ZP, PUSH_ZN}); str = file::readString(buffer, true); } t->react_mask = value; - } else if (util::strcomp(key, "}")) { + } + else if (util::strcomp(key, "}")) + { return t; } } - if (t->flags&FLAG_MOVING) t->mov_push = t->orient; + if (t->flags & FLAG_MOVING) + t->mov_push = t->orient; return t; } return nullptr; @@ -181,15 +215,20 @@ namespace actor actor_t *replaceWithTemplate(actor_t *act, const char *name) { - if (!act) return nullptr; + if (!act) + return nullptr; actor_t *newactor = createFromTemplate(name); newactor->pos.x = act->pos.x; newactor->pos.y = act->pos.y; newactor->pos.z = act->pos.z; - if (act->prev) act->prev->next = newactor; - if (act==first) first = newactor; - if (act==dirty) dirty = newactor; - if (act->next) act->next->prev = newactor; + if (act->prev) + act->prev->next = newactor; + if (act == first) + first = newactor; + if (act == dirty) + dirty = newactor; + if (act->next) + act->next->prev = newactor; newactor->prev = act->prev; newactor->next = act->next; act->prev = act->next = nullptr; @@ -202,11 +241,10 @@ namespace actor void cleanName(actor_t *act) { int size = strlen(act->name); - if (act->name[size-3] == '-' && act->name[size-1] >= 48 && act->name[size-1] <= 57 && act->name[size-2] >= 48 && act->name[size-2] <= 57 ) + if (act->name[size - 3] == '-' && act->name[size - 1] >= 48 && act->name[size - 1] <= 57 && act->name[size - 2] >= 48 && act->name[size - 2] <= 57) { - act->name[size-3] = 0; + act->name[size - 3] = 0; } - } // Li donem al actor un nom únic @@ -220,20 +258,22 @@ namespace actor if (other != act) { // ... però tenim el mateix nom... - if (strcmp(act->name, other->name)==0) + if (strcmp(act->name, other->name) == 0) { // Si el nom actual no acaba en guió + dos digits, li afegim "-01" al final int size = strlen(act->name); - if (act->name[size-3] != '-' || act->name[size-1] < 48 || act->name[size-1] > 57 || act->name[size-2] < 48 || act->name[size-2] > 57 ) + if (act->name[size - 3] != '-' || act->name[size - 1] < 48 || act->name[size - 1] > 57 || act->name[size - 2] < 48 || act->name[size - 2] > 57) { strcat(other->name, "-00"); strcat(act->name, "-01"); - } else { + } + else + { // Si ja acaba en dos digits, agafem el numero, li sumem 1, i li'l tornem a ficar - int num = (act->name[size-1]-48) + (act->name[size-2]-48)*10; + int num = (act->name[size - 1] - 48) + (act->name[size - 2] - 48) * 10; num++; - act->name[size-1] = (num % 10)+48; - act->name[size-2] = int(num / 10)+48; + act->name[size - 1] = (num % 10) + 48; + act->name[size - 2] = int(num / 10) + 48; } // I tornem a començar des del principi amb el nou nom other = first; @@ -245,47 +285,76 @@ namespace actor const char *numToOrient(uint8_t value) { - tmp[0]=0; - if (value==0) return "NONE"; - if (value&1) strcat(tmp, "XP "); - if (value&2) strcat(tmp, "XN "); - if (value&4) strcat(tmp, "YP "); - if (value&8) strcat(tmp, "YN "); - if (value&16) strcat(tmp, "ZP "); - if (value&32) strcat(tmp, "ZN "); + tmp[0] = 0; + if (value == 0) + return "NONE"; + if (value & 1) + strcat(tmp, "XP "); + if (value & 2) + strcat(tmp, "XN "); + if (value & 4) + strcat(tmp, "YP "); + if (value & 8) + strcat(tmp, "YN "); + if (value & 16) + strcat(tmp, "ZP "); + if (value & 32) + strcat(tmp, "ZN "); return tmp; } const char *numToFlags(uint16_t value) { - tmp[0]=0; - if (value==0) return "NONE"; - if (value & FLAG_PICKABLE) strcat(tmp, "PICKABLE "); - if (value & FLAG_PUSHABLE) strcat(tmp, "PUSHABLE "); - if (value & FLAG_REACTIVE) strcat(tmp, "REACTIVE "); - if (value & FLAG_MOVING) strcat(tmp, "MOVING "); - if (value & FLAG_ANIMATED) strcat(tmp, "ANIMATED "); - if (value & FLAG_ORIENTABLE) strcat(tmp, "ORIENTABLE "); - if (value & FLAG_DEADLY) strcat(tmp, "DEADLY "); - if (value & FLAG_GRAVITY) strcat(tmp, "GRAVITY "); - if (value & FLAG_SPECIAL) strcat(tmp, "SPECIAL "); - if (value & FLAG_INERTIA) strcat(tmp, "INERTIA "); - if (value & FLAG_DISAPPEAR) strcat(tmp, "DISAPPEAR "); + tmp[0] = 0; + if (value == 0) + return "NONE"; + if (value & FLAG_PICKABLE) + strcat(tmp, "PICKABLE "); + if (value & FLAG_PUSHABLE) + strcat(tmp, "PUSHABLE "); + if (value & FLAG_REACTIVE) + strcat(tmp, "REACTIVE "); + if (value & FLAG_MOVING) + strcat(tmp, "MOVING "); + if (value & FLAG_ANIMATED) + strcat(tmp, "ANIMATED "); + if (value & FLAG_ORIENTABLE) + strcat(tmp, "ORIENTABLE "); + if (value & FLAG_DEADLY) + strcat(tmp, "DEADLY "); + if (value & FLAG_GRAVITY) + strcat(tmp, "GRAVITY "); + if (value & FLAG_SPECIAL) + strcat(tmp, "SPECIAL "); + if (value & FLAG_INERTIA) + strcat(tmp, "INERTIA "); + if (value & FLAG_DISAPPEAR) + strcat(tmp, "DISAPPEAR "); return tmp; } const char *numToMov(uint8_t value) { - if (value==0) return "NONE"; - if (value==1) return "X"; - if (value==2) return "Y"; - if (value==3) return "Z"; - if (value==4) return "CW"; - if (value==5) return "CCW"; - if (value==6) return "RAND"; - if (value==7) return "RANDV"; - if (value==8) return "HUNT"; - if (value==9) return "RANDJ"; + if (value == 0) + return "NONE"; + if (value == 1) + return "X"; + if (value == 2) + return "Y"; + if (value == 3) + return "Z"; + if (value == 4) + return "CW"; + if (value == 5) + return "CCW"; + if (value == 6) + return "RAND"; + if (value == 7) + return "RANDV"; + if (value == 8) + return "HUNT"; + if (value == 9) + return "RANDJ"; return "NONE"; } @@ -297,7 +366,8 @@ namespace actor void order(actor_t *act) { - if (!act) return; + if (!act) + return; if (!a_is_greater_than_b(act, alpha)) { act->next_alpha = alpha; @@ -327,7 +397,8 @@ namespace actor actor_t *alphaOrder(actor_t *act) { - if (!act) return nullptr; + if (!act) + return nullptr; alpha = act; act->next_alpha = nullptr; act = act->next; @@ -343,7 +414,8 @@ namespace actor void saveToFile(FILE *f, actor_t *act, bool tab) { char ws[5] = ""; - if (tab) strcpy(ws, " "); + if (tab) + strcpy(ws, " "); fprintf(f, "\n%sactor{\n", ws); fprintf(f, " %sname: %s\n", ws, act->name); fprintf(f, " %sbmp: %s\n", ws, act->bmp); @@ -351,22 +423,31 @@ namespace actor fprintf(f, " %sbmp-offset: %i %i\n", ws, act->bmp_offset.x, act->bmp_offset.y); fprintf(f, " %spos: %i %i %i\n", ws, act->pos.x, act->pos.y, act->pos.z); fprintf(f, " %ssize: %i %i %i\n", ws, act->size.x, act->size.y, act->size.z); - if (act->orient!=0) fprintf(f, " %sorient: %s\n", ws, numToOrient(act->orient)); - if (act->anim_cycle!=0) fprintf(f, " %sanim-cycle: %s\n", ws, act->anim_cycle==0 ? "WALK" : act->anim_cycle==1 ? "SEQ" : act->anim_cycle==2 ? "MIN" : "DUO"); - if (act->anim_wait!=0) fprintf(f, " %sanim-wait: %i\n", ws, act->anim_wait); - if (act->flags!=0) fprintf(f, " %sflags: %s\n", ws, numToFlags(act->flags)); - if (act->react_mask!=0) fprintf(f, " %sreact-mask: %s\n", ws, numToOrient(act->react_mask)); - if (act->react_push!=0) fprintf(f, " %sreact-push: %s\n", ws, numToOrient(act->react_push)); - if (act->movement!=0) fprintf(f, " %smovement: %s\n", ws, numToMov(act->movement)); + if (act->orient != 0) + fprintf(f, " %sorient: %s\n", ws, numToOrient(act->orient)); + if (act->anim_cycle != 0) + fprintf(f, " %sanim-cycle: %s\n", ws, act->anim_cycle == 0 ? "WALK" : act->anim_cycle == 1 ? "SEQ" + : act->anim_cycle == 2 ? "MIN" + : "DUO"); + if (act->anim_wait != 0) + fprintf(f, " %sanim-wait: %i\n", ws, act->anim_wait); + if (act->flags != 0) + fprintf(f, " %sflags: %s\n", ws, numToFlags(act->flags)); + if (act->react_mask != 0) + fprintf(f, " %sreact-mask: %s\n", ws, numToOrient(act->react_mask)); + if (act->react_push != 0) + fprintf(f, " %sreact-push: %s\n", ws, numToOrient(act->react_push)); + if (act->movement != 0) + fprintf(f, " %smovement: %s\n", ws, numToMov(act->movement)); fprintf(f, "%s}\n", ws); } const bool check_2d_collision(actor_t *obj1, actor_t *obj2) { - return (obj1->pos.x < obj2->pos.x + obj2->size.x) && - (obj1->pos.x + obj1->size.x > obj2->pos.x ) && - (obj1->pos.y < obj2->pos.y + obj2->size.y) && - (obj1->pos.y + obj1->size.y > obj2->pos.y ); + return (obj1->pos.x < obj2->pos.x + obj2->size.x) && + (obj1->pos.x + obj1->size.x > obj2->pos.x) && + (obj1->pos.y < obj2->pos.y + obj2->size.y) && + (obj1->pos.y + obj1->size.y > obj2->pos.y); } const bool does_collide(actor_t *obj1) @@ -375,7 +456,8 @@ namespace actor actor_t *hero = find("HERO"); while (obj2) { - if (obj2 != hero && obj1 != obj2 && check_2d_collision(obj1, obj2)) return true; + if (obj2 != hero && obj1 != obj2 && check_2d_collision(obj1, obj2)) + return true; obj2 = obj2->next; } return false; @@ -383,7 +465,7 @@ namespace actor const bool is_above(actor_t *obj1, actor_t *obj2) { - return check_2d_collision(obj1, obj2) && (obj1->pos.z==obj2->pos.z+obj2->size.z); + return check_2d_collision(obj1, obj2) && (obj1->pos.z == obj2->pos.z + obj2->size.z); } actor_t *any_above_me(actor_t *act) @@ -391,9 +473,11 @@ namespace actor actor_t *other = first; while (other) { - if (is_above(other, act)) return other; + if (is_above(other, act)) + return other; other = other->next; - if (other == act) other = other->next; + if (other == act) + other = other->next; } /* other = dirty; @@ -412,9 +496,11 @@ namespace actor actor_t *other = first; while (other) { - if (is_above(act, other)) return other; + if (is_above(act, other)) + return other; other = other->next; - if (other == act) other = other->next; + if (other == act) + other = other->next; } /* other = dirty; @@ -430,10 +516,11 @@ namespace actor void setDirty(actor_t *act, const bool force) { - if (!act->prev && !act->next && !(act==first)) + if (!act->prev && !act->next && !(act == first)) { act->next = first; - if (first) first->prev = act; + if (first) + first->prev = act; first = act; } /* @@ -449,32 +536,33 @@ namespace actor */ } - void select(actor_t *act) { + void select(actor_t *act) + { selected = act; } const bool overlap(actor_t *act1, actor_t *act2) { - return act1->inner_x < act2->inner_x+act2->bmp_rect.w && - act1->inner_x+act1->bmp_rect.w > act2->inner_x && - act1->inner_y > act2->inner_y+act2->bmp_rect.h && - act1->inner_y+act1->bmp_rect.h < act2->inner_y; + return act1->inner_x < act2->inner_x + act2->bmp_rect.w && + act1->inner_x + act1->bmp_rect.w > act2->inner_x && + act1->inner_y > act2->inner_y + act2->bmp_rect.h && + act1->inner_y + act1->bmp_rect.h < act2->inner_y; } const bool isInFront(actor_t *act1, actor_t *act2) { - return (act1->pos.x >= act2->pos.x+act2->size.x) || - (act1->pos.y >= act2->pos.y+act2->size.y) || - (act1->pos.z >= act2->pos.z+act2->size.z); -/* - if (act1->pos.x >= act2->pos.x+act2->size.x) { return true; } - else if (act2->pos.x >= act1->pos.x+act1->size.x) { return false; } - else if (act1->pos.y >= act2->pos.y+act2->size.y) { return true; } - else if (act2->pos.y >= act1->pos.y+act1->size.y) { return false; } - else if (act1->pos.z >= act2->pos.z+act2->size.z) { return true; } - else if (act2->pos.z >= act1->pos.z+act1->size.z) { return false; } - else { return false; } -*/ + return (act1->pos.x >= act2->pos.x + act2->size.x) || + (act1->pos.y >= act2->pos.y + act2->size.y) || + (act1->pos.z >= act2->pos.z + act2->size.z); + /* + if (act1->pos.x >= act2->pos.x+act2->size.x) { return true; } + else if (act2->pos.x >= act1->pos.x+act1->size.x) { return false; } + else if (act1->pos.y >= act2->pos.y+act2->size.y) { return true; } + else if (act2->pos.y >= act1->pos.y+act1->size.y) { return false; } + else if (act1->pos.z >= act2->pos.z+act2->size.z) { return true; } + else if (act2->pos.z >= act1->pos.z+act1->size.z) { return false; } + else { return false; } + */ } void reorder() @@ -484,8 +572,8 @@ namespace actor while (dirty) { - dirty->inner_x = 148-dirty->bmp_offset.x + dirty->pos.x*2 - dirty->pos.y*2; - dirty->inner_y = 91-dirty->bmp_offset.y + dirty->pos.x + dirty->pos.y - dirty->pos.z*2; + dirty->inner_x = 148 - dirty->bmp_offset.x + dirty->pos.x * 2 - dirty->pos.y * 2; + dirty->inner_y = 91 - dirty->bmp_offset.y + dirty->pos.x + dirty->pos.y - dirty->pos.z * 2; if (first) { @@ -511,10 +599,12 @@ namespace actor { dirty->prev = current->prev; current->prev = dirty; - if (dirty->prev) dirty->prev->next = dirty; + if (dirty->prev) + dirty->prev->next = dirty; dirty = dirty->next; current->prev->next = current; - if (current==first) first=current->prev; + if (current == first) + first = current->prev; break; } } @@ -523,7 +613,7 @@ namespace actor { first = dirty; dirty = dirty->next; - first->prev=first->next=nullptr; + first->prev = first->next = nullptr; } } } @@ -531,43 +621,55 @@ namespace actor uint8_t push(actor_t *source, actor_t *act, uint8_t push) { uint8_t result = 0; - if ( (act->flags & FLAG_PUSHABLE) && ( !(source->flags&FLAG_HERO) || (hero::getSkills()&SKILL_GLOVES) || (push == PUSH_ZN) ) ) act->push |= push; - if ( (act->flags & FLAG_REACTIVE) && (act->react_mask & push) ) + if ((act->flags & FLAG_PUSHABLE) && (!(source->flags & FLAG_HERO) || (hero::getSkills() & SKILL_GLOVES) || (push == PUSH_ZN))) + act->push |= push; + if ((act->flags & FLAG_REACTIVE) && (act->react_mask & push)) { if (act->flags & FLAG_DEADLY) source->push |= PUSH_KILL; else result = act->react_push; } - if ( (source->flags & FLAG_HERO) && (act->flags & FLAG_DISAPPEAR) ) + if ((source->flags & FLAG_HERO) && (act->flags & FLAG_DISAPPEAR)) { act = actor::replaceWithTemplate(act, "EXPLOSION"); - act->name[0]='_'; + act->name[0] = '_'; } - if (source->flags & FLAG_DEADLY) { + if (source->flags & FLAG_DEADLY) + { act->push |= PUSH_KILL; } - if (source->flags&FLAG_HERO) + if (source->flags & FLAG_HERO) { if (act->flags & FLAG_SPECIAL) { - if (act->name[0]=='B') { // Es un booster - hero::collectBooster(&act->name[5], (act->name[2]-48)*10+(act->name[3]-48)); - } else if (act->name[0]=='S') { // Es un skill + if (act->name[0] == 'B') + { // Es un booster + hero::collectBooster(&act->name[5], (act->name[2] - 48) * 10 + (act->name[3] - 48)); + } + else if (act->name[0] == 'S') + { // Es un skill hero::giveSkill(&act->name[2]); - } else if (act->name[0]=='P') { - if (hero::getSkills()&SKILL_BAG) { // Es una part + } + else if (act->name[0] == 'P') + { + if (hero::getSkills() & SKILL_BAG) + { // Es una part hero::pickPart(&act->name[2]); - } else { + } + else + { return result; } - } else { + } + else + { SDL_assert(false); } act = actor::replaceWithTemplate(act, "EXPLOSION"); - act->name[0]='_'; + act->name[0] = '_'; room::cycleColor(1); } } @@ -580,96 +682,113 @@ namespace actor vec3_t max = room::getMax(); bool moving = false; - if ( input::keyDown(SDL_SCANCODE_LEFT) || input::keyDown(config::getKey(KEY_LEFT)) ) + if (input::keyDown(SDL_SCANCODE_LEFT) || input::keyDown(config::getKey(KEY_LEFT))) { hero::useBoostRun(); - act->orient=PUSH_XN; - if ( (act->pos.x>min.x && act->pos.y>=min.y && (act->pos.y+act->size.y)<=max.y) || ( (room::getDoors()&DOOR_XN) && (act->pos.y>=24) && (act->pos.y<=32) ) ) + act->orient = PUSH_XN; + if ((act->pos.x > min.x && act->pos.y >= min.y && (act->pos.y + act->size.y) <= max.y) || ((room::getDoors() & DOOR_XN) && (act->pos.y >= 24) && (act->pos.y <= 32))) { moving = true; - if ( (act->pos.x<=min.x) && (act->pos.z==room::getDoor(XN)*4) && (room::getDoors()&DOOR_XN) ) { - if (act->pos.y<28) + if ((act->pos.x <= min.x) && (act->pos.z == room::getDoor(XN) * 4) && (room::getDoors() & DOOR_XN)) + { + if (act->pos.y < 28) act->push |= PUSH_YP; - else if (act->pos.y>28) + else if (act->pos.y > 28) act->push |= PUSH_YN; else act->push |= PUSH_XN; - } else + } + else act->push |= PUSH_XN; } } - else if ( input::keyDown(SDL_SCANCODE_RIGHT) || input::keyDown(config::getKey(KEY_RIGHT)) ) + else if (input::keyDown(SDL_SCANCODE_RIGHT) || input::keyDown(config::getKey(KEY_RIGHT))) { hero::useBoostRun(); - act->orient=PUSH_XP; - if ( ((act->pos.x+act->size.x)pos.y>=min.y && (act->pos.y+act->size.y)<=max.y) || ( (room::getDoors()&DOOR_XP) && (act->pos.y>=24) && (act->pos.y<=32) ) ) + act->orient = PUSH_XP; + if (((act->pos.x + act->size.x) < max.x && act->pos.y >= min.y && (act->pos.y + act->size.y) <= max.y) || ((room::getDoors() & DOOR_XP) && (act->pos.y >= 24) && (act->pos.y <= 32))) { moving = true; - if ( ((act->pos.x+act->size.x)>=max.x) && (act->pos.z==room::getDoor(XP)*4) && (room::getDoors()&DOOR_XP) ) { - if (act->pos.y<28) + if (((act->pos.x + act->size.x) >= max.x) && (act->pos.z == room::getDoor(XP) * 4) && (room::getDoors() & DOOR_XP)) + { + if (act->pos.y < 28) act->push |= PUSH_YP; - else if (act->pos.y>28) + else if (act->pos.y > 28) act->push |= PUSH_YN; else act->push |= PUSH_XP; - } else + } + else act->push |= PUSH_XP; } } - else if ( input::keyDown(SDL_SCANCODE_UP) || input::keyDown(config::getKey(KEY_UP)) ) + else if (input::keyDown(SDL_SCANCODE_UP) || input::keyDown(config::getKey(KEY_UP))) { hero::useBoostRun(); - act->orient=PUSH_YN; - if ( (act->pos.y>min.y && act->pos.x>=min.x && (act->pos.x+act->size.x)<=max.x) || ( (room::getDoors()&DOOR_YN) && (act->pos.x>=24) && (act->pos.x<=32) ) ) + act->orient = PUSH_YN; + if ((act->pos.y > min.y && act->pos.x >= min.x && (act->pos.x + act->size.x) <= max.x) || ((room::getDoors() & DOOR_YN) && (act->pos.x >= 24) && (act->pos.x <= 32))) { moving = true; - if ( (act->pos.y<=min.y) && (act->pos.z==room::getDoor(YN)*4) && (room::getDoors()&DOOR_YN) ) { - if (act->pos.x<28) + if ((act->pos.y <= min.y) && (act->pos.z == room::getDoor(YN) * 4) && (room::getDoors() & DOOR_YN)) + { + if (act->pos.x < 28) act->push |= PUSH_XP; - else if (act->pos.x>28) + else if (act->pos.x > 28) act->push |= PUSH_XN; else act->push |= PUSH_YN; - } else + } + else act->push |= PUSH_YN; } } - else if ( input::keyDown(SDL_SCANCODE_DOWN) || input::keyDown(config::getKey(KEY_DOWN)) ) + else if (input::keyDown(SDL_SCANCODE_DOWN) || input::keyDown(config::getKey(KEY_DOWN))) { hero::useBoostRun(); - act->orient=PUSH_YP; - if ( ((act->pos.y+act->size.y)pos.x>=min.x && (act->pos.x+act->size.x)<=max.x) || ( (room::getDoors()&DOOR_YP) && (act->pos.x>=24) && (act->pos.x<=32) ) ) + act->orient = PUSH_YP; + if (((act->pos.y + act->size.y) < max.y && act->pos.x >= min.x && (act->pos.x + act->size.x) <= max.x) || ((room::getDoors() & DOOR_YP) && (act->pos.x >= 24) && (act->pos.x <= 32))) { moving = true; - if ( ((act->pos.y+act->size.y)>=max.y) && (act->pos.z==room::getDoor(YP)*4) && (room::getDoors()&DOOR_YP) ) { - if (act->pos.x<28) + if (((act->pos.y + act->size.y) >= max.y) && (act->pos.z == room::getDoor(YP) * 4) && (room::getDoors() & DOOR_YP)) + { + if (act->pos.x < 28) act->push |= PUSH_XP; - else if (act->pos.x>28) + else if (act->pos.x > 28) act->push |= PUSH_XN; else act->push |= PUSH_YP; - } else + } + else act->push |= PUSH_YP; } } - if ((input::keyPressed(SDL_SCANCODE_RETURN) || input::keyPressed(config::getKey(KEY_PICK)) ) && (hero::getSkills()&SKILL_PANTS)) + if ((input::keyPressed(SDL_SCANCODE_RETURN) || input::keyPressed(config::getKey(KEY_PICK))) && (hero::getSkills() & SKILL_PANTS)) { if (picked) { - picked->pos.x = act->pos.x; if (picked->pos.x + picked->size.x > room::getMax().x) picked->pos.x = room::getMax().x - picked->size.x; - picked->pos.y = act->pos.y; if (picked->pos.y + picked->size.y > room::getMax().y) picked->pos.y = room::getMax().y - picked->size.y; + picked->pos.x = act->pos.x; + if (picked->pos.x + picked->size.x > room::getMax().x) + picked->pos.x = room::getMax().x - picked->size.x; + picked->pos.y = act->pos.y; + if (picked->pos.y + picked->size.y > room::getMax().y) + picked->pos.y = room::getMax().y - picked->size.y; picked->pos.z = act->pos.z; if (does_collide(picked)) { - picked->pos.x-=2; + picked->pos.x -= 2; if (does_collide(picked)) { - picked->pos.x+=2; picked->pos.y-=2; + picked->pos.x += 2; + picked->pos.y -= 2; } } act->pos.z += picked->size.z; actor::actor_t *above = act->above; - while (above) { above->pos.z += picked->size.z; above = above->above; } + while (above) + { + above->pos.z += picked->size.z; + above = above->above; + } if (act->below) { act->below->above = picked; @@ -681,24 +800,25 @@ namespace actor actor::setDirty(picked, true); picked = nullptr; } - else if (act->below && act->below->flags&FLAG_PICKABLE) + else if (act->below && act->below->flags & FLAG_PICKABLE) { - //const int height = act->below->size.z; + // const int height = act->below->size.z; pick(act->below); - //if (!(( input::keyDown(SDL_SCANCODE_SPACE) || input::keyDown(config::getKey(KEY_JUMP)) ) && (hero::getSkills()&SKILL_SHOES) && (act->pos.y+act->size.y)<=max.y && act->pos.y>=min.y && (act->pos.x+act->size.x)<=max.x && act->pos.x>=min.x && act->react_mask==0 && (act->pos.z==0 || act->below))) - // act->pos.z -= height; + // if (!(( input::keyDown(SDL_SCANCODE_SPACE) || input::keyDown(config::getKey(KEY_JUMP)) ) && (hero::getSkills()&SKILL_SHOES) && (act->pos.y+act->size.y)<=max.y && act->pos.y>=min.y && (act->pos.x+act->size.x)<=max.x && act->pos.x>=min.x && act->react_mask==0 && (act->pos.z==0 || act->below))) + // act->pos.z -= height; } } actor::actor_t *future_below = any_below_me(act); - if (( input::keyDown(SDL_SCANCODE_SPACE) || input::keyDown(config::getKey(KEY_JUMP)) ) && (hero::getSkills()&SKILL_SHOES) && (act->pos.y+act->size.y)<=max.y && act->pos.y>=min.y && (act->pos.x+act->size.x)<=max.x && act->pos.x>=min.x && act->react_mask==0 && ((act->pos.z==0 && room::getFloor()!=11) || (act->below || future_below))) + if ((input::keyDown(SDL_SCANCODE_SPACE) || input::keyDown(config::getKey(KEY_JUMP))) && (hero::getSkills() & SKILL_SHOES) && (act->pos.y + act->size.y) <= max.y && act->pos.y >= min.y && (act->pos.x + act->size.x) <= max.x && act->pos.x >= min.x && act->react_mask == 0 && ((act->pos.z == 0 && room::getFloor() != 11) || (act->below || future_below))) { // [RZC 01/10/2024] Hack per a que al aterrar sobre els que desapareixen puga botar sobre ells, i a més ells desapareguen - if (!act->below && future_below && future_below->flags&FLAG_DISAPPEAR) actor::push(act, future_below, PUSH_ZN); - + if (!act->below && future_below && future_below->flags & FLAG_DISAPPEAR) + actor::push(act, future_below, PUSH_ZN); + // [RZC 14/05/2024] hack usant react_mask i react_push del heroi. Llegir més avall. - act->react_mask=hero::getBoostJump()>0 ? 2 : 1; // =1 estic botant (anant cap amunt) - act->react_push=8; // es el comptador de botant, seguirà pujant mentres siga > 0 - //act->react_push=hero::getBoostJump()>0?16:8; // es el comptador de botant, seguirà pujant mentres siga > 0 + act->react_mask = hero::getBoostJump() > 0 ? 2 : 1; // =1 estic botant (anant cap amunt) + act->react_push = 8; // es el comptador de botant, seguirà pujant mentres siga > 0 + // act->react_push=hero::getBoostJump()>0?16:8; // es el comptador de botant, seguirà pujant mentres siga > 0 act->flags &= uint8_t(~FLAG_GRAVITY); if (act->below) { @@ -707,8 +827,8 @@ namespace actor } hero::useBoostJump(); } - //if (input::keyDown(SDL_SCANCODE_Z) && act->pos.z>0) { act->push |= PUSH_ZN; moving = true; } - //if (input::keyDown(SDL_SCANCODE_A) && act->pos.zpush |= PUSH_ZP; moving = true; } + // if (input::keyDown(SDL_SCANCODE_Z) && act->pos.z>0) { act->push |= PUSH_ZN; moving = true; } + // if (input::keyDown(SDL_SCANCODE_A) && act->pos.zpush |= PUSH_ZP; moving = true; } // [RZC 14/05/2024] Açò es un hack. estic usant react_mask i react_push del hero com a guarda // i contador per al bot. Supose que perque se suposa que el heroi no te raons @@ -717,18 +837,20 @@ namespace actor if (act->react_mask) { // Si topetem en una vora de l'habitació, s'acabat el bot - if ((act->pos.x+act->size.x)>max.x || act->pos.xpos.y+act->size.y)>max.y || act->pos.yreact_push=0; - + if ((act->pos.x + act->size.x) > max.x || act->pos.x < min.x || (act->pos.y + act->size.y) > max.y || act->pos.y < min.y) + act->react_push = 0; + // Si encara està botant (react_push > 0)... - if (act->react_push>0) + if (act->react_push > 0) { const int vel = act->react_mask; - if (!actor::any_above_me(act)) act->pos.z+=vel; // seguim pujant - act->react_push--; // augmentem el comptador de bot + if (!actor::any_above_me(act)) + act->pos.z += vel; // seguim pujant + act->react_push--; // augmentem el comptador de bot } else // Si ja ha acabat de botar... { - act->react_mask=0; // desactivem la guarda (react_mask=0) + act->react_mask = 0; // desactivem la guarda (react_mask=0) act->flags |= FLAG_GRAVITY; // i reactivem el flag de gravetat } } @@ -737,88 +859,142 @@ namespace actor if (moving) { act->flags |= FLAG_ANIMATED; + //if (audio::getChannelState(walk_channel) == audio::CHANNEL_PAUSED) audio::resumeChannel(walk_channel); + if (act->anim_frame==0) walk_channel = audio::playSound(walk, 0); } else { act->flags &= uint8_t(~FLAG_ANIMATED); + //if (audio::getChannelState(walk_channel) == audio::CHANNEL_PLAYING) audio::pauseChannel(walk_channel); } } void updateMoving(actor_t *act) { - if (act->flags&FLAG_MOVING && act->mov_push==0) act->mov_push = act->orient; // Per a activar-lo si no ho està + if (act->flags & FLAG_MOVING && act->mov_push == 0) + act->mov_push = act->orient; // Per a activar-lo si no ho està act->push |= act->mov_push; } void changeMoving(actor_t *act) { - switch(act->movement) + switch (act->movement) { - case MOV_X: - act->mov_push = act->mov_push==PUSH_XP ? PUSH_XN : PUSH_XP; + case MOV_X: + act->mov_push = act->mov_push == PUSH_XP ? PUSH_XN : PUSH_XP; + break; + case MOV_Y: + act->mov_push = act->mov_push == PUSH_YP ? PUSH_YN : PUSH_YP; + break; + case MOV_Z: + act->mov_push = act->mov_push == PUSH_ZN ? PUSH_ZP : PUSH_ZN; + break; + case MOV_CW: + switch (act->mov_push) + { + case PUSH_XP: + act->mov_push = PUSH_YN; break; - case MOV_Y: - act->mov_push = act->mov_push==PUSH_YP ? PUSH_YN : PUSH_YP; + case PUSH_YN: + act->mov_push = PUSH_XN; break; - case MOV_Z: - act->mov_push = act->mov_push==PUSH_ZN ? PUSH_ZP : PUSH_ZN; + case PUSH_XN: + act->mov_push = PUSH_YP; break; - case MOV_CW: - switch (act->mov_push) - { - case PUSH_XP: act->mov_push=PUSH_YN; break; - case PUSH_YN: act->mov_push=PUSH_XN; break; - case PUSH_XN: act->mov_push=PUSH_YP; break; - case PUSH_YP: act->mov_push=PUSH_XP; break; - } + case PUSH_YP: + act->mov_push = PUSH_XP; break; - case MOV_CCW: - switch (act->mov_push) - { - case PUSH_XP: act->mov_push=PUSH_YP; break; - case PUSH_YP: act->mov_push=PUSH_XN; break; - case PUSH_XN: act->mov_push=PUSH_YN; break; - case PUSH_YN: act->mov_push=PUSH_XP; break; - } + } + break; + case MOV_CCW: + switch (act->mov_push) + { + case PUSH_XP: + act->mov_push = PUSH_YP; break; - case MOV_RAND: - act->react_push = (rand()%32)+8; // [RZC 26/09/2024] Hack usant react_push en el moviment RAND per a contar la distancia abans de canviar de direcció - switch (rand()%4) - { - case 0: act->mov_push=PUSH_YP; break; - case 1: act->mov_push=PUSH_XN; break; - case 2: act->mov_push=PUSH_YN; break; - case 3: act->mov_push=PUSH_XP; break; - } + case PUSH_YP: + act->mov_push = PUSH_XN; break; - case MOV_RANDV: - case MOV_RANDJ: - switch (rand()%8) - { - case 0: act->mov_push=PUSH_YP; break; - case 1: act->mov_push=PUSH_XN; break; - case 2: act->mov_push=PUSH_YN; break; - case 3: act->mov_push=PUSH_XP; break; - case 4: act->mov_push=PUSH_YP; act->mov_push|=PUSH_XN; break; - case 5: act->mov_push=PUSH_XN; act->mov_push|=PUSH_YN; break; - case 6: act->mov_push=PUSH_YN; act->mov_push|=PUSH_XP; break; - case 7: act->mov_push=PUSH_XP; act->mov_push|=PUSH_YP; break; - } + case PUSH_XN: + act->mov_push = PUSH_YN; break; - case MOV_HUNT: - actor_t *heroi = find("HERO"); - if (heroi) - { - int tombola[2]; int tombola_pos = 0; - if (heroi->pos.x < act->pos.x) tombola[tombola_pos++]=PUSH_XN; - if (heroi->pos.x > act->pos.x) tombola[tombola_pos++]=PUSH_XP; - if (heroi->pos.y < act->pos.y) tombola[tombola_pos++]=PUSH_YN; - if (heroi->pos.y > act->pos.y) tombola[tombola_pos++]=PUSH_YP; - act->mov_push=tombola[rand()%tombola_pos]; - } + case PUSH_YN: + act->mov_push = PUSH_XP; break; + } + break; + case MOV_RAND: + act->react_push = (rand() % 32) + 8; // [RZC 26/09/2024] Hack usant react_push en el moviment RAND per a contar la distancia abans de canviar de direcció + switch (rand() % 4) + { + case 0: + act->mov_push = PUSH_YP; + break; + case 1: + act->mov_push = PUSH_XN; + break; + case 2: + act->mov_push = PUSH_YN; + break; + case 3: + act->mov_push = PUSH_XP; + break; + } + break; + case MOV_RANDV: + case MOV_RANDJ: + switch (rand() % 8) + { + case 0: + act->mov_push = PUSH_YP; + break; + case 1: + act->mov_push = PUSH_XN; + break; + case 2: + act->mov_push = PUSH_YN; + break; + case 3: + act->mov_push = PUSH_XP; + break; + case 4: + act->mov_push = PUSH_YP; + act->mov_push |= PUSH_XN; + break; + case 5: + act->mov_push = PUSH_XN; + act->mov_push |= PUSH_YN; + break; + case 6: + act->mov_push = PUSH_YN; + act->mov_push |= PUSH_XP; + break; + case 7: + act->mov_push = PUSH_XP; + act->mov_push |= PUSH_YP; + break; + } + break; + case MOV_HUNT: + actor_t *heroi = find("HERO"); + if (heroi) + { + int tombola[2]; + int tombola_pos = 0; + if (heroi->pos.x < act->pos.x) + tombola[tombola_pos++] = PUSH_XN; + if (heroi->pos.x > act->pos.x) + tombola[tombola_pos++] = PUSH_XP; + if (heroi->pos.y < act->pos.y) + tombola[tombola_pos++] = PUSH_YN; + if (heroi->pos.y > act->pos.y) + tombola[tombola_pos++] = PUSH_YP; + act->mov_push = tombola[rand() % tombola_pos]; + } + break; } - if (act->flags & FLAG_ORIENTABLE) act->orient = act->mov_push; + if (act->flags & FLAG_ORIENTABLE) + act->orient = act->mov_push; } void updatePush(actor_t *act) @@ -826,10 +1002,11 @@ namespace actor vec3_t min = room::getMin(); vec3_t max = room::getMax(); - if ( (act->push & PUSH_KILL) && (act->flags & FLAG_HERO) ) { + if ((act->push & PUSH_KILL) && (act->flags & FLAG_HERO)) + { if (!editor::isDevMode()) { - const int lives = hero::getLives()-1; + const int lives = hero::getLives() - 1; hero::setLives(lives); stats::loseLive(); } @@ -837,7 +1014,9 @@ namespace actor actor_t *act = actor::find("HERO"); act = actor::replaceWithTemplate(act, "EXPLOSION"); actor_t *act2 = actor::createFromTemplate("EXPLOSION"); - act2->pos = act->pos; act2->pos.z += 8; act2->anim_frame=2; + act2->pos = act->pos; + act2->pos.z += 8; + act2->anim_frame = 2; act->anim_wait = act2->anim_wait = 1; actor::setDirty(act2); room::cycleColor(4); @@ -845,29 +1024,33 @@ namespace actor } // [RZC 26/09/2024] Hack usant react_push en el moviment RAND per a contar la distancia abans de canviar de direcció - if (act->movement==MOV_RAND) + if (act->movement == MOV_RAND) { act->react_push--; - if (act->react_push==0) changeMoving(act); + if (act->react_push == 0) + changeMoving(act); } - // [RZC 26/09/2024] Hack usant react_push en les bambolles de café per al dz del moviment de anar pegant botets - if (act->movement==MOV_RANDJ) + if (act->movement == MOV_RANDJ) { - if (act->pos.z==0) act->react_push=1; - if (act->pos.z>=6) act->react_push=-1; + if (act->pos.z == 0) + act->react_push = 1; + if (act->pos.z >= 6) + act->react_push = -1; act->pos.z += act->react_push; } - int vel = (act->flags&FLAG_HERO) && (hero::getBoostRun()>0) ? 2 : 1; + int vel = (act->flags & FLAG_HERO) && (hero::getBoostRun() > 0) ? 2 : 1; - if (act->push & PUSH_ZP) { - if (act->pos.z>=max.z) + if (act->push & PUSH_ZP) + { + if (act->pos.z >= max.z) { - if (act->flags & FLAG_MOVING) changeMoving(act); + if (act->flags & FLAG_MOVING) + changeMoving(act); - if ( ((act->flags&FLAG_HERO)!=0) && (room::getExit(ZP)!=-1) ) + if (((act->flags & FLAG_HERO) != 0) && (room::getExit(ZP) != -1)) { room::load(room::getExit(ZP)); act->pos.z = 4; @@ -885,10 +1068,12 @@ namespace actor // avall. De totes formes [TODO] revisar. // Estem tenint en compte els MOVILS, pero no els REACT actor_t *now = act; - do { + do + { actor::actor_t *other = actor::any_above_me(now); - if (!other || (other->flags & FLAG_PUSHABLE)) now->pos.z++; - if ( (now->pos.z>=max.z) && (now->flags&FLAG_HERO)!=0 && (room::getExit(ZP)!=-1) ) + if (!other || (other->flags & FLAG_PUSHABLE)) + now->pos.z++; + if ((now->pos.z >= max.z) && (now->flags & FLAG_HERO) != 0 && (room::getExit(ZP) != -1)) { room::load(room::getExit(ZP)); now->pos.z = 4; @@ -898,148 +1083,182 @@ namespace actor return; } now = other; - if (now && !(now->flags & FLAG_PUSHABLE)) { - if (act->flags & FLAG_MOVING) changeMoving(act); + if (now && !(now->flags & FLAG_PUSHABLE)) + { + if (act->flags & FLAG_MOVING) + changeMoving(act); now = nullptr; } } while (now); - + actor::setDirty(act); } act->push &= ~PUSH_ZP; } - if (act->push & PUSH_XN) { - act->pos.x-=vel; + if (act->push & PUSH_XN) + { + act->pos.x -= vel; actor::actor_t *other = actor::get_collision(act); - if (other || ( act->pos.xpos.y!=28) || (act->pos.z!=room::getDoor(XN)*4) || !(act->flags&FLAG_HERO) ) )) + if (other || (act->pos.x < min.x && (!(room::getDoors() & DOOR_XN) || (act->pos.y != 28) || (act->pos.z != room::getDoor(XN) * 4) || !(act->flags & FLAG_HERO)))) { - if (other) other->push |= push(act, other, PUSH_XN); - act->pos.x+=vel; - if (act->flags & FLAG_MOVING) changeMoving(act); - if (act->flags & FLAG_INERTIA) act->push = PUSH_NONE; + if (other) + other->push |= push(act, other, PUSH_XN); + act->pos.x += vel; + if (act->flags & FLAG_MOVING) + changeMoving(act); + if (act->flags & FLAG_INERTIA) + act->push = PUSH_NONE; } else { // Si tenim a algú damunt, el movem també - if (act->above && act->above->flags & FLAG_PUSHABLE) { + if (act->above && act->above->flags & FLAG_PUSHABLE) + { push(act, act->above, PUSH_XN); } // Si ja havem atravesat la porta, ens movem a la porta de l'altra costat - if (act->pos.xpos.x < min.x - 4) + { room::load(room::getExit(XN)); - act->pos.x = room::getMax().x-4; - act->pos.z = room::getDoor(XP)*4; + act->pos.x = room::getMax().x - 4; + act->pos.z = room::getDoor(XP) * 4; hero::setFirstPos(); room_changed = true; } actor::setDirty(act); } - if ( !(act->flags & FLAG_INERTIA) ) act->push &= ~PUSH_XN; + if (!(act->flags & FLAG_INERTIA)) + act->push &= ~PUSH_XN; } - if (act->push & PUSH_XP) { - act->pos.x+=vel; + if (act->push & PUSH_XP) + { + act->pos.x += vel; actor::actor_t *other = actor::get_collision(act); - if (other || ((act->pos.x+act->size.x)>max.x && ( !(room::getDoors()&DOOR_XP) || (act->pos.y!=28) || !(act->flags&FLAG_HERO) ) )) + if (other || ((act->pos.x + act->size.x) > max.x && (!(room::getDoors() & DOOR_XP) || (act->pos.y != 28) || !(act->flags & FLAG_HERO)))) { - if (other) other->push |= push(act, other, PUSH_XP); - act->pos.x-=vel; - if (act->flags & FLAG_MOVING) changeMoving(act); - if (act->flags & FLAG_INERTIA) act->push = PUSH_NONE; + if (other) + other->push |= push(act, other, PUSH_XP); + act->pos.x -= vel; + if (act->flags & FLAG_MOVING) + changeMoving(act); + if (act->flags & FLAG_INERTIA) + act->push = PUSH_NONE; } else { - if (act->above && act->above->flags & FLAG_PUSHABLE) { + if (act->above && act->above->flags & FLAG_PUSHABLE) + { push(act, act->above, PUSH_XP); } - if ((act->pos.x+act->size.x)>max.x+4) { - const bool llevar_abad = room::getCurrent()==63 && room::getExit(XP)==62; + if ((act->pos.x + act->size.x) > max.x + 4) + { + const bool llevar_abad = room::getCurrent() == 63 && room::getExit(XP) == 62; room::load(room::getExit(XP)); if (llevar_abad) { actor::remove(actor::find("ABAD")); } - act->pos.x = room::getMin().x-3; - act->pos.z = room::getDoor(XN)*4; + act->pos.x = room::getMin().x - 3; + act->pos.z = room::getDoor(XN) * 4; hero::setFirstPos(); room_changed = true; } actor::setDirty(act); } - if ( !(act->flags & FLAG_INERTIA) ) act->push &= ~PUSH_XP; + if (!(act->flags & FLAG_INERTIA)) + act->push &= ~PUSH_XP; } - if (act->push & PUSH_YN) { - act->pos.y-=vel; + if (act->push & PUSH_YN) + { + act->pos.y -= vel; actor::actor_t *other = actor::get_collision(act); - if (other || ( act->pos.ypos.x!=28) || (act->pos.z!=room::getDoor(YN)*4) || !(act->flags&FLAG_HERO) ) )) + if (other || (act->pos.y < min.y && (!(room::getDoors() & DOOR_YN) || (act->pos.x != 28) || (act->pos.z != room::getDoor(YN) * 4) || !(act->flags & FLAG_HERO)))) { - if (other) other->push |= push(act, other, PUSH_YN); - act->pos.y+=vel; - if (act->flags & FLAG_MOVING) changeMoving(act); - if (act->flags & FLAG_INERTIA) act->push = PUSH_NONE; + if (other) + other->push |= push(act, other, PUSH_YN); + act->pos.y += vel; + if (act->flags & FLAG_MOVING) + changeMoving(act); + if (act->flags & FLAG_INERTIA) + act->push = PUSH_NONE; } else { - if (act->above && act->above->flags & FLAG_PUSHABLE) { + if (act->above && act->above->flags & FLAG_PUSHABLE) + { push(act, act->above, PUSH_YN); } - if (act->pos.ypos.y < min.y - 4) + { room::load(room::getExit(YN)); - act->pos.y = room::getMax().y-4; - act->pos.z = room::getDoor(YP)*4; + act->pos.y = room::getMax().y - 4; + act->pos.z = room::getDoor(YP) * 4; hero::setFirstPos(); room_changed = true; } actor::setDirty(act); } - if ( !(act->flags & FLAG_INERTIA) ) act->push &= ~PUSH_YN; + if (!(act->flags & FLAG_INERTIA)) + act->push &= ~PUSH_YN; } - if (act->push & PUSH_YP) { - act->pos.y+=vel; + if (act->push & PUSH_YP) + { + act->pos.y += vel; actor::actor_t *other = actor::get_collision(act); - if (other || ( (act->pos.y+act->size.y)>max.y && ( !(room::getDoors()&DOOR_YP) || (act->pos.x!=28) || !(act->flags&FLAG_HERO) ) )) + if (other || ((act->pos.y + act->size.y) > max.y && (!(room::getDoors() & DOOR_YP) || (act->pos.x != 28) || !(act->flags & FLAG_HERO)))) { - if (other) other->push |= push(act, other, PUSH_YP); - act->pos.y-=vel; - if (act->flags & FLAG_MOVING) changeMoving(act); - if (act->flags & FLAG_INERTIA) act->push = PUSH_NONE; + if (other) + other->push |= push(act, other, PUSH_YP); + act->pos.y -= vel; + if (act->flags & FLAG_MOVING) + changeMoving(act); + if (act->flags & FLAG_INERTIA) + act->push = PUSH_NONE; } else { - if (act->above && act->above->flags & FLAG_PUSHABLE) { + if (act->above && act->above->flags & FLAG_PUSHABLE) + { push(act, act->above, PUSH_YP); } - if ((act->pos.y+act->size.y)>max.y+4) { + if ((act->pos.y + act->size.y) > max.y + 4) + { room::load(room::getExit(YP)); - act->pos.y = room::getMin().y-3; - act->pos.z = room::getDoor(YN)*4; + act->pos.y = room::getMin().y - 3; + act->pos.z = room::getDoor(YN) * 4; hero::setFirstPos(); room_changed = true; } actor::setDirty(act); } - if ( !(act->flags & FLAG_INERTIA) ) act->push &= ~PUSH_YP; + if (!(act->flags & FLAG_INERTIA)) + act->push &= ~PUSH_YP; } - if (act->push & PUSH_ZN) { + if (act->push & PUSH_ZN) + { // Si estic sobre el piso, no faig res if (act->pos.z == 0) { - if ( (act->flags & FLAG_MOVING) && (act->movement==MOV_Z) ) changeMoving(act); + if ((act->flags & FLAG_MOVING) && (act->movement == MOV_Z)) + changeMoving(act); act->push &= ~PUSH_ZN; - if ( (act->flags&FLAG_HERO) && (room::getFloor()==11) ) act->push |= PUSH_KILL; - if ( ((act->flags&FLAG_HERO)==0) || (room::getExit(ZN)==-1) ) return; + if ((act->flags & FLAG_HERO) && (room::getFloor() == 11)) + act->push |= PUSH_KILL; + if (((act->flags & FLAG_HERO) == 0) || (room::getExit(ZN) == -1)) + return; room::load(room::getExit(ZN)); act->pos.z = room::getMax().z; @@ -1053,11 +1272,13 @@ namespace actor if (act->below) { // ...i encara està baix... - if (is_above(act, act->below)) { + if (is_above(act, act->below)) + { // ...li pase a ell el push, neteje el meu flag, canvie direcció si pertoca i me ane act->push |= push(act, act->below, PUSH_ZN); // [RZC 20/09/2024] Canvie "act->below->push" per "act->push". Se li deu passar la reacció al que la inicia act->push &= ~PUSH_ZN; - if ( (act->flags & FLAG_MOVING) && (act->movement==MOV_Z) ) changeMoving(act); + if ((act->flags & FLAG_MOVING) && (act->movement == MOV_Z)) + changeMoving(act); return; } // ... pero si ja no està baix, el desasociem, i seguim el proces @@ -1077,12 +1298,14 @@ namespace actor // ... i li passem el push, netejem el meu flag i gonnem act->push |= push(act, act->below, PUSH_ZN); // [RZC 20/09/2024] Canvie "act->below->push" per "act->push". Se li deu passar la reacció al que la inicia act->push &= ~PUSH_ZN; - if ( (act->flags & FLAG_MOVING) && (act->movement==MOV_Z) ) changeMoving(act); + if ((act->flags & FLAG_MOVING) && (act->movement == MOV_Z)) + changeMoving(act); return; } // Si estem dins d'una porta, no caiguem. [TODO] Revisar - if (act->flags&FLAG_HERO && ((act->pos.x+act->size.x)>max.x || act->pos.xpos.y+act->size.y)>max.y || act->pos.yflags & FLAG_HERO && ((act->pos.x + act->size.x) > max.x || act->pos.x < min.x || (act->pos.y + act->size.y) > max.y || act->pos.y < min.y)) + return; // Si arribem fins ací, podem moure la posició act->push &= ~PUSH_ZN; @@ -1090,104 +1313,134 @@ namespace actor actor::setDirty(act); } -/* - if (act->push & PUSH_ZN) { - act->pos.z--; - actor::actor_t *other = actor::get_collision(act); - if (other || act->pos.z<0 || act->pos.x>max.x || act->pos.xpos.y>max.y || act->pos.yflags & FLAG_REACTIVE) other->push |= PUSH_ZN; - act->pos.z++; - if (act->flags & FLAG_MOVING) changeMoving(act); - } - else - { - actor::setDirty(act); - } - } -*/ + /* + if (act->push & PUSH_ZN) { + act->pos.z--; + actor::actor_t *other = actor::get_collision(act); + if (other || act->pos.z<0 || act->pos.x>max.x || act->pos.xpos.y>max.y || act->pos.yflags & FLAG_REACTIVE) other->push |= PUSH_ZN; + act->pos.z++; + if (act->flags & FLAG_MOVING) changeMoving(act); + } + else + { + actor::setDirty(act); + } + } + */ } void update(actor_t *act, const bool update_all) { - if (!act) return; + if (!act) + return; - if (act==first) { brilli_brilli=(brilli_brilli+1)&0x7; } + if (act == first) + { + brilli_brilli = (brilli_brilli + 1) & 0x7; + } actor_t *next = act->next; // Actualitzem el frame de l'animació (si no te el flag de animat, no afectarà per a res) - if (act->anim_wait_count==act->anim_wait) { - act->anim_frame=act->anim_frame+1; - if (act->anim_frame==4) { - if (act->name[0]=='_') { + if (act->anim_wait_count == act->anim_wait) + { + act->anim_frame = act->anim_frame + 1; + if (act->anim_frame == 4) + { + if (act->name[0] == '_') + { actor::remove(act); return; - } else { - act->anim_frame=0; + } + else + { + act->anim_frame = 0; } } - if (act->anim_cycle==2 && act->anim_frame==3) act->anim_frame=0; - act->anim_wait_count=0; - } else { + if (act->anim_cycle == 2 && act->anim_frame == 3) + act->anim_frame = 0; + act->anim_wait_count = 0; + } + else + { act->anim_wait_count++; } - if (act->flags & FLAG_HERO) updateUserInput(act); - if (act->flags & FLAG_MOVING) { - if (act->movement==MOV_HUNT && ( (act->pos.x&7)==0 || (act->pos.y&7)==0) ) changeMoving(act); + if (act->flags & FLAG_HERO) + updateUserInput(act); + if (act->flags & FLAG_MOVING) + { + if (act->movement == MOV_HUNT && ((act->pos.x & 7) == 0 || (act->pos.y & 7) == 0)) + changeMoving(act); updateMoving(act); } - if (act->flags & FLAG_GRAVITY) act->push |= PUSH_ZN; + if (act->flags & FLAG_GRAVITY) + act->push |= PUSH_ZN; - //if (act->flags & FLAG_PUSHABLE) + // if (act->flags & FLAG_PUSHABLE) updatePush(act); - //if (act->flags & FLAG_GRAVITY) updateGravity(act); - //if (act->flags & FLAG_REACTIVE) updateReactive(act); + // if (act->flags & FLAG_GRAVITY) updateGravity(act); + // if (act->flags & FLAG_REACTIVE) updateReactive(act); - //act->push = PUSH_NONE; + // act->push = PUSH_NONE; - if (!room_changed && update_all && next) update(next); + if (!room_changed && update_all && next) + update(next); room_changed = false; } void updateEditor(actor_t *act, const bool update_all) { - if (!act) return; + if (!act) + return; actor_t *next = act->next; - if (act->anim_wait_count==act->anim_wait) { - act->anim_frame=(act->anim_frame+1)%4; - if (act->anim_cycle==2 && act->anim_frame==3) act->anim_frame=0; - act->anim_wait_count=0; - } else { + if (act->anim_wait_count == act->anim_wait) + { + act->anim_frame = (act->anim_frame + 1) % 4; + if (act->anim_cycle == 2 && act->anim_frame == 3) + act->anim_frame = 0; + act->anim_wait_count = 0; + } + else + { act->anim_wait_count++; } - if (update_all && next) updateEditor(next); + if (update_all && next) + updateEditor(next); } void print(int x, int y, int num) { - int digits=0; + int digits = 0; bool sign = num < 0; num = SDL_abs(num); int n = num; - while (n>0) {n=n/10;digits++;} - if (sign) digits++; - x=x+digits*4; - if (num==0) draw::draw(x+4,y,5,7,0,120); - while (num>0) + while (n > 0) { - draw::draw(x,y,5,7,(num%10)*5,120); - num=num/10; - x=x-4; + n = n / 10; + digits++; } - if (sign) draw::draw(x,y,5,7,50,120); + if (sign) + digits++; + x = x + digits * 4; + if (num == 0) + draw::draw(x + 4, y, 5, 7, 0, 120); + while (num > 0) + { + draw::draw(x, y, 5, 7, (num % 10) * 5, 120); + num = num / 10; + x = x - 4; + } + if (sign) + draw::draw(x, y, 5, 7, 50, 120); } - void drawAt(actor_t * act, const int x, const int y) + void drawAt(actor_t *act, const int x, const int y) { act->inner_x = x; act->inner_y = y; @@ -1196,44 +1449,47 @@ namespace actor void draw(actor_t *act, const bool draw_all) { - if (!act) return; + if (!act) + return; - if (!editor::isEditing() || ( (act->flags&FLAG_HERO)==0)) + if (!editor::isEditing() || ((act->flags & FLAG_HERO) == 0)) { const int x = act->inner_x; // 148-act->bmp_offset.x + act->pos.x*2 - act->pos.y*2; const int y = act->inner_y; // 91-act->bmp_offset.y + act->pos.x + act->pos.y - act->pos.z*2; - const bool flip = ( (act->flags & FLAG_ORIENTABLE) && (act->orient==PUSH_XN || act->orient==PUSH_YP) ) ? DRAW_FLIP_HORIZONTAL : DRAW_FLIP_NONE; - const int oo = ( (act->flags & FLAG_ORIENTABLE) && (act->orient==PUSH_XN || act->orient==PUSH_YN) ) ? act->bmp_rect.h : 0; + const bool flip = ((act->flags & FLAG_ORIENTABLE) && (act->orient == PUSH_XN || act->orient == PUSH_YP)) ? DRAW_FLIP_HORIZONTAL : DRAW_FLIP_NONE; + const int oo = ((act->flags & FLAG_ORIENTABLE) && (act->orient == PUSH_XN || act->orient == PUSH_YN)) ? act->bmp_rect.h : 0; - const int ao = (act->flags & FLAG_ANIMATED) ? anims[act->anim_cycle][act->anim_frame]*act->bmp_rect.w : 0; + const int ao = (act->flags & FLAG_ANIMATED) ? anims[act->anim_cycle][act->anim_frame] * act->bmp_rect.w : 0; draw::pushSource(); draw::setSource(act->surface); - if (editor::isEditing() && (act==selected) && modules::game::getSection()==modules::game::SECTION_ACTOR) draw::swapcol(1, room::getColor(1)); // Si està seleccionat, que canvie de color + if (editor::isEditing() && (act == selected) && modules::game::getSection() == modules::game::SECTION_ACTOR) + draw::swapcol(1, room::getColor(1)); // Si està seleccionat, que canvie de color draw::stencil::set(act->tag); - draw::draw(x, y, act->bmp_rect.w, act->bmp_rect.h, act->bmp_rect.x+ao, act->bmp_rect.y+oo, flip); + draw::draw(x, y, act->bmp_rect.w, act->bmp_rect.h, act->bmp_rect.x + ao, act->bmp_rect.y + oo, flip); draw::swapcol(1, room::getColor(0)); // Tornem al color per defecte - if (act->flags&FLAG_SPECIAL) + if (act->flags & FLAG_SPECIAL) { draw::setSource(brilli); - const int dx = (act->bmp_rect.w-22)>>1; - draw::draw(x+dx, y, 22, 24, brilli_brilli*22, 96, DRAW_FLIP_NONE); + const int dx = (act->bmp_rect.w - 22) >> 1; + draw::draw(x + dx, y, 22, 24, brilli_brilli * 22, 96, DRAW_FLIP_NONE); } draw::popSource(); if (debug::isEnabled(DEBUG_ACTOR_POS)) { char tmp[100]; - draw::print(SDL_itoa(act->inner_x, tmp, 10), x+9,y+20, LIGHT+WHITE, BLACK); - draw::print(SDL_itoa(act->inner_y, tmp, 10), x+9,y+26, LIGHT+WHITE, BLACK); + draw::print(SDL_itoa(act->inner_x, tmp, 10), x + 9, y + 20, LIGHT + WHITE, BLACK); + draw::print(SDL_itoa(act->inner_y, tmp, 10), x + 9, y + 26, LIGHT + WHITE, BLACK); draw::swapcol(1, room::getColor(0)); // Tornem al color per defecte } - } - if (draw_all && act->next) draw(act->next); + } + if (draw_all && act->next) + draw(act->next); } - actor_t *find(std::string name) + actor_t *find(std::string name) { actor_t *act = first; while (act) @@ -1266,7 +1522,7 @@ namespace actor actor_t *act = first; while (act) { - if (act->pos.x==x && act->pos.y==y && act->pos.z==z) + if (act->pos.x == x && act->pos.y == y && act->pos.z == z) { return act; } @@ -1309,43 +1565,56 @@ namespace actor const bool check_collision(actor_t *obj1, actor_t *obj2) { - return (obj1->pos.x < obj2->pos.x + obj2->size.x) && - (obj1->pos.x + obj1->size.x > obj2->pos.x ) && - (obj1->pos.y < obj2->pos.y + obj2->size.y) && - (obj1->pos.y + obj1->size.y > obj2->pos.y ) && - (obj1->pos.z < obj2->pos.z + obj2->size.z) && - (obj1->pos.z + obj1->size.z > obj2->pos.z ); + return (obj1->pos.x < obj2->pos.x + obj2->size.x) && + (obj1->pos.x + obj1->size.x > obj2->pos.x) && + (obj1->pos.y < obj2->pos.y + obj2->size.y) && + (obj1->pos.y + obj1->size.y > obj2->pos.y) && + (obj1->pos.z < obj2->pos.z + obj2->size.z) && + (obj1->pos.z + obj1->size.z > obj2->pos.z); } void remove(actor_t *act) { - if (!act) return; - if (act->prev) act->prev->next = act->next; - if (act==first) first = act->next; - if (act==dirty) dirty = act->next; - if (act->next) act->next->prev = act->prev; - //draw::freeSurface(act->surface); - if (act==selected) selected = nullptr; - if (act->below) act->below->above = nullptr; - if (act->above) act->above->below = nullptr; + if (!act) + return; + if (act->prev) + act->prev->next = act->next; + if (act == first) + first = act->next; + if (act == dirty) + dirty = act->next; + if (act->next) + act->next->prev = act->prev; + // draw::freeSurface(act->surface); + if (act == selected) + selected = nullptr; + if (act->below) + act->below->above = nullptr; + if (act->above) + act->above->below = nullptr; free(act); } void pick(actor_t *act) { - if (!act) return; - if (act->prev) act->prev->next = act->next; - if (act==first) first = act->next; - if (act==dirty) dirty = act->next; - if (act->next) act->next->prev = act->prev; - if (act==selected) selected = nullptr; + if (!act) + return; + if (act->prev) + act->prev->next = act->next; + if (act == first) + first = act->next; + if (act == dirty) + dirty = act->next; + if (act->next) + act->next->prev = act->prev; + if (act == selected) + selected = nullptr; picked = act; - picked->pos.x=24; - picked->pos.y=80; - picked->pos.z=0; - picked->inner_x = 148-act->bmp_offset.x + act->pos.x*2 - act->pos.y*2; - picked->inner_y = 91-act->bmp_offset.y + act->pos.x + act->pos.y - act->pos.z*2; - + picked->pos.x = 24; + picked->pos.y = 80; + picked->pos.z = 0; + picked->inner_x = 148 - act->bmp_offset.x + act->pos.x * 2 - act->pos.y * 2; + picked->inner_y = 91 - act->bmp_offset.y + act->pos.x + act->pos.y - act->pos.z * 2; } actor_t *getPicked() { return picked; } @@ -1358,9 +1627,12 @@ namespace actor while (act) { actor_t *tmp = act->next; - if (!all && (act->flags & FLAG_HERO)) { + if (!all && (act->flags & FLAG_HERO)) + { hero = act; - } else { + } + else + { free(act); } act = tmp; @@ -1371,7 +1643,8 @@ namespace actor picked = nullptr; } first = dirty = nullptr; - if (hero) { + if (hero) + { hero->above = hero->below = hero->next = hero->prev = nullptr; first = hero; } @@ -1394,11 +1667,11 @@ namespace actor void load() { - //newCategory("default"); + // newCategory("default"); categories.clear(); templates.clear(); char filename[] = "templates.txt"; - int filesize=0; + int filesize = 0; char *buffer = file::getFileBuffer(filename, filesize, true); char *original_buffer = buffer; int current_category = 0; @@ -1407,12 +1680,13 @@ namespace actor { while (*buffer != 0) { - const char* key = file::readString(&buffer); + const char *key = file::readString(&buffer); if (util::strcomp(key, "category{")) { - const char* key = file::readString(&buffer); - if (util::strcomp(key, "name:")) { + const char *key = file::readString(&buffer); + if (util::strcomp(key, "name:")) + { const char *val = file::readString(&buffer); current_category = newCategory(val); } @@ -1424,10 +1698,10 @@ namespace actor templates.push_back(*t); free(t); } - else if (util::strcomp(key, "}")) { + else if (util::strcomp(key, "}")) + { current_category = 0; } - } free(original_buffer); } @@ -1444,7 +1718,7 @@ namespace actor fprintf(f, " name: %s\n", cat_name.c_str()); auto actors = getByCategory(cat_name.c_str()); - for (auto t : actors ) + for (auto t : actors) { saveToFile(f, &t, true); } @@ -1466,14 +1740,16 @@ namespace actor return templates.size(); }*/ - std::vector getByCategory(const char* category) + std::vector getByCategory(const char *category) { std::string catname = category; std::vector actors; for (auto act : templates) { - if (act.template_category>=categories.size()) act.template_category = 0; - if (categories[act.template_category]==catname) actors.push_back(act); + if (act.template_category >= categories.size()) + act.template_category = 0; + if (categories[act.template_category] == catname) + actors.push_back(act); } return actors; } @@ -1486,7 +1762,7 @@ namespace actor const int newCategory(const char *name) { categories.push_back(name); - return categories.size()-1; + return categories.size() - 1; } actor_t *get(const int index) @@ -1496,8 +1772,10 @@ namespace actor actor_t *getByName(const char *name) { - for (int i=0;iname); new_template.template_category = existing_template->template_category; // Li fiquem la categoria que tenia abans copy(existing_template, &new_template); - } else { + } + else + { // ... i sinó, afegim el actor seleccionat a la llista de plantilles new_template.template_category = 0; // Li fiquem la categoria per defecte templates.push_back(new_template); @@ -1546,31 +1826,35 @@ namespace actor void swapCategories(const int a, const int b) { - if (a >= categories.size() || a < 0) return; - if (b >= categories.size() || b < 0) return; + if (a >= categories.size() || a < 0) + return; + if (b >= categories.size() || b < 0) + return; auto str = categories[a]; categories[a] = categories[b]; categories[b] = str; for (auto &actor : templates) { - if (actor.template_category == a) actor.template_category = b; - else if (actor.template_category == b) actor.template_category = a; + if (actor.template_category == a) + actor.template_category = b; + else if (actor.template_category == b) + actor.template_category = a; } -/* - auto old_categories = categories; - categories.clear(); - std::string relocated = ""; - for (int i=0; iflags = FLAG_HERO | FLAG_PUSHABLE | FLAG_GRAVITY | FLAG_ORIENTABLE | FLAG_ANIMATED; actor::setDirty(hero, true); @@ -1602,9 +1886,16 @@ namespace actor lives = 8; skills = SKILL_NONE; parts = PART_NONE; - for (int i=0; i<100; ++i) boosters_collected[i] = false; + for (int i = 0; i < 100; ++i) + boosters_collected[i] = false; brilli = draw::getSurface("objectes.gif"); - } else { + + walk = audio::loadSound("walk.wav"); + //walk_channel = audio::playSound(walk, -1); + //audio::pauseChannel(walk_channel); + } + else + { hero->pos = first_pos; hero->orient = first_orient; } @@ -1633,11 +1924,11 @@ namespace actor const int getBoosterFromString(const char *booster) { static const char *boostset_name[4] = {"RUN", "GOD", "JUMP", "LIVE"}; - for (int i=0;i<4;++i) + for (int i = 0; i < 4; ++i) { - if (strcmp(booster, boostset_name[i])==0) + if (strcmp(booster, boostset_name[i]) == 0) { - return 1< 0) boost_god--; + if (boost_god > 0) + boost_god--; } void useBoostRun() { - if (boost_steps > 0) boost_steps--; + if (boost_steps > 0) + boost_steps--; } void useBoostJump() { - if (boost_jumps > 0) boost_jumps--; - + if (boost_jumps > 0) + boost_jumps--; } - const int getSkillFromString(char *skill) { static const char *skillset_name[4] = {"SHOES", "GLOVES", "PANTS", "BAG"}; - for (int i=0;i<4;++i) + for (int i = 0; i < 4; ++i) { - if (strcmp(skill, skillset_name[i])==0) + if (strcmp(skill, skillset_name[i]) == 0) { - return 1<pos.x = *x; - if (y) hero->pos.y = *y; - if (z) hero->pos.z = *z; + if (x) + hero->pos.x = *x; + if (y) + hero->pos.y = *y; + if (z) + hero->pos.z = *z; } void setFirstPos() @@ -1852,18 +2181,21 @@ namespace actor { partsCollected = livesLost = 0; catsLifeOdds = 5; - for (int i=0; i #include #include +#include "jfile.h" namespace audio { @@ -15,11 +16,14 @@ namespace audio { }; + char *music_buffer = nullptr; + // Inicialitza el sistema de só void init() { + int result = Mix_Init(MIX_INIT_OGG | MIX_INIT_WAVPACK); // Al final he ficat la configuració automàtica i au. Si en el futur necesitem canviar-ho pos se canvia - Mix_OpenAudio(48000, AUDIO_S16, 2, 1024); + result = Mix_OpenAudio(48000, AUDIO_S16, 2, 1024); } // Tanca el sistema de só (no shit, sherlock) @@ -31,11 +35,17 @@ namespace audio // Carrega un arxiu de música en format OGG const music *loadMusic(const std::string filename) { - return (music *)Mix_LoadMUS(filename.c_str()); + int size; + if (music_buffer) free(music_buffer); + music_buffer = file::getFileBuffer(filename, size); + auto rwops = SDL_RWFromMem(music_buffer, size); + auto mus = Mix_LoadMUS_RW(rwops, 1); + //free(buffer); + return (music *)mus; } // Comença a reproduïr la música en questió - void playMusic(music *mus, const int loop) + void playMusic(const music *mus, const int loop) { Mix_PlayMusic((Mix_Music *)mus, loop); } @@ -82,9 +92,11 @@ namespace audio } // Carrega un só des d'un arxiu WAV - const sound *loadSound(const std::string filename) + sound *loadSound(const std::string filename) { - return (sound *)Mix_LoadWAV(filename.c_str()); + int size; + char *buffer = file::getFileBuffer(filename, size); + return (sound *)Mix_LoadWAV_RW(SDL_RWFromMem(buffer, size), 1); } // Comença a reproduïr el só especificat diff --git a/source/jaudio.h b/source/jaudio.h index 388e220..d69e205 100644 --- a/source/jaudio.h +++ b/source/jaudio.h @@ -39,7 +39,7 @@ namespace audio /// @brief Comença a reproduïr la música en questió /// @param mus punter a la música /// @param loop quants bucles farà (-1=infinit, 0=no repeteix, 1=repeteix 1 vegada...) - void playMusic(music *mus, const int loop = -1); + void playMusic(const music *mus, const int loop = -1); /// @brief Pausa la música que està sonant ara void pauseMusic(); @@ -61,7 +61,7 @@ namespace audio /// @brief Carrega un só des d'un arxiu WAV /// @param filename nom de l'arxiu /// @return un punter al só - const sound *loadSound(const std::string filename); + sound *loadSound(const std::string filename); /// @brief Comença a reproduïr el só especificat /// @param snd punter al só a reproduïr diff --git a/source/jgame.cpp b/source/jgame.cpp index 58f7c15..5b9aa6f 100644 --- a/source/jgame.cpp +++ b/source/jgame.cpp @@ -1,6 +1,7 @@ #include "jgame.h" #include "jdraw.h" #include "jinput.h" +#include "jaudio.h" #include namespace game @@ -35,6 +36,7 @@ int main(int argc, char *argv[]) game::init(); input::init(); + audio::init(); static unsigned int current_ticks = SDL_GetTicks(); diff --git a/source/m_game.cpp b/source/m_game.cpp index 2b86743..6ffa23d 100644 --- a/source/m_game.cpp +++ b/source/m_game.cpp @@ -7,6 +7,7 @@ #include "console.h" #include "editor.h" #include "jutil.h" +#include "jaudio.h" namespace modules { @@ -40,6 +41,9 @@ namespace modules gifs.push_back(std::string(buffer)); } fclose(f); + } else { + auto musica = audio::loadMusic("ingame.ogg"); + audio::playMusic(musica); } actor::hero::init(); diff --git a/source/m_menu.cpp b/source/m_menu.cpp index cc66c26..4d184f1 100644 --- a/source/m_menu.cpp +++ b/source/m_menu.cpp @@ -4,7 +4,7 @@ #include "jdraw.h" #include "config.h" #include - +#include "jaudio.h" namespace modules { namespace menu @@ -17,6 +17,7 @@ namespace modules void init() { + audio::stopMusic(); selected_option = OPTION_JUGAR; ::game::setUpdateTicks(64); draw::loadPalette("test.gif");