aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrumeet <yuuta@yuuta.moe>2021-11-21 20:44:56 -0800
committerTrumeet <yuuta@yuuta.moe>2021-11-21 20:44:56 -0800
commitd8d478e4346d7f9b106d50728d840b1a171106f4 (patch)
tree3b9dbff28113bab8d1783ad606ab0d3ae39eff1a
parent844dc6a239f3b23cc861b38f0c84f9f7fb7036d8 (diff)
downloadmcal-d8d478e4346d7f9b106d50728d840b1a171106f4.tar
mcal-d8d478e4346d7f9b106d50728d840b1a171106f4.tar.gz
mcal-d8d478e4346d7f9b106d50728d840b1a171106f4.tar.bz2
mcal-d8d478e4346d7f9b106d50728d840b1a171106f4.zip
feat(expexc): support input dimensions and dimensions + positions
-rw-r--r--common.h19
-rw-r--r--expexc.c65
2 files changed, 81 insertions, 3 deletions
diff --git a/common.h b/common.h
index 950c9de..c78bc50 100644
--- a/common.h
+++ b/common.h
@@ -6,7 +6,7 @@
#include <assert.h>
#include <math.h>
-enum val_type { VEC3D, BOX };
+enum val_type { VEC3D, BOX, ENTITY_DIMEN };
struct val {
enum val_type type;
@@ -29,6 +29,12 @@ struct box {
double max_z;
};
+struct entity_dimen {
+ enum val_type type;
+ double width;
+ double height;
+};
+
static inline double *val_get_index(struct val *val, int index)
{
switch (val->type)
@@ -54,6 +60,14 @@ static inline double *val_get_index(struct val *val, int index)
case 5: return &v_box->max_z;
default: assert(0);
}
+ case ENTITY_DIMEN:
+ struct entity_dimen *v_dimen = (struct entity_dimen *)val;
+ switch (index)
+ {
+ case 0: return &v_dimen->width;
+ case 1: return &v_dimen->height;
+ default: assert(0);
+ }
default:
assert(0);
}
@@ -72,6 +86,9 @@ static int val_parse(char *in, struct val *o)
case BOX:
required_vars = 6;
break;
+ case ENTITY_DIMEN:
+ required_vars = 2;
+ break;
}
while (p != NULL)
{
diff --git a/expexc.c b/expexc.c
index 2ca52d3..9a28b31 100644
--- a/expexc.c
+++ b/expexc.c
@@ -15,8 +15,15 @@ int main(int argc, char **argv)
{
goto usage;
usage:
- fprintf(stderr, "Usage: %s minX,minY,minZ,maxX,maxY,maxZ (Bounding box of the target entity)\n"
+ fprintf(stderr, "Usage: %s minX,minY,minZ,maxX,maxY,maxZ\n"
"\n"
+ "Options:\n"
+ "\t-b bounding box\tEntity bounding box. Position dependent. [Mandatory, or -d]"
+ "\t-d dimension\tUse entity dimension instead of bounding box. Note: output is also position independent.\n"
+ "\t-p vec3d\tOptional argument used with -d. Specify the position of the entity so expexc will show the final position dependent destinations. Same effect with -b alone. [Optional, defaults to 0,0,0]\n"
+ "\n"
+ "Bounding box format: minX,minY,minZ,maxX,maxY,maxZ. No spaces or brackets allowed.\n"
+ "Dimension format: width,height. No spaces or brackets allowed.\n"
"Use this tool to simulate the rays to cast for exposure rate calculation.\n"
"Whenever an entity is to be affected by an explosion, Minecraft will cast lots of rays from the explosion center to the target entity to see how many of them are blocked. The percentage of successful casts will be used for acceleration and damage calculation (see expvc(1) -x).\n"
"\n"
@@ -24,7 +31,61 @@ usage:
, argv[0]);
return 64;
}
- if (val_parse(argv[1], (struct val *)&bbox)) goto usage;
+ struct vec3d position = { VEC3D, 0.0, 0.0, 0.0 };
+ struct entity_dimen dimen = { ENTITY_DIMEN, 0.0, 0.0 };
+ int arg_supplied = 0;
+ int use_bbox = 1;
+ for (int i = 1; i < argc; i ++)
+ {
+ const char *arg = argv[i];
+ if (!strcmp("-h", arg)) goto usage;
+ if (i == argc - 1)
+ {
+ fprintf(stderr, "%s requires an argument.\n", arg);
+ goto usage;
+ }
+ char *val = argv[++i];
+ if (!strcmp("-b", arg))
+ {
+ if (arg_supplied ++)
+ {
+ fprintf(stderr, "-d is already supplied. It cannot be used in conjunction with -b.\n");
+ goto usage;
+ }
+ if (val_parse(val, (struct val *)&bbox)) goto usage;
+ }
+ else if (!strcmp("-d", arg))
+ {
+ if (arg_supplied ++)
+ {
+ fprintf(stderr, "-b is already supplied. It cannot be used in conjunction with -d.\n");
+ goto usage;
+ }
+ if (val_parse(val, (struct val *)&dimen)) goto usage;
+ use_bbox = 0;
+ }
+ else if (!strcmp("-p", arg)) { if (val_parse(val, (struct val *)&position)) goto usage; }
+ else
+ {
+ fprintf(stderr, "Unknown option %s.\n", arg);
+ goto usage;
+ }
+ }
+ if (!arg_supplied)
+ {
+ fprintf(stderr, "You must supply -b or -d.\n");
+ goto usage;
+ }
+ if (!use_bbox)
+ {
+ double half_width = dimen.width / 2.0;
+ bbox.min_x = position.x -half_width;
+ bbox.min_y = position.y;
+ bbox.min_z = position.z -half_width;
+ bbox.max_x = position.x + half_width;
+ bbox.max_y = position.y + dimen.height;
+ bbox.max_z = position.z + half_width;
+ }
fprintf(stderr, "Box(%.2f, %.2f, %.2f -> %.2f, %.2f, %.2f)\n",
bbox.min_x,
bbox.min_y,