Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "zcommon.acs"
- #include "commonFuncs.h"
- #define STRALLOC_INPUTSTRING 192
- #define STRALLOC_INPUTHELP 193
- #define INPUTIDBASE 29050
- #define INPUTCHARS 95
- global int 0:strings[];
- global int 9:stringIndex[];
- int vInputChars[INPUTCHARS] = {97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 58, 59, 60, 61, 62, 63, 64, 91, 92, 93, 94, 95, 96, 123, 124, 125, 126, 32};
- int vOutputChars[128] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 94, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 77, 78, 79, 80, 81, 82, 83, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 84, 85, 86, 87, 88, 89, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 90, 91, 92, 93, -1};
- int inputLock[32] = {0};
- function int addString(int string)
- {
- int strSize = StrLen(string) + 1; // gotta remember the null byte at the start
- int index = 0; int ret; int i = 0; int j; int c;
- int wIndex = findFreeIndex(strSize);
- for (i = 0; i < strSize; i++)
- {
- j = i + wIndex;
- strings[j] = GetChar(string, i);
- }
- strings[j + i] = 0;
- addIndex(wIndex);
- return wIndex;
- }
- function int addCleanString(int string)
- {
- int strSize = StrLen(string) + 1;
- int index = 0; int i = 0; int j = 0; int k = 0; int c; int ignoreNext;
- int wIndex = findFreeIndex(strSize);
- for (i = 0; i < strSize; i++)
- {
- c = GetChar(string, i);
- if ( ( ((c > 8) && (c < 14)) || ((c > 31) && (c < 127)) || ((c > 160) && (c < 173)) ) && !ignoreNext)
- {
- j = (k++) + wIndex;
- strings[j] = c;
- }
- else if (c == 28 && !ignoreNext)
- {
- ignoreNext = 1;
- }
- else
- {
- ignoreNext = 0;
- }
- }
- strings[j + 1] = 0;
- addIndex(wIndex);
- return wIndex;
- }
- function int addLowerString(int string)
- {
- int strSize = StrLen(string) + 1;
- int index = 0; int i = 0; int j = 0; int k = 0; int c; int ignoreNext;
- int wIndex = findFreeIndex(strSize);
- for (i = 0; i < strSize; i++)
- {
- c = GetChar(string, i);
- if ( ( ((c > 8) && (c < 14)) || ((c > 31) && (c < 127)) || ((c > 160) && (c < 173)) ) && !ignoreNext)
- {
- j = (k++) + wIndex;
- if ((c > 64) && (c < 91))
- {
- strings[j] = c + 32;
- }
- else
- {
- strings[j] = c;
- }
- }
- else if (c == 28 && !ignoreNext)
- {
- ignoreNext = 1;
- }
- else
- {
- ignoreNext = 0;
- }
- }
- strings[j + 1] = 0;
- addIndex(wIndex);
- return wIndex;
- }
- function int getString(int index)
- {
- int ret = "";
- int i = 0; int j; int c;
- if (getIndex(index) == -1)
- {
- return StrParam(s:"ERR");
- }
- while (1)
- {
- j = i + index;
- i += 1;
- c = strings[j];
- if (c == 0)
- {
- break;
- }
- ret = StrParam(s:ret, c:c);
- }
- return ret;
- }
- function void freeString(int index)
- {
- int i = 0; int j; int c;
- if (getIndex(index) == -1)
- {
- return;
- }
- while (1)
- {
- j = i + index;
- c = strings[j];
- if (c == 0)
- {
- break;
- }
- strings[j] = 0;
- i += 1;
- }
- freeIndex(index);
- }
- function int stringLength(int index)
- {
- int i = 0; int j; int c;
- if (getIndex(index) == -1)
- {
- return -1;
- }
- while (1)
- {
- j = i + index;
- c = strings[j];
- if (c == 0)
- {
- break;
- }
- i += 1;
- }
- return i;
- }
- function int reallocString(int index, int string)
- {
- freeString(index);
- return addString(string);
- }
- function int reallocCleanString(int index, int string)
- {
- freeString(index);
- return addCleanString(string);
- }
- function int reallocLowerString(int index, int string)
- {
- freeString(index);
- return addLowerString(string);
- }
- function int findFreeIndex(int size)
- {
- int c; int i = -1; int index = 0; int ret;
- while (1)
- {
- c = strings[index];
- if (c == 0)
- {
- if (i == 0)
- {
- ret = index;
- }
- i += 1;
- }
- else
- {
- i = -1;
- }
- if (i >= (size - 1))
- {
- break;
- }
- index += 1;
- }
- return ret;
- }
- function int addIndex(int index)
- {
- int i = 0;
- while (1)
- {
- if (stringIndex[i] == (index + 1))
- {
- break;
- }
- else if (stringIndex[i] == 0)
- {
- stringIndex[i] = (index + 1);
- break;
- }
- i += 1;
- }
- return i;
- }
- function int getIndex(int index)
- {
- int i = 0;
- while (1)
- {
- if (stringIndex[i] == (index + 1))
- {
- break;
- }
- else if (stringIndex[i] == 0)
- {
- return -1;
- }
- i += 1;
- }
- return i;
- }
- function void freeIndex(int index)
- {
- int curIndex = getIndex(index);
- if (curIndex == -1)
- {
- return;
- }
- int i = curIndex + 1;
- int j = i;
- stringIndex[curIndex] = 0;
- while (1)
- {
- if (stringIndex[i] == 0)
- {
- break;
- }
- j = i;
- i += 1;
- }
- stringIndex[curIndex] = stringIndex[j];
- stringIndex[j] = 0;
- }
- function int dumpStrings(int stop)
- {
- int printStr = "";
- int i = 0; int strsFound = 0; int stopAtZero = 0;
- if (stop == 0)
- {
- stop = 0x7FFFFFFF;
- stopAtZero = 1;
- }
- while (i < stop)
- {
- if (stringIndex[i] != 0)
- {
- strsFound++;
- printStr = StrParam(s:printStr, s:"(", d:i, s:", ", d:stringIndex[i], s:"): ", s:getString(stringIndex[i] - 1), s:"\n");
- }
- else if (stopAtZero)
- {
- break;
- }
- i += 1;
- }
- if (strsFound == 0)
- {
- printStr = StrParam(s:"<NONE>"); // For consistency reasons, we use StrParam here
- }
- return printStr;
- }
- function int padStringR(int baseStr, int padChar, int len)
- {
- int baseStrLen = StrLen(baseStr);
- int pad = "";
- int padLen; int i;
- if (baseStrLen >= len)
- {
- return baseStr;
- }
- padChar = GetChar(padChar, 0);
- padLen = len - baseStrLen;
- for (i = 0; i < padLen; i++)
- {
- pad = StrParam(s:pad, c:padChar);
- }
- return StrParam(s:baseStr, s:pad);
- }
- function int padStringL(int baseStr, int padChar, int len)
- {
- int baseStrLen = StrLen(baseStr);
- int pad = "";
- int padLen; int i;
- if (baseStrLen >= len)
- {
- return baseStr;
- }
- padChar = GetChar(padChar, 0);
- padLen = len - baseStrLen;
- for (i = 0; i < padLen; i++)
- {
- pad = StrParam(s:pad, c:padChar);
- }
- return StrParam(s:pad, s:baseStr);
- }
- function int changeString(int string, int repl, int where)
- {
- int i; int j; int k;
- int ret = "";
- int len = StrLen(string);
- int rLen = StrLen(repl);
- if ((where + rLen < 0) || (where >= len))
- {
- return string;
- }
- for (i = 0; i < len; i++)
- {
- if (inRange(where, where+rLen, i))
- {
- ret = StrParam(s:ret, c:GetChar(repl, i-where));
- }
- else
- {
- ret = StrParam(s:ret, c:GetChar(string, i));
- }
- }
- return ret;
- }
- function int sliceString(int string, int start, int end)
- {
- int len = StrLen(string);
- int ret = "";
- int i;
- if (start < 0)
- {
- start = len + start;
- }
- if (end <= 0)
- {
- end = len + end;
- }
- start = max(0, start);
- end = min(end, len-1);
- for (i = start; i < end; i++)
- {
- ret = StrParam(s:ret, c:GetChar(string, i));
- }
- return ret;
- }
- script STRALLOC_INPUTSTRING (int maxLength, int cStr, int prompt)
- {
- int cCharIndex = 0;
- int cChar = vInputChars[cCharIndex];
- int cStrIndex = 0;
- int pStr; int pStr2; int pStrLen;
- int pChar; int pCharStr;
- int yawBuffer;
- int yawOverflow;
- int letterShift;
- int pitchBuffer;
- int pitchOverflow;
- int charShift;
- int hudWidth; int cenWidth;
- int hudHeight; int cenHeight;
- int update; int tic = 0;
- int cStrTmp;
- int pln = PlayerNumber();
- if (pln == -1)
- {
- terminate;
- }
- if (inputLock[pln] == 1)
- {
- terminate;
- }
- inputLock[pln] = 1;
- SetPlayerProperty(0, 1, PROP_TOTALLYFROZEN);
- if (cStr == 0)
- {
- cStr = addString("");
- }
- else
- {
- cStr = addString(cStr);
- cStrTmp = getString(cStr);
- cCharIndex = GetChar(cStrTmp, cStrIndex);
- cCharIndex = vOutputChars[cCharIndex];
- }
- maxLength = max(0, maxLength);
- if (maxLength == 0)
- {
- maxLength = 32;
- }
- hudWidth = max(320, 10 * maxLength);
- hudHeight = hudWidth - (hudWidth >> 2);
- cenWidth = (hudWidth << 15) + 0.4;
- cenHeight = (hudHeight << 15);
- SetHudSize(hudWidth, hudHeight, 1);
- SetFont("CONFONT");
- while (1)
- {
- letterShift = 0;
- charShift = 0;
- if (keyPressed(BT_MOVERIGHT) || keyPressed(BT_RIGHT) || keyPressed(BT_ATTACK))
- {
- letterShift++;
- }
- else if (keyPressed(BT_MOVELEFT) || keyPressed(BT_LEFT) || keyPressed(BT_ALTATTACK))
- {
- letterShift--;
- }
- if (keyPressed(BT_FORWARD))
- {
- charShift++;
- }
- else if (keyPressed(BT_BACK))
- {
- charShift--;
- }
- pitchBuffer += GetPlayerInput(-1, INPUT_PITCH) * 150;
- pitchOverflow = pitchBuffer >> 16;
- pitchBuffer -= (pitchOverflow << 16);
- if (pitchOverflow + charShift != 0)
- {
- cCharIndex += (pitchOverflow + charShift);
- charShift = 0; pitchOverflow = 0;
- update = 1;
- }
- if (yawOverflow + letterShift != 0)
- {
- cStrTmp = getString(cStr);
- cStrIndex += (yawOverflow + letterShift);
- cStrIndex = max(0, cStrIndex);
- if (cStrIndex >= StrLen(cStrTmp))
- {
- cCharIndex = 0;
- }
- else
- {
- cCharIndex = GetChar(cStrTmp, cStrIndex);
- cCharIndex = vOutputChars[cCharIndex];
- }
- letterShift = 0; yawOverflow = 0;
- update = 1;
- }
- if (keyPressed(BT_JUMP))
- {
- cStrTmp = getString(cStr);
- cStrTmp = sliceString(cStrTmp, 0, -1);
- cStr = reallocString(cStr, cStrTmp);
- if ((cStrIndex >= StrLen(cStrTmp)) && (cStrIndex != 0))
- {
- cStrIndex = StrLen(cStrTmp) - 1;
- cCharIndex = GetChar(cStrTmp, cStrIndex);
- cCharIndex = vOutputChars[cCharIndex];
- }
- update = 1;
- }
- if (keyPressed(BT_CROUCH))
- {
- cStr = reallocString(cStr, "");
- cStrIndex = 0;
- update = 1;
- }
- if (keyPressed(BT_USE))
- {
- HudMessage(s:""; HUDMSG_PLAIN, INPUTIDBASE-3, CR_WHITE, 0, 0, 1);
- HudMessage(s:""; HUDMSG_PLAIN, INPUTIDBASE-2, CR_WHITE, 0, 0, 1);
- HudMessage(s:""; HUDMSG_PLAIN, INPUTIDBASE-1, CR_WHITE, 0, 0, 1);
- HudMessage(s:""; HUDMSG_PLAIN, INPUTIDBASE, CR_WHITE, 0, 0, 1);
- HudMessage(s:""; HUDMSG_PLAIN, INPUTIDBASE+1, CR_WHITE, 0, 0, 1);
- HudMessage(s:""; HUDMSG_PLAIN, INPUTIDBASE+2, CR_WHITE, 0, 0, 1);
- HudMessage(s:""; HUDMSG_PLAIN, INPUTIDBASE+3, CR_WHITE, 0, 0, 1);
- HudMessage(s:""; HUDMSG_PLAIN, INPUTIDBASE+4, CR_WHITE, 0, 0, 1);
- HudMessage(s:""; HUDMSG_PLAIN, INPUTIDBASE+5, CR_WHITE, 0, 0, 1);
- break;
- }
- if (update || (tic % 175 == 0))
- {
- ACS_ExecuteAlways(STRALLOC_INPUTHELP, 0, prompt, 0,0);
- tic = 0;
- update = 0;
- cStrIndex = mod(cStrIndex, maxLength);
- cStrTmp = getString(cStr);
- if (StrLen(cStrTmp) <= cStrIndex)
- {
- cCharIndex = 0;
- }
- cCharIndex = mod(cCharIndex, INPUTCHARS);
- cChar = vInputChars[cCharIndex];
- cStrTmp = padStringR(cStrTmp, " ", cStrIndex+1);
- cStr = reallocString(cStr, changeString(cStrTmp, StrParam(c:cChar), cStrIndex));
- cStrTmp = getString(cStr);
- pStr = padStringR(cStrTmp, "_", maxLength);
- pStr2 = padStringR(cStrTmp, " ", maxLength);
- pStrLen = StrLen(pStr);
- pChar = StrParam(c:GetChar(pStr, cStrIndex));
- pCharStr = padStringL(pChar, " ", cStrIndex+1);
- pCharStr = padStringR(pCharStr, " ", maxLength);
- HudMessage(s:pStr; HUDMSG_PLAIN, INPUTIDBASE, CR_BLACK, cenWidth, cenHeight, 5.0);
- HudMessage(s:pStr2; HUDMSG_PLAIN, INPUTIDBASE-1, CR_GREY, cenWidth, cenHeight, 5.0);
- HudMessage(s:pCharStr; HUDMSG_PLAIN, INPUTIDBASE-2, CR_GREEN, cenWidth, cenHeight, 5.0);
- HudMessage(d:StrLen(cStrTmp), s:"/", d:maxLength, s:"\ca characters"; HUDMSG_PLAIN, INPUTIDBASE-3, CR_GOLD, cenWidth, cenHeight - (cenHeight >> 2), 5.0);
- }
- tic++;
- Delay(1);
- }
- GiveInventory("192Return", cStr);
- SetPlayerProperty(0, 0, PROP_TOTALLYFROZEN);
- inputLock[pln] = 0;
- Delay(1);
- TakeInventory("192Return", cStr);
- }
- script STRALLOC_INPUTHELP (int prompt)
- {
- SetHudSize(640, 480, 0);
- HudMessage(s:"Strafing and (alt-)firing shifts characters"; HUDMSG_FADEOUT, INPUTIDBASE+1, CR_GREEN, 320.4, 320.0, 8.0, 1.0);
- HudMessage(s:"Moving forward and looking up changes to next character"; HUDMSG_FADEOUT, INPUTIDBASE+2, CR_WHITE, 320.4, 335.0, 8.0, 1.0);
- HudMessage(s:"Moving backward and looking down changes to previous character"; HUDMSG_FADEOUT, INPUTIDBASE+3, CR_BRICK, 320.4, 350.0, 8.0, 1.0);
- HudMessage(s:"Jumping backspaces, crouch resets, use submits"; HUDMSG_FADEOUT, INPUTIDBASE+4, CR_YELLOW, 320.4, 365.0, 8.0, 1.0);
- SetHudSize(480, 360, 0);
- SetFont("BIGFONT");
- if (prompt != 0)
- {
- HudMessage(s:prompt; HUDMSG_FADEOUT, INPUTIDBASE+5, CR_WHITE, 240.4, 112.0, 8.0, 1.0);
- }
- }
- script 293 (void)
- {
- int s1; int s2; int s3;
- ACS_ExecuteAlways(STRALLOC_INPUTSTRING, 0, 32, "Lasers", "Mustache");
- while (CheckInventory("192Return") == 0)
- {
- Delay(1);
- }
- s1 = CheckInventory("192Return");
- s2 = addCleanString(StrParam(n:0));
- s3 = addLowerString(StrParam(n:0));
- SetFont("CONFONT");
- Print(s:dumpStrings(0));
- }
- script 294 (void)
- {
- int s1;
- Print(s:"this SHOULD work");
- s1 = addString("this SHOULD work");
- Print(d:s1, s:": ", s:getString(s1));
- Delay(35);
- Print(s:changeString(getString(s1), "pies", 0));
- Delay(35);
- Print(s:changeString(getString(s1), "is not", 5));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement