Skip to content

Commit

Permalink
ZVISION: Fix lever code;
Browse files Browse the repository at this point in the history
  • Loading branch information
Marisa-Chan committed Feb 7, 2014
1 parent 4a454ed commit 0033740
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions engines/zvision/lever_control.cpp
Expand Up @@ -91,9 +91,11 @@ void LeverControl::parseLevFile(const Common::String &fileName) {
return;
}

Common::String line = file.readLine();
Common::String line;

while (!file.eos()) {
line = file.readLine();

if (line.matchString("*animation_id*", true)) {
// Not used
} else if (line.matchString("*filename*", true)) {
Expand Down Expand Up @@ -142,28 +144,30 @@ void LeverControl::parseLevFile(const Common::String &fileName) {
uint frameNumber;
uint x, y;

line.toLowercase();

if (sscanf(line.c_str(), "%u:%u %u", &frameNumber, &x, &y) == 3) {
_frameInfo[frameNumber].hotspot.left = x;
_frameInfo[frameNumber].hotspot.top = y;
_frameInfo[frameNumber].hotspot.right = x + _hotspotDelta.x;
_frameInfo[frameNumber].hotspot.bottom = y + _hotspotDelta.y;
}

Common::StringTokenizer tokenizer(line, " ^=()");
Common::StringTokenizer tokenizer(line, " ^=()~");
tokenizer.nextToken();
tokenizer.nextToken();

Common::String token = tokenizer.nextToken();
while (!tokenizer.empty()) {
if (token == "D") {
if (token == "d") {
token = tokenizer.nextToken();

uint angle;
uint toFrame;
sscanf(token.c_str(), "%u,%u", &toFrame, &angle);

_frameInfo[frameNumber].directions.push_back(Direction(angle, toFrame));
} else if (token.hasPrefix("P")) {
} else if (token.hasPrefix("p")) {
// Format: P(<from> to <to>)
tokenizer.nextToken();
tokenizer.nextToken();
Expand All @@ -177,7 +181,7 @@ void LeverControl::parseLevFile(const Common::String &fileName) {
}
}

line = file.readLine();
// Don't read lines in this place because last will not be parsed.
}
}

Expand Down Expand Up @@ -290,7 +294,7 @@ int LeverControl::calculateVectorAngle(const Common::Point &pointOne, const Comm

// Calculate the angle using arctan
// Then convert to degrees. (180 / 3.14159 = 57.2958)
int angle = int(atan((float)yDist / (float)xDist) * 57);
int angle = int(atan((float)yDist / (float)abs(xDist)) * 57);

// Calculate what quadrant pointTwo is in
uint quadrant = ((yDist > 0 ? 1 : 0) << 1) | (xDist < 0 ? 1 : 0);
Expand Down Expand Up @@ -339,16 +343,16 @@ int LeverControl::calculateVectorAngle(const Common::Point &pointOne, const Comm
// Convert the local angles to unit circle angles
switch (quadrant) {
case 0:
angle = 180 + angle;
angle = -angle;
break;
case 1:
// Do nothing
angle = angle + 180;
break;
case 2:
angle = 180 + angle;
angle = 360 - angle;
break;
case 3:
angle = 360 + angle;
angle = 180 + angle;
break;
}

Expand Down

0 comments on commit 0033740

Please sign in to comment.