-
Answer of https://cafe.naver.com/edac/111879 = https://cafe.naver.com/edac/111841 Implementation ChoicesChoice 1. ButtonShould we use primary order button? (Hold, Carrier Stop, Reaver Stop, ...)
Choice 2. Spatial data structureI'm going to check simple rectangular position but it would be clever to use spatial data structure, like simple grid or quad tree, to avoid checking all units and instead check units only in boundary. Choice 3. How to check unit positionWe'll use simple 4 DeathsX instead of Bring. CBringEPD is too slow to run on multiple units because it backups unitID, sets unitID to unique one, runs Bring and restores unitID, on every unit to check. If you use location, you must synchronize Location Coordinates and Position-checking conditions correctly and it would be nice if the synchronization only runs minimally on-demand. Choice 4. Prevent HP from exceeding maximumSC gracefully handles this for shield point and units with hp regeneration. Turn on HP regeneration for simple reasoning. If you don't want HP regeneration, you need to build efficient data structure to load max hp by unit kind. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
epScript example)
// BuildCheckConst : https://cafe.naver.com/edac/98602
import bcc.BuildCheckConst;
function healSkill() {
var healCenter = 0;
var healPlayer;
// we'll cache unit selections because they're seldom changed
const ptrCache = EUDVArray(8 * 12)();
const epdCache = EUDVArray(8 * 12)();
const vr1, vr2 = EUDVArrayReader(), EUDVArrayReader();
var ptr, epd;
DoActions(
vr1.seek(ptrCache, EPD(ptrCache), ptr),
vr2.seek(epdCache, EPD(epdCache), epd));
const selectEPD = EPD(0x6284E8);
var select = selectEPD;
while (select < selectEPD + 8 * 12) {
vr1.read();
vr2.read();
if (!MemoryEPD(select, Exactly, ptr)) {
ptr, epd = cunitepdread_epd(select);
const pos = (select - selectEPD) * 18;
const updatePtr = EPD(ptrCache) + 78 + pos;
const updateEPD = EPD(epdCache) + 78 + pos;
dwwrite_epd(updatePtr, ptr);
dwwrite_epd(updateEPD, epd);
}
if (ptr == 0) continue;
const unitKind = epd + 25;
if (MemoryEPD(unitKind, Exactly, $U("Zerg Zergling"))) {
const buildQueue = epd + 0x98/4, epd + 0x9C/4, epd + 0xA0/4;
if (MemoryEPD(buildQueue[0], Exactly, 0xE400E4)
&& MemoryEPD(buildQueue[1], Exactly, 0xE400E4)
&& MemoryXEPD(buildQueue[2], Exactly, 0xE4, 0xFFFF)
) { // Zergling isn't training any unit
} else {
// Zergling is training some unit
const buildReset = function() {
dwwrite_epd(buildQueue[0], 0xE400E4);
dwwrite_epd(buildQueue[1], 0xE400E4);
wwrite_epd(buildQueue[2], 0, 0xE4);
};
if (BuildCheckConst(epd, "Zerg Broodling")) {
// We *must* read owner since user can select unit owned by another player
const owner = maskread_epd(epd + 19, 15);
const energy = epd + 0xA0/4;
if (MemoryXEPD(energy, AtMost, (20 << 16) - 1, 0xFFFF0000)) {
buildReset();
SetCurrentPlayer(owner);
DisplayText("Not enough energy");
} else if (healCenter == 0) {
buildReset();
SetMemoryXEPD(energy, Subtract, 20 << 16, 0xFFFF0000);
healPlayer = owner;
healCenter = epd + 0x28/4;
}
}
}
}
EUDSetContinuePoint();
select += 1;
}
if (healCenter == 0) return;
// Should we cache healCenter? I guess not...
const healX = maskread_epd(healCenter, 0xFFFF);
const healY = maskread_epd(healCenter, 0xFFFF0000);
const healCond = DeathsX(CurrentPlayer, AtLeast, 0, 0, 0xFFFF),
DeathsX(CurrentPlayer, AtMost, 0, 0, 0xFFFF),
DeathsX(CurrentPlayer, AtLeast, 0, 0, 0xFFFF0000),
DeathsX(CurrentPlayer, AtMost, 0, 0, 0xFFFF0000);
dwwrite(healCond[0] + 8, healX);
dwwrite(healCond[1] + 8, healX + 5 * 16);
dwwrite(healCond[2] + 8, healY);
dwwrite(healCond[3] + 8, healY + 5 * 16 * 65536);
DoActions( // prevent wrap-around at map boundary
SetMemory(healCond[0] + 8, Subtract, 5 * 16),
SetMemory(healCond[2] + 8, Subtract, 5 * 16 * 65536)
);
foreach(ptr, epd : EUDLoopUnit2()) {
const unitKind = epd + 25;
if (MemoryEPD(unitKind, Exactly, $U("Zerg Hydralisk"))) {
SetCurrentPlayer(epd + 0x28/4);
if (MemoryXEPD(epd + 19, Exactly, healPlayer, 0xFF)
&& healCond) {
dwadd_epd(epd + 2, 10 * 256);
}
}
}
} |
Beta Was this translation helpful? Give feedback.
epScript example)