Skip to content

Commit

Permalink
Fix mission copy preserving tile classes (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
cxong committed Feb 21, 2019
1 parent 7e645da commit daaea88
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 25 deletions.
69 changes: 44 additions & 25 deletions src/cdogs/mission.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,20 @@ void MissionInit(Mission *m)
IntDoorStyle(0), NULL, colorWhite, colorWhite);
}

static const MissionTileClasses *MissionGetTileClassesC(const Mission *m)
{
switch (m->Type)
{
case MAPTYPE_CLASSIC:
return &m->u.Classic.TileClasses;
case MAPTYPE_STATIC:
return NULL;
case MAPTYPE_CAVE:
return &m->u.Cave.TileClasses;
default:
return NULL;
}
}
void MissionCopy(Mission *dst, const Mission *src)
{
if (src == NULL)
Expand All @@ -141,7 +155,6 @@ void MissionCopy(Mission *dst, const Mission *src)
{
CSTRDUP(dst->Description, src->Description);
}
dst->Type = src->Type;
dst->Size = src->Size;

strcpy(dst->ExitStyle, src->ExitStyle);
Expand All @@ -165,42 +178,25 @@ void MissionCopy(Mission *dst, const Mission *src)
switch (src->Type)
{
case MAPTYPE_CLASSIC:
TileClassCopy(
&dst->u.Classic.TileClasses.Door,
&src->u.Classic.TileClasses.Door);
TileClassCopy(
&dst->u.Classic.TileClasses.Floor,
&src->u.Classic.TileClasses.Floor);
TileClassCopy(
&dst->u.Classic.TileClasses.Wall,
&src->u.Classic.TileClasses.Wall);
TileClassCopy(
&dst->u.Classic.TileClasses.Room,
&src->u.Classic.TileClasses.Room);
MissionTileClassesCopy(
MissionGetTileClasses(dst), MissionGetTileClassesC(src));
break;

case MAPTYPE_STATIC:
MissionStaticCopy(&dst->u.Static, &src->u.Static);
break;

case MAPTYPE_CAVE:
TileClassCopy(
&dst->u.Cave.TileClasses.Door,
&src->u.Cave.TileClasses.Door);
TileClassCopy(
&dst->u.Cave.TileClasses.Floor,
&src->u.Cave.TileClasses.Floor);
TileClassCopy(
&dst->u.Cave.TileClasses.Wall,
&src->u.Cave.TileClasses.Wall);
TileClassCopy(
&dst->u.Cave.TileClasses.Room,
&src->u.Cave.TileClasses.Room);
MissionTileClassesCopy(
MissionGetTileClasses(dst), MissionGetTileClassesC(src));
break;

default:
break;
}

// Copy type at the end so we can do type-specific conversions before this
dst->Type = src->Type;
}

void MissionTerminate(Mission *m)
Expand Down Expand Up @@ -234,6 +230,20 @@ void MissionTerminate(Mission *m)
memset(m, 0, sizeof *m);
}

MissionTileClasses *MissionGetTileClasses(Mission *m)
{
switch (m->Type)
{
case MAPTYPE_CLASSIC:
return &m->u.Classic.TileClasses;
case MAPTYPE_STATIC:
return NULL;
case MAPTYPE_CAVE:
return &m->u.Cave.TileClasses;
default:
return NULL;
}
}

// +-----------------------+
// | And now the code... |
Expand Down Expand Up @@ -306,6 +316,15 @@ void MissionSetupTileClasses(PicManager *pm, const MissionTileClasses *mtc)
pm, &mtc->Room, mtc->Room.Style, mtc->Room.Mask, mtc->Room.MaskAlt);
SetupDoorTileClasses(pm, mtc->Door.Style);
}
void MissionTileClassesCopy(
MissionTileClasses *dst, const MissionTileClasses *src)
{
if (dst == NULL || src == NULL) return;
TileClassCopy(&dst->Door, &src->Door);
TileClassCopy(&dst->Floor, &src->Floor);
TileClassCopy(&dst->Wall, &src->Wall);
TileClassCopy(&dst->Room, &src->Room);
}
void MissionTileClassesTerminate(MissionTileClasses *mtc)
{
TileClassTerminate(&mtc->Wall);
Expand Down
4 changes: 4 additions & 0 deletions src/cdogs/mission.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,12 @@ void MissionInit(Mission *m);
void MissionCopy(Mission *dst, const Mission *src);
void MissionTerminate(Mission *m);

MissionTileClasses *MissionGetTileClasses(Mission *m);

void SetupMission(Mission *m, struct MissionOptions *mo, int missionIndex);
void MissionSetupTileClasses(PicManager *pm, const MissionTileClasses *mtc);
void MissionTileClassesCopy(
MissionTileClasses *dst, const MissionTileClasses *src);
void MissionTileClassesTerminate(MissionTileClasses *mtc);

void MissionSetMessageIfComplete(struct MissionOptions *options);
Expand Down
6 changes: 6 additions & 0 deletions src/cdogs/mission_convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@

void MissionConvertToType(Mission *m, Map *map, MapType type)
{
MissionTileClasses mtc;
MissionTileClasses *mtcOrig = MissionGetTileClasses(m);
MissionTileClassesCopy(&mtc, mtcOrig);
MissionTileClassesTerminate(mtcOrig);
memset(&m->u, 0, sizeof m->u);
switch (type)
{
Expand All @@ -58,6 +62,7 @@ void MissionConvertToType(Mission *m, Map *map, MapType type)
m->u.Classic.Pillars.Count = 1;
m->u.Classic.Pillars.Min = 2;
m->u.Classic.Pillars.Max = 3;
memcpy(&m->u.Classic.TileClasses, &mtc, sizeof mtc);
break;
case MAPTYPE_STATIC:
MissionStaticFromMap(&m->u.Static, map);
Expand All @@ -78,6 +83,7 @@ void MissionConvertToType(Mission *m, Map *map, MapType type)
m->u.Cave.Rooms.WallLength = 1;
m->u.Cave.Rooms.WallPad = 1;
m->u.Cave.Squares = 1;
memcpy(&m->u.Cave.TileClasses, &mtc, sizeof mtc);
break;
default:
CASSERT(false, "unknown map type");
Expand Down

0 comments on commit daaea88

Please sign in to comment.