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

Region system #896

Merged
merged 6 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
42 changes: 7 additions & 35 deletions desktop_version/src/CustomLevels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1678,35 +1678,7 @@ bool customlevelclass::save(const std::string& _path)

void customlevelclass::generatecustomminimap(void)
{
map.customzoom = 1;
if (mapwidth <= 10 && mapheight <= 10)
{
map.customzoom = 2;
}
if (mapwidth <= 5 && mapheight <= 5)
{
map.customzoom = 4;
}

// Set minimap offsets
switch (map.customzoom)
{
case 4:
map.custommmxoff = 24 * (5 - mapwidth);
map.custommmyoff = 18 * (5 - mapheight);
break;
case 2:
map.custommmxoff = 12 * (10 - mapwidth);
map.custommmyoff = 9 * (10 - mapheight);
break;
default:
map.custommmxoff = 6 * (20 - mapwidth);
map.custommmyoff = int(4.5 * (20 - mapheight));
break;
}

map.custommmxsize = 240 - (map.custommmxoff * 2);
map.custommmysize = 180 - (map.custommmyoff * 2);
const MapRenderData data = map.get_render_data();

// Start drawing the minimap

Expand All @@ -1715,22 +1687,22 @@ void customlevelclass::generatecustomminimap(void)
graphics.clear();

// Scan over the map size
for (int j2 = 0; j2 < mapheight; j2++)
for (int j2 = data.starty; j2 < data.starty + data.height; j2++)
{
for (int i2 = 0; i2 < mapwidth; i2++)
for (int i2 = data.startx; i2 < data.startx + data.width; i2++)
{
std::vector<SDL_Point> dark_points;
std::vector<SDL_Point> light_points;

bool dark = getroomprop(i2, j2)->tileset == 1;

// Ok, now scan over each square
for (int j = 0; j < 9 * map.customzoom; j++)
for (int j = 0; j < 9 * data.zoom; j++)
{
for (int i = 0; i < 12 * map.customzoom; i++)
for (int i = 0; i < 12 * data.zoom; i++)
{
int tile;
switch (map.customzoom)
switch (data.zoom)
{
case 4:
tile = absfree(
Expand All @@ -1755,7 +1727,7 @@ void customlevelclass::generatecustomminimap(void)
if (tile >= 1)
{
// Add this pixel
SDL_Point point = { (i2 * 12 * map.customzoom) + i, (j2 * 9 * map.customzoom) + j };
SDL_Point point = { ((i2 - data.startx) * 12 * data.zoom) + i, ((j2 - data.starty) * 9 * data.zoom) + j };
if (dark)
{
dark_points.push_back(point);
Expand Down
77 changes: 77 additions & 0 deletions desktop_version/src/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5907,6 +5907,48 @@ void Game::customloadquick(const std::string& savfile)
map.roomnameset = true;
map.roomname_special = true;
}
else if (SDL_strcmp(pKey, "currentregion") == 0)
{
map.currentregion = help.Int(pText);
}
else if (SDL_strcmp(pKey, "regions") == 0)
{
tinyxml2::XMLElement* pElem2;
for (pElem2 = pElem->FirstChildElement(); pElem2 != NULL; pElem2 = pElem2->NextSiblingElement())
{
int thisid = 0;
int thisrx = 0;
int thisry = 0;
int thisrx2 = (cl.mapwidth - 1);
int thisry2 = (cl.mapheight - 1);
if (pElem2->Attribute("id"))
{
thisid = help.Int(pElem2->Attribute("id"));
}

for (tinyxml2::XMLElement* pElem3 = pElem2->FirstChildElement(); pElem3 != NULL; pElem3 = pElem3->NextSiblingElement())
{
if (SDL_strcmp(pElem3->Value(), "rx") == 0 && pElem3->GetText() != NULL)
{
thisrx = help.Int(pElem3->GetText());
}
if (SDL_strcmp(pElem3->Value(), "ry") == 0 && pElem3->GetText() != NULL)
{
thisry = help.Int(pElem3->GetText());
}
if (SDL_strcmp(pElem3->Value(), "rx2") == 0 && pElem3->GetText() != NULL)
{
thisrx2 = help.Int(pElem3->GetText());
}
if (SDL_strcmp(pElem3->Value(), "ry2") == 0 && pElem3->GetText() != NULL)
{
thisry2 = help.Int(pElem3->GetText());
}
}

map.setregion(thisid, thisrx, thisry, thisrx2, thisry2);
}
}
}
}

Expand Down Expand Up @@ -6291,6 +6333,41 @@ bool Game::customsavequick(const std::string& savfile)

xml::update_tag(msgs, "crewmates", crewmates());

xml::update_tag(msgs, "currentregion", map.currentregion);

tinyxml2::XMLElement* msg = xml::update_element_delete_contents(msgs, "regions");
for (size_t i = 0; i < SDL_arraysize(map.region); i++)
{
if (map.region[i].isvalid)
{
tinyxml2::XMLElement* region_el;
region_el = doc.NewElement("region");

region_el->SetAttribute("id", (help.String(i).c_str()));

tinyxml2::XMLElement* rx_el;
rx_el = doc.NewElement("rx");
rx_el->LinkEndChild(doc.NewText(help.String(map.region[i].rx).c_str()));
region_el->LinkEndChild(rx_el);

tinyxml2::XMLElement* ry_el;
ry_el = doc.NewElement("ry");
ry_el->LinkEndChild(doc.NewText(help.String(map.region[i].ry).c_str()));
region_el->LinkEndChild(ry_el);

tinyxml2::XMLElement* rx2_el;
rx2_el = doc.NewElement("rx2");
rx2_el->LinkEndChild(doc.NewText(help.String(map.region[i].rx2).c_str()));
region_el->LinkEndChild(rx2_el);

tinyxml2::XMLElement* ry2_el;
ry2_el = doc.NewElement("ry2");
ry2_el->LinkEndChild(doc.NewText(help.String(map.region[i].ry2).c_str()));
region_el->LinkEndChild(ry2_el);

msg->LinkEndChild(region_el);
}
}

//Special stats

Expand Down
9 changes: 9 additions & 0 deletions desktop_version/src/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,15 @@ void Graphics::draw_grid_tile(
draw_grid_tile(texture, t, x, y, width, height, color, 1, 1);
}

void Graphics::draw_region_image(int t, int xp, int yp, int wp, int hp)
{
if (!INBOUNDS_ARR(t, customminimaps) || customminimaps[t] == NULL)
{
return;
}
draw_texture_part(customminimaps[t], xp, yp, 0, 0, wp, hp, 1, 1);
}

void Graphics::cutscenebars(void)
{
const int usethispos = lerp(oldcutscenebarspos, cutscenebarspos);
Expand Down
4 changes: 4 additions & 0 deletions desktop_version/src/Graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ class Graphics
void draw_grid_tile(SDL_Texture* texture, int t, int x, int y, int width, int height, SDL_Color color, int scalex, int scaley);
void draw_grid_tile(SDL_Texture* texture, int t, int x, int y, int width, int height, SDL_Color color);

void draw_region_image(int t, int xp, int yp, int wp, int hp);

void updatetextboxes(void);
const char* textbox_line(char* buffer, size_t buffer_len, size_t textbox_i, size_t line_i);
void drawgui(void);
Expand Down Expand Up @@ -337,6 +339,8 @@ class Graphics

SDL_Texture* images[NUM_IMAGES];

SDL_Texture* customminimaps[401];

bool flipmode;
bool setflipmode;
bool notextoutline;
Expand Down
32 changes: 32 additions & 0 deletions desktop_version/src/GraphicsResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,33 @@ void GraphicsResources::init(void)
SDL_assert(0 && "Failed to create minimap texture! See stderr.");
return;
}

SDL_zeroa(graphics.customminimaps);

EnumHandle handle = {};
const char* item;
char full_item[64];
while ((item = FILESYSTEM_enumerateAssets("graphics", &handle)) != NULL)
{
if (SDL_strncmp(item, "region", 6) != 0)
{
continue;
}
char* end;
int i = SDL_strtol(&item[6], &end, 10);
// make sure the region id is actually in bounds!
if (i < 1 || i > 400)
{
continue;
}
if (item == end || SDL_strcmp(end, ".png") != 0)
{
continue;
}
SDL_snprintf(full_item, sizeof(full_item), "graphics/%s", item);
graphics.customminimaps[i] = LoadImage(full_item);
}
FILESYSTEM_freeEnumerate(&handle);
}


Expand Down Expand Up @@ -476,6 +503,11 @@ void GraphicsResources::destroy(void)

CLEAR(im_sprites_translated);
CLEAR(im_flipsprites_translated);

for (size_t i = 0; i < SDL_arraysize(graphics.customminimaps); i++)
{
CLEAR(graphics.customminimaps[i]);
}
#undef CLEAR

VVV_freefunc(SDL_FreeSurface, im_sprites_surf);
Expand Down
Loading
Loading