Skip to content

Commit

Permalink
Edit hair in char editor #601
Browse files Browse the repository at this point in the history
Fix old static map loading #475
  • Loading branch information
cxong committed Feb 23, 2020
1 parent 47f39e9 commit 84ee188
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 132 deletions.
121 changes: 62 additions & 59 deletions src/cdogs/draw/draw_actor.c
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
/*
C-Dogs SDL
A port of the legendary (and fun) action/arcade cdogs.
Copyright (C) 1995 Ronny Wester
Copyright (C) 2003 Jeremy Chin
Copyright (C) 2003-2007 Lucas Martin-King
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
This file incorporates work covered by the following copyright and
permission notice:
Copyright (c) 2013-2019 Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
C-Dogs SDL
A port of the legendary (and fun) action/arcade cdogs.
Copyright (C) 1995 Ronny Wester
Copyright (C) 2003 Jeremy Chin
Copyright (C) 2003-2007 Lucas Martin-King
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
This file incorporates work covered by the following copyright and
permission notice:
Copyright (c) 2013-2020 Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include "draw/draw_actor.h"

Expand Down Expand Up @@ -163,9 +163,6 @@ ActorPics GetCharacterPicsFromActor(TActor *a)
gun->Gun != NULL ? gun->Gun->Sprites : NULL, gun->state,
shadowMask, maskP, colors, a->dead);
}
static const Pic *GetHairPic(
const Character *c, const direction_e dir, const gunstate_e gunState,
const CharColors *colors);
static const Pic *GetBodyPic(
PicManager *pm, const CharSprites *cs, const direction_e dir,
const ActorAnimation anim, const int frame, const bool isArmed,
Expand Down Expand Up @@ -238,7 +235,10 @@ ActorPics GetCharacterPics(
pics.HeadOffset = GetActorDrawOffset(
pics.Head, BODY_PART_HEAD, c->Class->Sprites, anim, frame, dir,
gunState);
pics.Hair = GetHairPic(c, headDir, gunState, colors);
if (c->Class->HasHair)
{
pics.Hair = GetHairPic(c->Hair, headDir, gunState, colors);
}
pics.HairOffset = GetActorDrawOffset(
pics.Hair, BODY_PART_HAIR, c->Class->Sprites, anim, frame, dir,
gunState);
Expand Down Expand Up @@ -432,11 +432,11 @@ const Pic *GetHeadPic(
&gPicManager, c->HeadSprites, colors);
return CArrayGet(&ns->pics, idx);
}
static const Pic *GetHairPic(
const Character *c, const direction_e dir, const gunstate_e gunState,
const Pic *GetHairPic(
const char *hair, const direction_e dir, const gunstate_e gunState,
const CharColors *colors)
{
if (!c->Class->HasHair || c->Hair == NULL)
if (hair == NULL)
{
return NULL;
}
Expand All @@ -445,7 +445,7 @@ static const Pic *GetHairPic(
const int idx = (int)dir + row * 8;
// Get or generate masked sprites
char buf[CDOGS_PATH_MAX];
sprintf(buf, "chars/hairs/%s", c->Hair);
sprintf(buf, "chars/hairs/%s", hair);
const NamedSprites *ns =
PicManagerGetCharSprites(&gPicManager, buf, colors);
return CArrayGet(&ns->pics, idx);
Expand Down Expand Up @@ -535,12 +535,15 @@ void DrawHead(
PicRender(
head, renderer, drawPos, mask, 0, svec2_one(), SDL_FLIP_NONE,
Rect2iZero());
const Pic *hair = GetHairPic(c, dir, g, &c->Colors);
if (hair)
if (c->Class->HasHair)
{
PicRender(
hair, renderer, drawPos, mask, 0, svec2_one(), SDL_FLIP_NONE,
Rect2iZero());
const Pic* hair = GetHairPic(c->Hair, dir, g, &c->Colors);
if (hair)
{
PicRender(
hair, renderer, drawPos, mask, 0, svec2_one(), SDL_FLIP_NONE,
Rect2iZero());
}
}
}
#define DYING_BODY_OFFSET 3
Expand Down
3 changes: 3 additions & 0 deletions src/cdogs/draw/draw_actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ void DrawHead(
const Pic *GetHeadPic(
const CharacterClass *c, const direction_e dir, const gunstate_e gunState,
const CharColors *colors);
const Pic* GetHairPic(
const char* hair, const direction_e dir, const gunstate_e gunState,
const CharColors* colors);
ActorPics GetCharacterPics(
const Character *c, const direction_e dir, const direction_e legDir,
const ActorAnimation anim, const int frame,
Expand Down
52 changes: 26 additions & 26 deletions src/cdogs/map_new.c
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
/*
C-Dogs SDL
A port of the legendary (and fun) action/arcade cdogs.
Copyright (c) 2014-2017, 2019 Cong Xu
All rights reserved.
C-Dogs SDL
A port of the legendary (and fun) action/arcade cdogs.
Copyright (c) 2014-2017, 2019 Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include "map_new.h"

Expand Down Expand Up @@ -399,16 +399,16 @@ void LoadMissionTileClasses(
LoadColor(&altMask, node, "AltMask");
}
TileClassInit(
&mtc->Wall, &gPicManager, &gTileWall, wallStyle, NULL,
&mtc->Wall, &gPicManager, &gTileWall, wallStyle, "o",
wallMask, altMask);
TileClassInit(
&mtc->Floor, &gPicManager, &gTileFloor, floorStyle, NULL,
&mtc->Floor, &gPicManager, &gTileFloor, floorStyle, "normal",
floorMask, altMask);
TileClassInit(
&mtc->Room, &gPicManager, &gTileRoom, roomStyle, NULL,
&mtc->Room, &gPicManager, &gTileRoom, roomStyle, "normal",
roomMask, altMask);
TileClassInit(
&mtc->Door, &gPicManager, &gTileDoor, doorStyle, NULL,
&mtc->Door, &gPicManager, &gTileDoor, doorStyle, "normal_h",
colorWhite, colorWhite);
}
else
Expand Down
1 change: 1 addition & 0 deletions src/cdogs/mission_static.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ static void ConvertOldTile(
memcpy(tc, base, sizeof *tc);
if (base->Name) CSTRDUP(tc->Name, base->Name);
if (base->Style) CSTRDUP(tc->Style, base->Style);
if (base->StyleType) CSTRDUP(tc->StyleType, base->StyleType);
tc->Mask = base->Mask;
tc->MaskAlt = base->MaskAlt;
if (hashmap_put(m->TileClasses, keyBuf, tc) != MAP_OK)
Expand Down
57 changes: 30 additions & 27 deletions src/cdogs/tile_class.c
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
/*
C-Dogs SDL
A port of the legendary (and fun) action/arcade cdogs.
Copyright (c) 2018-2020 Cong Xu
All rights reserved.
C-Dogs SDL
A port of the legendary (and fun) action/arcade cdogs.
Copyright (c) 2018-2020 Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include "tile_class.h"

Expand Down Expand Up @@ -165,11 +165,14 @@ void TileClassInit(
}
t->Mask = mask;
t->MaskAlt = maskAlt;
// Generate the pic in case it doesn't exist
PicManagerGenerateMaskedStylePic(
pm, t->Name, style, type, mask, maskAlt, false);
t->Pic = TileClassGetPic(pm, t);
CASSERT(t->Pic != NULL, "cannot find tile pic");
if (t->Name != NULL)
{
// Generate the pic in case it doesn't exist
PicManagerGenerateMaskedStylePic(
pm, t->Name, style, type, mask, maskAlt, false);
t->Pic = TileClassGetPic(pm, t);
CASSERT(t->Pic != NULL, "cannot find tile pic");
}
}
const TileClass *TileClassesGetMaskedTile(
const TileClass *baseClass, const char *style, const char *type,
Expand Down
Loading

0 comments on commit 84ee188

Please sign in to comment.