MCPcopy Index your code
hub / github.com/NetHack/NetHack / l_selection_gradient

Function l_selection_gradient

src/nhlsel.c:861–915  ·  view source on GitHub ↗

Gradients are versatile enough, with so many independently optional * arguments, that it doesn't seem helpful to provide a non-table form with * non-obvious argument order. */ selection.gradient({ type = "radial", x = 3, y = 5, x2 = 10, y2 = 12, * mindist = 4, maxdist = 10, limited = false }); */

Source from the content-addressed store, hash-verified

859/* selection.gradient({ type = "radial", x = 3, y = 5, x2 = 10, y2 = 12,
860 * mindist = 4, maxdist = 10, limited = false }); */
861staticfn int
862l_selection_gradient(lua_State *L)
863{
864 int argc = lua_gettop(L);
865 struct selectionvar *sel = (struct selectionvar *) 0;
866 /* if x2 and y2 aren't set, the gradient has a single center point of x,y;
867 * if they are set, the gradient is centered on a (x,y) to (x2,y2) line */
868 coordxy x = 0, y = 0, x2 = -1, y2 = -1;
869 /* points are always added within mindist of the center; the chance for a
870 * point between mindist and maxdist to be added to the selection starts
871 * at 100% at mindist and decreases linearly to 0% at maxdist */
872 coordxy mindist = 0, maxdist = 0;
873 long type = 0;
874 static const char *const gradtypes[] = {
875 "radial", "square", NULL
876 };
877 static const int gradtypes2i[] = {
878 SEL_GRADIENT_RADIAL, SEL_GRADIENT_SQUARE, -1
879 };
880
881 if (argc == 1 && lua_type(L, 1) == LUA_TTABLE) {
882 lcheck_param_table(L);
883 type = gradtypes2i[get_table_option(L, "type", "radial", gradtypes)];
884 x = (coordxy) get_table_int(L, "x");
885 y = (coordxy) get_table_int(L, "y");
886 x2 = (coordxy) get_table_int_opt(L, "x2", -1);
887 y2 = (coordxy) get_table_int_opt(L, "y2", -1);
888 cvt_to_abscoord(&x, &y);
889 cvt_to_abscoord(&x2, &y2);
890 /* maxdist is required because there's no obvious default value for
891 * it, whereas mindist has an obvious default of 0 */
892 maxdist = get_table_int(L, "maxdist");
893 mindist = get_table_int_opt(L, "mindist", 0);
894
895 lua_pop(L, 1);
896 (void) l_selection_new(L);
897 sel = l_selection_check(L, 1);
898 } else {
899 nhl_error(L, "selection.gradient requires table argument");
900 /* NOTREACHED */
901 }
902
903 /* someone might conceivably want to draw a gradient somewhere off-map. So
904 * the only coordinate that's "illegal" for that is (-1,-1).
905 * If a level designer really needs to draw a gradient line using that
906 * coordinate, they can do so by setting regular x and y to -1. */
907 if (x2 == -1 && y2 == -1) {
908 x2 = x;
909 y2 = y;
910 }
911
912 selection_do_gradient(sel, x, y, x2, y2, type, mindist, maxdist);
913 lua_settop(L, 1);
914 return 1;
915}
916
917DISABLE_WARNING_UNREACHABLE_CODE
918

Callers

nothing calls this directly

Calls 9

lcheck_param_tableFunction · 0.85
get_table_optionFunction · 0.85
get_table_intFunction · 0.85
get_table_int_optFunction · 0.85
cvt_to_abscoordFunction · 0.85
l_selection_newFunction · 0.85
l_selection_checkFunction · 0.85
nhl_errorFunction · 0.85
selection_do_gradientFunction · 0.85

Tested by

no test coverage detected