- Guardat de actor a arxiu
- Creació de actor desde plantilla
This commit is contained in:
131
source/actor.cpp
131
source/actor.cpp
@@ -64,6 +64,16 @@ namespace actor
|
||||
return act;
|
||||
}
|
||||
|
||||
actor_t *createFromTemplate(const char *name)
|
||||
{
|
||||
actor_t *templ = actor::templates::getByName(name);
|
||||
if (!templ) return nullptr;
|
||||
|
||||
actor_t *act = createEmptyActor();
|
||||
actor::templates::copy(act, templ);
|
||||
return act;
|
||||
}
|
||||
|
||||
actor_t *createFromFile(char **buffer)
|
||||
{
|
||||
if (*buffer)
|
||||
@@ -140,6 +150,68 @@ namespace actor
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
char tmp[255];
|
||||
|
||||
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 ");
|
||||
return tmp;
|
||||
}
|
||||
|
||||
const char *numToFlags(uint16_t value)
|
||||
{
|
||||
tmp[0]=0;
|
||||
if (value==0) return "NONE";
|
||||
if (value&1) strcat(tmp, "HERO ");
|
||||
if (value&2) strcat(tmp, "PUSHABLE ");
|
||||
if (value&4) strcat(tmp, "REACTIVE ");
|
||||
if (value&8) strcat(tmp, "MOVING ");
|
||||
if (value&16) strcat(tmp, "ANIMATED ");
|
||||
if (value&32) strcat(tmp, "ORIENTABLE ");
|
||||
if (value&64) strcat(tmp, "DEADLY ");
|
||||
if (value&128) strcat(tmp, "GRAVITY ");
|
||||
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 "HUNT";
|
||||
return "NONE";
|
||||
}
|
||||
|
||||
void saveToFile(FILE *f, actor_t *act)
|
||||
{
|
||||
fprintf(f, "actor{\n");
|
||||
fprintf(f, " name: %s\n", act->name);
|
||||
fprintf(f, " bmp: %s\n", act->bmp);
|
||||
fprintf(f, " bmp-rect: %i %i %i %i\n", act->bmp_rect.x, act->bmp_rect.y, act->bmp_rect.w, act->bmp_rect.h);
|
||||
fprintf(f, " bmp-offset: %i %i\n", act->bmp_offset.x, act->bmp_offset.y);
|
||||
fprintf(f, " pos: %i %i %i\n", act->pos.x, act->pos.y, act->pos.z);
|
||||
fprintf(f, " size: %i %i %i\n", act->size.x, act->size.y, act->size.z);
|
||||
fprintf(f, " orient: %s\n", numToOrient(act->orient));
|
||||
fprintf(f, " anim-cycle: %s\n", act->anim_cycle==0 ? "WALK" : "SEQ");
|
||||
fprintf(f, " anim-wait: %i\n", act->anim_wait);
|
||||
fprintf(f, " flags: %s\n", numToFlags(act->flags));
|
||||
fprintf(f, " react-mask: %s\n", numToOrient(act->react_mask));
|
||||
fprintf(f, " react-push: %s\n", numToOrient(act->react_push));
|
||||
fprintf(f, " movement: %s\n\n", numToMov(act->movement));
|
||||
fprintf(f, "}\n\n");
|
||||
}
|
||||
|
||||
const bool check_2d_collision(actor_t *obj1, actor_t *obj2)
|
||||
{
|
||||
return (obj1->pos.x < obj2->pos.x + obj2->size.x) &&
|
||||
@@ -869,51 +941,8 @@ namespace actor
|
||||
|
||||
namespace templates
|
||||
{
|
||||
char tmp[255];
|
||||
|
||||
std::vector<actor_t> templates;
|
||||
|
||||
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 ");
|
||||
return tmp;
|
||||
}
|
||||
|
||||
const char *numToFlags(uint16_t value)
|
||||
{
|
||||
tmp[0]=0;
|
||||
if (value==0) return "NONE";
|
||||
if (value&1) strcat(tmp, "HERO ");
|
||||
if (value&2) strcat(tmp, "PUSHABLE ");
|
||||
if (value&4) strcat(tmp, "REACTIVE ");
|
||||
if (value&8) strcat(tmp, "MOVING ");
|
||||
if (value&16) strcat(tmp, "ANIMATED ");
|
||||
if (value&32) strcat(tmp, "ORIENTABLE ");
|
||||
if (value&64) strcat(tmp, "DEADLY ");
|
||||
if (value&128) strcat(tmp, "GRAVITY ");
|
||||
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 "HUNT";
|
||||
return "NONE";
|
||||
}
|
||||
|
||||
void load()
|
||||
{
|
||||
templates.clear();
|
||||
@@ -946,21 +975,7 @@ namespace actor
|
||||
for (int i=0; i<templates.size(); ++i)
|
||||
{
|
||||
actor_t t = templates[i];
|
||||
fprintf(f, "actor{\n");
|
||||
fprintf(f, " name: %s\n", t.name);
|
||||
fprintf(f, " bmp: %s\n", t.bmp);
|
||||
fprintf(f, " bmp-rect: %i %i %i %i\n", t.bmp_rect.x, t.bmp_rect.y, t.bmp_rect.w, t.bmp_rect.h);
|
||||
fprintf(f, " bmp-offset: %i %i\n", t.bmp_offset.x, t.bmp_offset.y);
|
||||
fprintf(f, " pos: %i %i %i\n", t.pos.x, t.pos.y, t.pos.z);
|
||||
fprintf(f, " size: %i %i %i\n", t.size.x, t.size.y, t.size.z);
|
||||
fprintf(f, " orient: %s\n", numToOrient(t.orient));
|
||||
fprintf(f, " anim-cycle: %s\n", t.anim_cycle==0 ? "WALK" : "SEQ");
|
||||
fprintf(f, " anim-wait: %i\n", t.anim_wait);
|
||||
fprintf(f, " flags: %s\n", numToFlags(t.flags));
|
||||
fprintf(f, " react-mask: %s\n", numToOrient(t.react_mask));
|
||||
fprintf(f, " react-push: %s\n", numToOrient(t.react_push));
|
||||
fprintf(f, " movement: %s\n\n", numToMov(t.movement));
|
||||
fprintf(f, "}\n\n");
|
||||
saveToFile(f, &t);
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
|
||||
@@ -86,8 +86,12 @@ namespace actor
|
||||
// Torna un nou actor
|
||||
actor_t *create(std::string name, vec3_t p, vec3_t s, std::string bmp, SDL_Rect r, SDL_Point o);
|
||||
|
||||
actor_t *createFromTemplate(const char *name);
|
||||
|
||||
actor_t *createFromFile(char **buffer);
|
||||
|
||||
void saveToFile(FILE *f, actor_t *act);
|
||||
|
||||
void setDirty(actor_t *act, const bool force=false);
|
||||
|
||||
void select(actor_t *act);
|
||||
|
||||
Reference in New Issue
Block a user