Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Per-room altstate system #906

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 62 additions & 3 deletions desktop_version/src/CustomLevels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ RoomProperty::RoomProperty(void)
enemyy2=240;
enemytype=0;
directmode=0;
altstate=0;
}

customlevelclass::customlevelclass(void)
Expand Down Expand Up @@ -344,6 +345,7 @@ void customlevelclass::reset(void)
roomproperties[i+(j*maxwidth)].enemyy2=240;
roomproperties[i+(j*maxwidth)].enemytype=0;
roomproperties[i+(j*maxwidth)].directmode=0;
roomproperties[i+(j*maxwidth)].altstate=0;
}
}

Expand All @@ -352,6 +354,11 @@ void customlevelclass::reset(void)
script.clearcustom();

onewaycol_override = false;

for (int i = 0; i < numrooms; i++)
{
altstates[i].clear();
}
}

const int* customlevelclass::loadlevel( int rxi, int ryi )
Expand All @@ -366,13 +373,29 @@ const int* customlevelclass::loadlevel( int rxi, int ryi )

static int result[1200];

for (int j = 0; j < 30; j++)
int state = getroomprop(rxi, ryi)->altstate;

if (state < 0 || state > altstates[rxi + maxwidth * ryi].size())
{
for (int i = 0; i < 40; i++)
state = 0;
setroomaltstate(rxi, ryi, 0);
}

if (state == 0)
{
for (int j = 0; j < 30; j++)
{
result[i + j*40] = gettile(rxi, ryi, i, j);
for (int i = 0; i < 40; i++)
{
result[i + j * 40] = gettile(rxi, ryi, i, j);
}
}
}
else
{
const int* altstate = altstates[rxi + maxwidth * ryi][state - 1].data();
SDL_memcpy(result, altstate, sizeof(result));
}

return result;
}
Expand Down Expand Up @@ -830,6 +853,7 @@ const RoomProperty* customlevelclass::getroomprop(const int rx, const int ry)
static RoomProperty blank;
blank.tileset = 1;
blank.directmode = 1;
blank.altstate = 0;
blank.roomname.clear();

return &blank;
Expand Down Expand Up @@ -1100,6 +1124,41 @@ bool customlevelclass::load(std::string& _path)
}
}

if (SDL_strcmp(pKey, "altstates") == 0)
{
for (tinyxml2::XMLElement* stateEl = pElem->FirstChildElement(); stateEl; stateEl = stateEl->NextSiblingElement())
{
int x = 0;
int y = 0;
int state = 0;
stateEl->QueryIntAttribute("x", &x);
stateEl->QueryIntAttribute("y", &y);

const char* pText2 = stateEl->GetText();
if (pText2 == NULL)
{
pText2 = "";
}

std::vector<int> tiles;
tiles.resize(30 * 40, 0);

char buffer[16];
size_t start = 0;

int tile = 0;
while (next_split_s(buffer, sizeof(buffer), &start, pText2, ','))
{
if (INBOUNDS_VEC(tile, tiles))
{
tiles[tile] = help.Int(buffer);
}
tile++;
}

altstates[x + maxwidth * y].push_back(tiles);
}
}

if (SDL_strcmp(pKey, "edEntities") == 0)
{
Expand Down
6 changes: 5 additions & 1 deletion desktop_version/src/CustomLevels.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <SDL.h>
#include <string>
#include <vector>
#include <map>

class CustomEntity
{
Expand All @@ -32,7 +33,8 @@ class CustomEntity
FOREACH_PROP(enemyx2, int) \
FOREACH_PROP(enemyy2, int) \
FOREACH_PROP(enemytype, int) \
FOREACH_PROP(directmode, int)
FOREACH_PROP(directmode, int) \
FOREACH_PROP(altstate, int)

class RoomProperty
{
Expand Down Expand Up @@ -158,6 +160,8 @@ class customlevelclass
Uint32 getonewaycol(const int rx, const int ry);
Uint32 getonewaycol(void);
bool onewaycol_override;

std::vector<std::vector<int> > altstates[numrooms];
};

#ifndef CL_DEFINITION
Expand Down
18 changes: 18 additions & 0 deletions desktop_version/src/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2232,3 +2232,21 @@ void mapclass::twoframedelayfix(void)
game.statedelay = 0;
script.load(game.newscript);
}

void mapclass::setaltstate(int x, int y, int state)
{
#if !defined(NO_CUSTOM_LEVELS)
if (custommode)
{
cl.setroomaltstate(x, y, state);
if (game.roomx - 100 == x && game.roomy - 100 == y)
{
gotoroom(x + 100, y + 100);
}
}
else
#endif
{
obj.altstates = state;
}
}
2 changes: 2 additions & 0 deletions desktop_version/src/Map.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class mapclass

void twoframedelayfix(void);

void setaltstate(int x, int y, int state);


int roomdeaths[20 * 20];
int roomdeathsfinal[20 * 20];
Expand Down
19 changes: 17 additions & 2 deletions desktop_version/src/Script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1694,9 +1694,13 @@ void scriptclass::run(void)
{
game.savecolour = getcolorfromname(words[1]);
}
else if (words[0] == "altstates")
else if (words[0] == "altstate")
{
obj.altstates = ss_toi(words[1]);
int room_x = game.roomx - 100;
int room_y = game.roomy - 100;
if (ss_toi(words[1]) != -1) room_x = ss_toi(words[1]);
if (ss_toi(words[2]) != -1) room_y = ss_toi(words[2]);
map.setaltstate(room_x, room_y, ss_toi(words[3]));
}
else if (words[0] == "activeteleporter")
{
Expand Down Expand Up @@ -3247,6 +3251,17 @@ void scriptclass::hardreset(void)
SDL_memset(map.roomdeaths, 0, sizeof(map.roomdeaths));
SDL_memset(map.roomdeathsfinal, 0, sizeof(map.roomdeathsfinal));
map.resetmap();

#if !defined(NO_CUSTOM_LEVELS)
for (int j = 0; j < cl.maxheight; j++)
{
for (int i = 0; i < cl.maxwidth; i++)
{
cl.setroomaltstate(j, i, 0);
}
}
#endif

//entityclass
obj.nearelephant = false;
obj.upsetmode = false;
Expand Down
6 changes: 3 additions & 3 deletions desktop_version/src/Scripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6332,7 +6332,7 @@ void scriptclass::load(const std::string& name)
"rescued(green)",
"rescued(yellow)",
"missing(blue)",
"altstates(1)",
"altstate(-1,-1,1)",

"fadeout()",
"untilfade()",
Expand Down Expand Up @@ -6592,7 +6592,7 @@ void scriptclass::load(const std::string& name)
"flash(10)",
"shake(20)",
"playef(23)",
"altstates(2)",
"altstate(-1,-1,2)",
"gotoroom(17,6)",

"delay(20)",
Expand All @@ -6601,7 +6601,7 @@ void scriptclass::load(const std::string& name)
"flash(10)",
"shake(20)",
"playef(23)",
"altstates(0)",
"altstate(-1,-1,0)",
"gotoroom(17,6)",

"delay(20)",
Expand Down