Skip to content

Instantly share code, notes, and snippets.

@ckarnell
Last active February 27, 2023 01:42
Show Gist options
  • Save ckarnell/d14a4a92d4f484d86e11ff647910d8e2 to your computer and use it in GitHub Desktop.
Save ckarnell/d14a4a92d4f484d86e11ff647910d8e2 to your computer and use it in GitHub Desktop.
#include "modes/PikaPalBattlefield.hpp"
#define ANALOG_STICK_MIN 48
#define ANALOG_STICK_NEUTRAL 128
#define ANALOG_STICK_MAX 208
#define ANALOG_STICK_NEUTRAL_TO_EDGE 80
PikaPalBattlefield::PikaPalBattlefield(socd::SocdType socd_type) : ControllerMode(socd_type) {
_socd_pair_count = 4;
_socd_pairs = new socd::SocdPair[_socd_pair_count]{
socd::SocdPair{&InputState::left, &InputState::right },
socd::SocdPair{ &InputState::down, &InputState::up },
socd::SocdPair{ &InputState::c_left, &InputState::c_right},
socd::SocdPair{ &InputState::c_down, &InputState::c_up },
};
horizontal_socd = false;
}
void PikaPalBattlefield::HandleSocd(InputState &inputs) {
horizontal_socd = inputs.left && inputs.right;
InputMode::HandleSocd(inputs);
}
void PikaPalBattlefield::UpdateDigitalOutputs(InputState &inputs, OutputState &outputs) {
outputs.a = inputs.a;
outputs.b = inputs.b;
outputs.x = inputs.x;
outputs.y = inputs.y;
outputs.buttonR = inputs.z;
if (inputs.nunchuk_connected) {
outputs.triggerLDigital = inputs.nunchuk_z;
} else {
outputs.triggerLDigital = inputs.l;
}
outputs.triggerRDigital = inputs.r;
outputs.start = inputs.start;
// Activate D-Pad layer by holding Mod X + Mod Y + Nunchuk C button.
if (inputs.mod_x && inputs.mod_y && inputs.nunchuk_c) {
outputs.dpadUp = inputs.c_up;
outputs.dpadDown = inputs.c_down;
outputs.dpadLeft = inputs.c_left;
outputs.dpadRight = inputs.c_right;
}
if (inputs.select)
outputs.dpadLeft = true;
if (inputs.home)
outputs.dpadRight = true;
}
void PikaPalBattlefield::UpdateAnalogOutputs(InputState &inputs, OutputState &outputs) {
// Coordinate calculations to make modifier handling simpler.
UpdateDirections(
inputs.left,
inputs.right,
inputs.down,
inputs.up,
inputs.c_left,
inputs.c_right,
inputs.c_down,
inputs.c_up,
ANALOG_STICK_MIN,
ANALOG_STICK_NEUTRAL,
ANALOG_STICK_MAX,
outputs
);
bool shield_button_pressed = inputs.l || inputs.r || inputs.lightshield || inputs.midshield;
bool mod1 = inputs.mod_x;
bool mod2 = inputs.mod_y;
bool mod3 = inputs.nunchuk_c;
bool mod4 = mod1 && mod2;
bool mod5 = mod1 && mod3;
bool mod6 = mod2 && mod3;
bool mod7 = inputs.b && inputs.x;
if (directions.diagonal) {
// L, R, LS, and MS + q1/2 = 7000 7000
outputs.leftStickX = 128 + (directions.x * 56);
outputs.leftStickY = 128 + (directions.y * 56);
// L, R, LS, and MS + q3/4 = 7000 6875 (For vanilla shield drop. Gives 44.5
// degree wavedash).
if (directions.y == -1 && shield_button_pressed) {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.7); // TODO: Test
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.7125); // TODO: Test
}
}
if (mod1) {
if (inputs.b) {
if (directions.horizontal) {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.65);
}
if (directions.vertical) {
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.65);
}
if (directions.diagonal) {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.85);
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.5125);
}
} else {
if (directions.horizontal) {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.65);
}
if (directions.vertical) {
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.8750);
}
if (directions.diagonal) {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.9);
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.4);
}
}
}
if (mod2) {
if (inputs.b) {
if (directions.horizontal) {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.9250);
}
if (directions.vertical) {
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.9250);
}
if (directions.diagonal) {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.4);
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.9);
}
} else {
if (directions.horizontal) {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.8);
}
if (directions.vertical) {
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.8);
}
if (directions.diagonal) {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.2875);
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.9500);
}
}
}
if (mod3) {
if (inputs.b) {
if (directions.horizontal) {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.2875);
}
if (directions.vertical) {
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.55);
}
if (directions.diagonal) {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.5125);
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.85);
}
} else {
if (directions.horizontal) {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.2875);
}
if (directions.vertical) {
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.2875);
}
if (directions.diagonal) {
if (directions.y == -1) {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.625);
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.4);
} else {
if (directions.x == -1) {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.3125);
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.5375);
}
else {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.2875);
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.35);
}
}
}
}
}
if (mod4) {
if (inputs.b) {
if (directions.horizontal) {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.5125);
}
if (directions.vertical) {
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.5125);
}
if (directions.diagonal) {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.7875);
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.6125);
}
} else {
// if (directions.horizontal) {
// outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0);
// }
// if (directions.vertical) {
// outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0);
// }
// if (directions.diagonal) {
// if (directions.y == -1) {
// outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0);
// outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0);
// } else {
// if (directions.x == -1) {
// outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0);
// outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0);
// }
// else {
// outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0);
// outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0);
// }
// }
// }
}
}
if (mod5) {
if (inputs.b) {
if (directions.horizontal) {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.775);
}
if (directions.vertical) {
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.775);
}
if (directions.diagonal) {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.95);
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.2875);
}
} else {
// if (directions.horizontal) {
// outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0);
// }
// if (directions.vertical) {
// outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0);
// }
// if (directions.diagonal) {
// if (directions.y == -1) {
// outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0);
// outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0);
// } else {
// if (directions.x == -1) {
// outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0);
// outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0);
// }
// else {
// outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0);
// outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0);
// }
// }
// }
}
}
if (mod6) {
if (inputs.b) {
if (directions.horizontal) {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.5);
}
if (directions.vertical) {
if (directions.y == -1) {
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.5);
} else {
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.5125);
}
}
if (directions.diagonal) {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.6125);
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.7875);
}
} else {
// if (directions.horizontal) {
// outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0);
// }
// if (directions.vertical) {
// outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0);
// }
// if (directions.diagonal) {
// if (directions.y == -1) {
// outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0);
// outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0);
// } else {
// if (directions.x == -1) {
// outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0);
// outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0);
// }
// else {
// outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0);
// outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0);
// }
// }
// }
}
}
if (mod7) {
if (directions.horizontal) {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.85);
}
if (directions.vertical) {
if (directions.y == -1) {
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.85);
} else {
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 1.0);
}
}
if (directions.diagonal) {
if (directions.y == -1) {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.7625);
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.6);
} else {
if (directions.x == -1) {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.5);
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.75);
} else {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.5625);
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.825);
}
}
}
if (mod1) {
if (directions.horizontal) {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.65);
}
if (directions.vertical) {
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.65);
}
if (directions.diagonal) {
if (directions.y == -1) {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.4875);
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.5125);
} else {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.8875);
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.45);
}
}
} else if (mod2) {
if (directions.horizontal) {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.9);
}
if (directions.vertical) {
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.9);
}
if (directions.diagonal) {
if (directions.y == -1) {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.7625);
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.6);
} else {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.5625);
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.825);
}
}
} else if (mod3) {
if (directions.horizontal) {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.55);
}
if (directions.vertical) {
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.55);
}
if (directions.diagonal) {
if (directions.y == -1) {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.85);
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.525);
} else {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.6875);
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.45);
}
}
}
if (mod4) {
if (directions.horizontal) {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.7875);
}
if (directions.vertical) {
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.7875);
}
if (directions.diagonal) {
if (directions.y == -1) {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.675);
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.4);
} else {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.8875);
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.45);
}
}
} else if (mod5) {
if (directions.horizontal) {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.775);
}
if (directions.vertical) {
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.775);
}
if (directions.diagonal) {
if (directions.y == -1) {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.95);
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.2875);
} else {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.425);
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.5375);
}
}
} else if (mod6) {
if (directions.horizontal) {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.5);
}
if (directions.vertical) {
if (directions.y == -1) {
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.5);
} else {
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.5125);
}
}
if (directions.diagonal) {
if (directions.y == -1) {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.7875);
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.6125);
} else {
outputs.leftStickX = 128 + (directions.x * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.9125);
outputs.leftStickY = 128 + (directions.y * ANALOG_STICK_NEUTRAL_TO_EDGE * 0.4);
}
}
}
}
// // C-stick ASDI Slideoff angle overrides any other C-stick modifiers (such as
// // angled fsmash).
// if (directions.cx != 0 && directions.cy != 0) {
// // 5250 8500 = 42 68
// outputs.rightStickX = 128 + (directions.cx * 42);
// outputs.rightStickY = 128 + (directions.cy * 68);
// }
// // Horizontal SOCD overrides X-axis modifiers (for ledgedash maximum jump
// // trajectory).
// if (horizontal_socd && !directions.vertical) {
// outputs.leftStickX = 128 + (directions.x * 80);
// }
if (inputs.lightshield) {
outputs.triggerRAnalog = 49;
}
if (inputs.midshield) {
outputs.triggerRAnalog = 94;
}
if (outputs.triggerLDigital) {
outputs.triggerLAnalog = 140;
}
if (outputs.triggerRDigital) {
outputs.triggerRAnalog = 140;
}
// Shut off c-stick when using dpad layer.
if (inputs.mod_x && inputs.mod_y && inputs.nunchuk_c) {
outputs.rightStickX = 128;
outputs.rightStickY = 128;
}
// // Nunchuk overrides left stick.
// if (inputs.nunchuk_connected) {
// outputs.leftStickX = inputs.nunchuk_x;
// outputs.leftStickY = inputs.nunchuk_y;
// }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment