Skip to content

Instantly share code, notes, and snippets.

@Xane123
Created June 28, 2018 05:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xane123/d0b0626158646d84135aff9e0fa8c256 to your computer and use it in GitHub Desktop.
Save Xane123/d0b0626158646d84135aff9e0fa8c256 to your computer and use it in GitHub Desktop.
Mary's Magical Adventure upgrade menu source (from COMMON2.acs)
////////////
//UPGRADES//
////////////
script "DetermineWUpgradeSpawn" (int spec_id)
{
bool can_spawn[3]; //Stores whether weapon upgrades, health upgrades, and jump height upgrades can spawn here.
If(special_id[spec_id]==FALSE&&challenge[0]==0)
{ //Upgrades will only spawn if the player hasn't already picked up the upgrade.
int thing_id = UniqueTID(900,100);
If(thing_id==0) { Log(s:"A unique thing ID couldn't be determined. Aborting upgrade spawn."); Terminate; }
If(PlayerClass(0)==CHAR_SCALETEST) { Log(s:"Scale test detected!"); Terminate; }
//First, determine what is able to spawn.
If(!AllUpgrades(0)) can_spawn[0] = TRUE; //Allow weapon upgrade spawns if the player doesn't have all of them.
If(upgrades[21]==FALSE) can_spawn[1] = TRUE; //Allow health upgrades.
If(upgrades[22]==FALSE) can_spawn[2] = TRUE; //Allow jump height upgrades.
PrintBold(d:can_spawn[0], s:"/", d:can_spawn[1], s:"/", d:can_spawn[2]);
If((can_spawn[0]==TRUE&&can_spawn[1]==FALSE&&can_spawn[2]==FALSE)||(can_spawn[0]==FALSE&&can_spawn[1]==TRUE&&can_spawn[2]==FALSE)||(can_spawn[0]==FALSE&&can_spawn[1]==FALSE&&can_spawn[2]==TRUE)) { } //If only one can spawn, don't bother deciding.
Else If(Random(-2,2)<=0 && can_spawn[0]==TRUE)
{
can_spawn[1] = FALSE; //The others can no longer spawn!
can_spawn[2] = FALSE;
}
Else If(can_spawn[1]==TRUE||can_spawn[2]==TRUE)
{
can_spawn[0] = FALSE; //Can't spawn weapon upgrades if it lost the random chance!
If(can_spawn[1]==TRUE&&can_spawn[2]==TRUE)
{
//If(Random(0,32)>28) can_spawn[2] = FALSE; //At random, the health upgrade may appear.
//Else can_spawn[1] = FALSE; //Most of the time, it won't appear due to the big bias against it.
can_spawn[Random(1,2)] = FALSE;
}
}
PrintBold(s:"Decided on:\n", d:can_spawn[0], s:"/", d:can_spawn[1], s:"/", d:can_spawn[2]);
If(can_spawn[0]==TRUE) Spawn("PowerupWeapon",GetActorX(0),GetActorY(0),GetActorZ(0),thing_id,0);
Else If(can_spawn[1]==TRUE) Spawn("PowerupHealth",GetActorX(0),GetActorY(0),GetActorZ(0),thing_id,0);
Else Spawn("PowerupJump",GetActorX(0),GetActorY(0),GetActorZ(0),thing_id,0);
GiveActorInventory(thing_id,"Variable1",spec_id); //Transfer the special ID to the upgrade object so it knows what to mark should it be picked up.
Thing_ChangeTID(thing_id,0); //Remove its thing ID afterwards so other objects can use it.
}
Thing_Remove(0); //After spawning the upgrade, remove the dummy spawner object.
}
script "Upgrade_MarkSpecialID" (int spec_id) { If(spec_id==0) special_id[CheckInventory("Variable1")] = TRUE; Else special_id[spec_id] = TRUE; } //This is used by upgrade objects to mark themselves as "collected".
script "Upgrade_CheckValidity" (int upgrade_type, int spec_id) //The "upgrade type" here is the same as the upgrade[] array.
{ //Returns FALSE if this upgrade is no longer needed. If it's TRUE, it can stay.
//If the upgrade was previously picked up or if the player has all weapon upgrades, then disappear!
If(special_id[spec_id]==TRUE || (upgrade_type==0 && AllUpgrades(0))) SetResultValue(FALSE);
Else SetResultValue(TRUE);
}
//The menu that appears upon collecting an upgrade.
script "UpgradeMenu" (void)
{
int xlist[20] = { 78.1, 78.1, 78.1, 78.1, //X coordinates for each upgrade.
78.1, 78.1, 78.1, 78.1,
78.1, 78.1, 78.1, 78.1,
218.1, 218.1, 218.1, 218.1,
218.1, 218.1, 218.1, 218.1 };
int ylist[20] = { 93.0, 102.0, 111.0, 120.0, //Y coordinates for each upgrade.
148.0, 156.0, 164.0, 172.0,
200.0, 209.0, 218.0, 227.0,
148.0, 156.0, 164.0, 172.0,
200.0, 209.0, 218.0, 227.0 };
int selected = 0, color = CR_YELLOW, direction = 0; //-1 = backward, 0 = no movement, 1 = forward
str text; //What text to use for each upgrade in the menu.
bool awaiting_release = FALSE; //This is TRUE after forward/backward input is given to the game.
If(AllUpgrades(0)) Terminate; //If all upgrades were obtained, don't let this menu appear!
selected = AttemptMenuMovement(selected, selected+1, TRUE); //If the first upgrade can't be selected, choose a later one.
SetHUDSize(427, 320, FALSE);
Until(no_scripts[PlayerNumber()]==FALSE) Delay(1); //Wait until no script-blocking is in effect.
FadeTo(0,0,0,1.0,0.25);
Delay(12);
GiveInventory("Cutscene",1); //Freeze everything during the menu.
no_scripts[PlayerNumber()] = TRUE; //Freeze the combo meter and disable common scripts.
important_fade[PlayerNumber()] = TRUE; //Prevent active powerup coins from breaking this effect.
FadeTo(96,64,128,1.0,0.5);
SetFont("UPGRADBG");
HUDMessage (s:"A";
HUDMSG_FADEINOUT, 80, CR_UNTRANSLATED, 214.0,160.0, 1.0, 0.5, 0.0);
SetFont("UPGRADHD");
For(int pos_head = 480.0; pos_head > 40.0; pos_head -= 32.0)
{ //Quickly move this text to the top of the screen as the background fades in.
HUDMessage (s:"A";
HUDMSG_FADEOUT, 39, CR_WHITE, 214.0,0.0+pos_head, 0.0, 0.1, 0.0);
Delay(1);
}
Until(selected>=50)
{
If(movement[PlayerNumber()]>0&&!awaiting_release) { direction = 1; awaiting_release = TRUE; }
Else If(movement[MAX_PLAYERS+PlayerNumber()]>0&&!awaiting_release) { direction = -1; awaiting_release = TRUE; }
If(direction==1) selected = AttemptMenuMovement(selected, selected-1, FALSE);
Else If(direction==-1) selected = AttemptMenuMovement(selected, selected+1, FALSE);
direction = 0; //Disable movement once it's done.
Delay(1); //Wait then render the menu. If player released movement, unlock it.
If(awaiting_release&&movement[PlayerNumber()]==0&&movement[MAX_PLAYERS+PlayerNumber()]==0) awaiting_release = FALSE;
If(!awaiting_release&&openInput[PlayerNumber()] & (BT_USE|BT_JUMP|BT_ATTACK|BT_ALTATTACK|BT_USER2)) selected += 50;
//Render the menu proper next.
SetFont("UPGRADBG");
HUDMessage (s:"A";
HUDMSG_FADEOUT, 80, CR_UNTRANSLATED, 214.0,160.0, 0.0, 0.25);
SetFont("UPGRADHD");
HUDMessage (s:"A";
HUDMSG_FADEOUT, 39, CR_UNTRANSLATED, 214.0,40.0, 0.0, 0.25);
SetFont("CONFONT");
For(int i1 = 0; i1 < 20; i1++)
{
text = StrParam(l:StrParam(s:"UPGRADE_", d:i1+(PlayerClass(PlayerNumber())*20)));
If(UpgradeSelectable(i1)) color = CR_YELLOW;
Else { color = CR_GRAY; If(!HasWeapon(i1/4)) text = "?????"; }
HUDMessage (s:text;
HUDMSG_FADEOUT, 59-i1, color, xlist[i1]+8.0,ylist[i1], 0.0, 0.25);
}
For(int i2 = 0; i2 < 20; i2++)
{
If(i2==selected) SetFont("MENULIT3"); //Yellow
Else If(HasWeapon(i2/4)&&i2%4==3&&(upgrades[i2-1]==FALSE||upgrades[i2-2]==FALSE||upgrades[i2-3]==FALSE)) SetFont("MENULIT1"); //Red
Else If(HasWeapon(i2/4)) SetFont("MENULIT2"); //Green
Else If(!HasWeapon(i2/4)) SetFont("MENULIT0"); //Grey
HUDMessage (s:"A";
HUDMSG_FADEOUT, 79-i2, CR_YELLOW, xlist[i2],ylist[i2], 0.0, 0.255);
}
}
HUDMessage (l:StrParam(s:"UPGRADE_", d:((selected-50)+PlayerClass(PlayerNumber())*20), s:"_DESCRIPTION");
HUDMSG_FADEOUT, 38, CR_UNTRANSLATED, 214.0,240.0, 0.0, 0.25);
FadeTo(255,255,255,1.0,0.25);
Delay(12);
selected -= 50;
TakeInventory("PowerTimeFreezer",1); //Allow enemies to move again.
no_scripts[PlayerNumber()] = FALSE; //Allow scripts again.
ACS_NamedExecute("GiveUpgrade",0,selected,0,0); //Give the player the upgrade they selected.
FadeTo(255,255,255,0.0,0.25);
important_fade[PlayerNumber()] = FALSE; //Allow screen tinting by Powerup Coins again.
}
script "CheckUpgrade" (int weaponslot, int upgrade)
{ //Locates and uses the correct weapon upgrade from the array.
If(weaponslot<=0) { Log(s:"Use the weapon slot number associated with the weapon, not 0-based!"); Terminate; }
If(upgrade<=0) { Log(s:"WHICH upgrade? Remember, it isn't 0-based here!"); Terminate; }
weaponslot--; upgrade--;
If(upgrade>=4) upgrade = 3;
SetResultValue(upgrades[(weaponslot*4)+upgrade]);
}
function int AttemptMenuMovement (int current, int next, int initial) //Initial means the current position isn't treated as "valid" used when first loading the menu.
{ //Scans upgrades to check for validity. Returns next menu item to jump to.
int original = current; //Save the current upgrade array index into a different variable. It changes purpose next.
bool direction, valid = FALSE, initial_orig; //Initial_detection is for forcing the description to appear when menu first appears.
initial_orig = initial; //Store the "initial" variable for use later.
//Determine which direction the player is trying to move.
If(current<next) direction = TRUE; //Going right/forward
else direction = FALSE; //Going left/backward
Until(valid)
{ //If the player has this weapon and doesn't have this upgrade, it's valid.
If(UpgradeSelectable(current)&&initial) valid = TRUE;
Else
{
initial = TRUE; //After a "movement", the next value can be accepted as the new value, even if the initial menu movement.
If(direction==TRUE) current++;
Else current--;
//Log(d:current);
If(current>20||current<0) { current = -1; valid = TRUE; }
}
}
if(current>=0&&current<=19&&(current!=original||initial_orig))
{
SetHUDSize(427, 320, FALSE);
SetFont("3DLETTER");
HUDMessage (l:StrParam(s:"UPGRADE_", d:current, s:"_DESCRIPTION");
HUDMSG_TYPEON, 38, CR_UNTRANSLATED, 214.0,256.0, 60.0, 0.03, 1.0);
}
If(current>=0&&current<=19) original = current; //Only return a different index if it's valid.
return original; //Return the new index. If invalid, this just returns the same number.
}
function int UpgradeSelectable (int x)
{
If(upgrades[x]==FALSE&&HasWeapon(x/4)&&((x%4!=3)||(x%4==3&&upgrades[x-1]==TRUE&&upgrades[x-2]==TRUE&&upgrades[x-3]==TRUE))) x = TRUE;
Else x = FALSE; //Check the many conditions above. If they are all valid, return TRUE. Else, return FALSE.
return x;
}
function int IsCharacter (int x) //Returns TRUE if any player is using the character specified.
{
int class = x; //Store the requested player class into "class" as it changes purposes to TRUE/FALSE next.
x = FALSE; //By default, this function returns FALSE. If any player is using "class", it becomes TRUE.
For(int i = 0; i < PlayerCount(); i++) If(PlayerClass(i)==class) x = TRUE;
return x; //Return TRUE/FALSE.
}
function int AllUpgrades (int x) //Returns TRUE if all possible upgrades are owned by players. Mary and Xane share upgrade "slots" 0-19.
{
bool check = TRUE; //If this is TRUE, the "for" loop will actually check the array index.
int total = 20; //What number of TRUE returns are needed for all upgrades to be considered collected.
int counter = 0; //Increases each time an upgrade is checked successfully.
x = FALSE; //By default, this function returns FALSE. It becomes TRUE if the player is proven to have all of 'em.
For(int i = 0; i < 20; i++)
{ //Scan each upgrade array index. If one is collected, add to the counter.
check = TRUE; //Check the array index if the player has the weapon...
//Log(s:"Currently on ", d:i, s:".");
If(i % 4 == 0 && !HasWeapon(i/4))
{ //Every four upgrades is another weapon, so check here for if the player even has the weapon(s)!
i += 3; //Unsure about if this needs to be increased by three or four.
total -= 4; //Well, that's four less upgrades required.
check = FALSE; //Skip the check.
//Log(s:"Skipped weapon #", d:i/4, s:"! Now on index ", d:i, s:"! Total is now ", d:total, s:".");
}
If(check && upgrades[i]==TRUE) counter++;
}
If(counter>=total) x = TRUE; //Success, all collected!
return x; //Return TRUE/FALSE.
}
function int HasWeapon (int x) //Returns TRUE if the player has this weapon number.
{ //0-2: Normal weapons, 3: Super weapon, 4: Secret weapon
str WeaponClasses[10] = { "MaryUmbrella", "MaryHammer", "MaryWeapon3", "MaryWand", "MaryWeaponSecret",
"XaneSword", "XaneHammer", "XaneWeapon3", "XaneWeaponSuper", "XaneWeaponSecret" };
int which = x; //Store this in "which" as the weapon number variable is about to be repurposed.
x = FALSE; //This is now repurposed for the TRUE/FALSE this function returns.
For(int i = 0; i < PlayerCount(); i++)
{ //See if the player has Mary or Xane's weapon in this slot. If ANY player has it, this will return TRUE.
If(CheckActorInventory(1000+i,WeaponClasses[which])||CheckActorInventory(1000+i,WeaponClasses[which+5])) x = TRUE; }
return x; //Once this is done, return the result.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment