2020-01-01 21:29:24 +01:00
|
|
|
#include "BlockV.h"
|
|
|
|
|
2021-09-12 08:15:34 +02:00
|
|
|
#include <SDL_stdinc.h>
|
|
|
|
|
2022-11-21 20:02:38 +01:00
|
|
|
#include "CustomLevels.h"
|
2023-01-13 20:32:05 +01:00
|
|
|
#include "Font.h"
|
|
|
|
|
Explicitly declare void for all void parameter functions (#628)
Apparently in C, if you have `void test();`, it's completely okay to do
`test(2);`. The function will take in the argument, but just discard it
and throw it away. It's like a trash can, and a rude one at that. If you
declare it like `void test(void);`, this is prevented.
This is not a problem in C++ - doing `void test();` and `test(2);` is
guaranteed to result in a compile error (this also means that right now,
at least in all `.cpp` files, nobody is ever calling a void parameter
function with arguments and having their arguments be thrown away).
However, we may not be using C++ in the future, so I just want to lay
down the precedent that if a function takes in no arguments, you must
explicitly declare it as such.
I would've added `-Wstrict-prototypes`, but it produces an annoying
warning message saying it doesn't work in C++ mode if you're compiling
in C++ mode. So it can be added later.
2021-02-25 23:23:59 +01:00
|
|
|
blockclass::blockclass(void)
|
Fix entity and block indices after destroying them
This patch restores some 2.2 behavior, fixing a regression caused by the
refactor of properly using std::vectors.
In 2.2, the game allocated 200 items in obj.entities, but used a system
where each entity had an `active` attribute to signify if the entity
actually existed or not. When dealing with entities, you would have to
check this `active` flag, or else you'd be dealing with an entity that
didn't actually exist. (By the way, what I'm saying applies to blocks
and obj.blocks as well, except for some small differing details like the
game allocating 500 block slots versus obj.entities's 200.)
As a consequence, the game had to use a separate tracking variable,
obj.nentity, because obj.entities.size() would just report 200, instead
of the actual amount of entities. Needless to say, having to check for
`active` and use `obj.nentity` is a bit error-prone, and it's messier
than simply using the std::vector the way it was intended. Also, this
resulted in a hard limit of 200 entities, which custom level makers ran
into surprisingly quite often.
2.3 comes along, and removes the whole system. Now, std::vectors are
properly being used, and obj.entities.size() reports the actual number
of entities in the vector; you no longer have to check for `active` when
dealing with entities of any sort.
But there was one previous behavior of 2.2 that this system kind of
forgets about - namely, the ability to have holes in between entities.
You see, when an entity got disabled in 2.2 (which just meant turning
its `active` off), the indices of all other entities stayed the same;
the indice of the entity that got disabled stays there as a hole in the
array. But when an entity gets removed in 2.3 (previous to this patch),
the indices of every entity afterwards in the array get shifted down by
one. std::vector isn't really meant to be able to contain holes.
Do the indices of entities and blocks matter? Yes; they determine the
order in which entities and blocks get evaluated (the highest indice
gets evaluated first), and I had to fix some block evaluation order
stuff in previous PRs.
And in the case of entities, they matter hugely when using the
recently-discovered Arbitrary Entity Manipulation glitch (where crewmate
script commands are used on arbitrary entities by setting the `i`
attribute of `scriptclass` and passing invalid crewmate identifiers to
the commands). If you use Arbitrary Entity Manipulation after destroying
some entities, there is a chance that your script won't work between 2.2
and 2.3.
The indices also still determine the rendering order of entities
(highest indice gets drawn first, which means lowest indice gets drawn
in front of other entities). As an example: let's say we have the player
at 0, a gravity line at 1, and a checkpoint at 2; then we destroy the
gravity line and create a crewmate (let's do Violet).
If we're able to have holes, then after removing the gravity line, none
of the other indices shift. Then Violet will be created at indice 1, and
will be drawn in front of the checkpoint.
But if we can't have holes, then removing the gravity line results in
the indice of the checkpoint shifting down to indice 1. Then Violet is
created at indice 2, and gets drawn behind the checkpoint! This is a
clear illustration of changing the behavior that existed in 2.2.
However, I also don't want to go back to the `active` system of having
to check an attribute before operating on an entity. So... what do we
do to restore the holes?
Well, we don't need to have an `active` attribute, or modify any
existing code that operates on entities. Instead, we can just set the
attributes of the entities so that they naturally get ignored by
everything that comes into contact with it. For entities, we set their
invis to true, and their size, type, and rule to -1 (the game never uses
a size, type, or rule of -1 anywhere); for blocks, we set their type to
-1, and their width and height to 0.
obj.entities.size() will no longer necessarily equal the amount of
entities in the room; rather, it will be the amount of entity SLOTS that
have been allocated. But nothing that uses obj.entities.size() needs to
actually know the amount of entities; it's mostly used for iterating
over every entity in the vector.
Excess entity slots get cleaned up upon every call of
mapclass::gotoroom(), which will now deallocate entity slots starting
from the end until it hits a player, at which point it will switch to
disabling entity slots instead of removing them entirely.
The entclass::clear() and blockclass::clear() functions have been
restored because we need to call their initialization functions when
reusing a block/entity slot; it's possible to create an entity with an
invalid type number (it creates a glitchy Viridian), and without calling
the initialization function again, it would simply not create anything.
After this patch is applied, entity and block indices will be restored
to how they behaved in 2.2.
2020-12-27 07:11:34 +01:00
|
|
|
{
|
2021-09-07 03:56:39 +02:00
|
|
|
clear();
|
Fix entity and block indices after destroying them
This patch restores some 2.2 behavior, fixing a regression caused by the
refactor of properly using std::vectors.
In 2.2, the game allocated 200 items in obj.entities, but used a system
where each entity had an `active` attribute to signify if the entity
actually existed or not. When dealing with entities, you would have to
check this `active` flag, or else you'd be dealing with an entity that
didn't actually exist. (By the way, what I'm saying applies to blocks
and obj.blocks as well, except for some small differing details like the
game allocating 500 block slots versus obj.entities's 200.)
As a consequence, the game had to use a separate tracking variable,
obj.nentity, because obj.entities.size() would just report 200, instead
of the actual amount of entities. Needless to say, having to check for
`active` and use `obj.nentity` is a bit error-prone, and it's messier
than simply using the std::vector the way it was intended. Also, this
resulted in a hard limit of 200 entities, which custom level makers ran
into surprisingly quite often.
2.3 comes along, and removes the whole system. Now, std::vectors are
properly being used, and obj.entities.size() reports the actual number
of entities in the vector; you no longer have to check for `active` when
dealing with entities of any sort.
But there was one previous behavior of 2.2 that this system kind of
forgets about - namely, the ability to have holes in between entities.
You see, when an entity got disabled in 2.2 (which just meant turning
its `active` off), the indices of all other entities stayed the same;
the indice of the entity that got disabled stays there as a hole in the
array. But when an entity gets removed in 2.3 (previous to this patch),
the indices of every entity afterwards in the array get shifted down by
one. std::vector isn't really meant to be able to contain holes.
Do the indices of entities and blocks matter? Yes; they determine the
order in which entities and blocks get evaluated (the highest indice
gets evaluated first), and I had to fix some block evaluation order
stuff in previous PRs.
And in the case of entities, they matter hugely when using the
recently-discovered Arbitrary Entity Manipulation glitch (where crewmate
script commands are used on arbitrary entities by setting the `i`
attribute of `scriptclass` and passing invalid crewmate identifiers to
the commands). If you use Arbitrary Entity Manipulation after destroying
some entities, there is a chance that your script won't work between 2.2
and 2.3.
The indices also still determine the rendering order of entities
(highest indice gets drawn first, which means lowest indice gets drawn
in front of other entities). As an example: let's say we have the player
at 0, a gravity line at 1, and a checkpoint at 2; then we destroy the
gravity line and create a crewmate (let's do Violet).
If we're able to have holes, then after removing the gravity line, none
of the other indices shift. Then Violet will be created at indice 1, and
will be drawn in front of the checkpoint.
But if we can't have holes, then removing the gravity line results in
the indice of the checkpoint shifting down to indice 1. Then Violet is
created at indice 2, and gets drawn behind the checkpoint! This is a
clear illustration of changing the behavior that existed in 2.2.
However, I also don't want to go back to the `active` system of having
to check an attribute before operating on an entity. So... what do we
do to restore the holes?
Well, we don't need to have an `active` attribute, or modify any
existing code that operates on entities. Instead, we can just set the
attributes of the entities so that they naturally get ignored by
everything that comes into contact with it. For entities, we set their
invis to true, and their size, type, and rule to -1 (the game never uses
a size, type, or rule of -1 anywhere); for blocks, we set their type to
-1, and their width and height to 0.
obj.entities.size() will no longer necessarily equal the amount of
entities in the room; rather, it will be the amount of entity SLOTS that
have been allocated. But nothing that uses obj.entities.size() needs to
actually know the amount of entities; it's mostly used for iterating
over every entity in the vector.
Excess entity slots get cleaned up upon every call of
mapclass::gotoroom(), which will now deallocate entity slots starting
from the end until it hits a player, at which point it will switch to
disabling entity slots instead of removing them entirely.
The entclass::clear() and blockclass::clear() functions have been
restored because we need to call their initialization functions when
reusing a block/entity slot; it's possible to create an entity with an
invalid type number (it creates a glitchy Viridian), and without calling
the initialization function again, it would simply not create anything.
After this patch is applied, entity and block indices will be restored
to how they behaved in 2.2.
2020-12-27 07:11:34 +01:00
|
|
|
}
|
|
|
|
|
Explicitly declare void for all void parameter functions (#628)
Apparently in C, if you have `void test();`, it's completely okay to do
`test(2);`. The function will take in the argument, but just discard it
and throw it away. It's like a trash can, and a rude one at that. If you
declare it like `void test(void);`, this is prevented.
This is not a problem in C++ - doing `void test();` and `test(2);` is
guaranteed to result in a compile error (this also means that right now,
at least in all `.cpp` files, nobody is ever calling a void parameter
function with arguments and having their arguments be thrown away).
However, we may not be using C++ in the future, so I just want to lay
down the precedent that if a function takes in no arguments, you must
explicitly declare it as such.
I would've added `-Wstrict-prototypes`, but it produces an annoying
warning message saying it doesn't work in C++ mode if you're compiling
in C++ mode. So it can be added later.
2021-02-25 23:23:59 +01:00
|
|
|
void blockclass::clear(void)
|
2020-01-01 21:29:24 +01:00
|
|
|
{
|
2021-09-07 03:56:39 +02:00
|
|
|
type = 0;
|
|
|
|
trigger = 0;
|
2020-01-01 21:29:24 +01:00
|
|
|
|
2021-09-07 03:56:39 +02:00
|
|
|
xp = 0;
|
|
|
|
yp = 0;
|
|
|
|
wp = 0;
|
|
|
|
hp = 0;
|
|
|
|
rect.x = xp;
|
|
|
|
rect.y = yp;
|
|
|
|
rect.w = wp;
|
|
|
|
rect.h = hp;
|
2020-01-01 21:29:24 +01:00
|
|
|
|
2021-09-07 03:56:39 +02:00
|
|
|
r = 0;
|
|
|
|
g = 0;
|
|
|
|
b = 0;
|
2020-07-06 22:04:34 +02:00
|
|
|
|
Add `setactivityposition(x,y)`, add new textbox color `transparent` (#847)
* Add `setactivityposition(x,y)`, add new textbox color `transparent`
This commit adds a new internal command as a part of the visual activity zone changes I've been making.
This one allows the user to reposition the activity zone to anywhere on the screen.
In addition, this commit adds the textbox color `transparent`, which just sets r, g and b to 0.
rgb(0, 0, 0) normally creates the color black, however in VVVVVV textboxes, it makes the background
of them invisible, and makes the text the off-white color which the game uses elsewhere.
* add new variables to hardreset
* Fix unwanted text centering; offset position by 16, 4
It makes sense for `setactivityposition(0, 0)` to place the activity zone in the default position,
so the x has been offset by 16, and the y has been offset by 4.
Text was being automatically centered, meaning any activity zone which wasn't centered had misplaced text.
This has been fixed by calculating the center manually, and offsetting it by the passed value.
2021-10-14 00:38:51 +02:00
|
|
|
activity_y = 0;
|
|
|
|
|
2023-01-13 20:32:05 +01:00
|
|
|
/* std::strings get initialized automatically, but this is
|
|
|
|
* in case this function gets called again after construction */
|
2021-09-07 03:56:39 +02:00
|
|
|
script.clear();
|
|
|
|
prompt.clear();
|
2023-01-13 20:32:05 +01:00
|
|
|
|
|
|
|
print_flags = PR_FONT_INTERFACE;
|
2020-01-01 21:29:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void blockclass::rectset(const int xi, const int yi, const int wi, const int hi)
|
|
|
|
{
|
2021-09-07 03:56:39 +02:00
|
|
|
rect.x = xi;
|
|
|
|
rect.y = yi;
|
|
|
|
rect.w = wi;
|
|
|
|
rect.h = hi;
|
2020-01-01 21:29:24 +01:00
|
|
|
}
|
2020-04-04 00:26:19 +02:00
|
|
|
|
2021-09-12 08:15:34 +02:00
|
|
|
void blockclass::setblockcolour(const char* col)
|
2020-04-04 00:26:19 +02:00
|
|
|
{
|
2022-11-21 20:02:38 +01:00
|
|
|
#ifndef NO_CUSTOM_LEVELS
|
|
|
|
if (cl.customcolours.count(col) != 0)
|
|
|
|
{
|
|
|
|
r = cl.customcolours[col].r;
|
|
|
|
g = cl.customcolours[col].g;
|
|
|
|
b = cl.customcolours[col].b;
|
|
|
|
}
|
|
|
|
else // Turn the if into an else if so we don't run the default colour processing
|
|
|
|
#endif
|
2021-09-12 08:15:34 +02:00
|
|
|
if (SDL_strcmp(col, "cyan") == 0)
|
2021-09-07 03:56:39 +02:00
|
|
|
{
|
|
|
|
r = 164;
|
|
|
|
g = 164;
|
|
|
|
b = 255;
|
|
|
|
}
|
2021-09-12 08:15:34 +02:00
|
|
|
else if (SDL_strcmp(col, "red") == 0)
|
2021-09-07 03:56:39 +02:00
|
|
|
{
|
|
|
|
r = 255;
|
|
|
|
g = 60;
|
|
|
|
b = 60;
|
|
|
|
}
|
2021-09-12 08:15:34 +02:00
|
|
|
else if (SDL_strcmp(col, "green") == 0)
|
2021-09-07 03:56:39 +02:00
|
|
|
{
|
|
|
|
r = 144;
|
|
|
|
g = 255;
|
|
|
|
b = 144;
|
|
|
|
}
|
2021-09-12 08:15:34 +02:00
|
|
|
else if (SDL_strcmp(col, "yellow") == 0)
|
2021-09-07 03:56:39 +02:00
|
|
|
{
|
|
|
|
r = 255;
|
|
|
|
g = 255;
|
|
|
|
b = 134;
|
|
|
|
}
|
2021-09-12 08:15:34 +02:00
|
|
|
else if (SDL_strcmp(col, "blue") == 0)
|
2021-09-07 03:56:39 +02:00
|
|
|
{
|
|
|
|
r = 95;
|
|
|
|
g = 95;
|
|
|
|
b = 255;
|
|
|
|
}
|
2021-09-12 08:15:34 +02:00
|
|
|
else if (SDL_strcmp(col, "purple") == 0)
|
2021-09-07 03:56:39 +02:00
|
|
|
{
|
|
|
|
r = 255;
|
|
|
|
g = 134;
|
|
|
|
b = 255;
|
|
|
|
}
|
2021-09-12 08:15:34 +02:00
|
|
|
else if (SDL_strcmp(col, "white") == 0)
|
2021-09-07 03:56:39 +02:00
|
|
|
{
|
|
|
|
r = 244;
|
|
|
|
g = 244;
|
|
|
|
b = 244;
|
|
|
|
}
|
2021-09-12 08:15:34 +02:00
|
|
|
else if (SDL_strcmp(col, "gray") == 0)
|
2021-09-07 03:56:39 +02:00
|
|
|
{
|
|
|
|
r = 174;
|
|
|
|
g = 174;
|
|
|
|
b = 174;
|
|
|
|
}
|
2021-09-12 08:15:34 +02:00
|
|
|
else if (SDL_strcmp(col, "orange") == 0)
|
2021-09-07 03:56:39 +02:00
|
|
|
{
|
|
|
|
r = 255;
|
|
|
|
g = 130;
|
|
|
|
b = 20;
|
|
|
|
}
|
Add `setactivityposition(x,y)`, add new textbox color `transparent` (#847)
* Add `setactivityposition(x,y)`, add new textbox color `transparent`
This commit adds a new internal command as a part of the visual activity zone changes I've been making.
This one allows the user to reposition the activity zone to anywhere on the screen.
In addition, this commit adds the textbox color `transparent`, which just sets r, g and b to 0.
rgb(0, 0, 0) normally creates the color black, however in VVVVVV textboxes, it makes the background
of them invisible, and makes the text the off-white color which the game uses elsewhere.
* add new variables to hardreset
* Fix unwanted text centering; offset position by 16, 4
It makes sense for `setactivityposition(0, 0)` to place the activity zone in the default position,
so the x has been offset by 16, and the y has been offset by 4.
Text was being automatically centered, meaning any activity zone which wasn't centered had misplaced text.
This has been fixed by calculating the center manually, and offsetting it by the passed value.
2021-10-14 00:38:51 +02:00
|
|
|
else if (SDL_strcmp(col, "transparent") == 0)
|
|
|
|
{
|
|
|
|
r = 0;
|
|
|
|
g = 0;
|
|
|
|
b = 0;
|
|
|
|
}
|
2021-09-07 03:56:39 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
//use a gray
|
|
|
|
r = 174;
|
|
|
|
g = 174;
|
|
|
|
b = 174;
|
|
|
|
}
|
2020-04-04 00:26:19 +02:00
|
|
|
}
|