[Balder-cvs] balder2d/src artificialcontroller.cpp,1.9,1.10 probe.cpp,1.30,1.31
Status: Beta
Brought to you by:
holomorph
From: Bjorn H. <hol...@us...> - 2006-03-21 20:48:42
|
Update of /cvsroot/balder/balder2d/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26152/src Modified Files: artificialcontroller.cpp probe.cpp Log Message: fixed Probe-probe collisions to ignore exploding probes. added some more AI functionality, and made the ArtificialController::py_IsLineOfSight work better Index: artificialcontroller.cpp =================================================================== RCS file: /cvsroot/balder/balder2d/src/artificialcontroller.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** artificialcontroller.cpp 20 Mar 2006 06:40:30 -0000 1.9 --- artificialcontroller.cpp 21 Mar 2006 20:47:20 -0000 1.10 *************** *** 198,231 **** // ss << "testing line from (" << x1 << ", " << y1 << ") to (" << x2 << ", " << y2 << ")"; // test every pixel along the line connecting the two points ! if (x1 > x2) { // swap those two points so I can just write the loop once ! int temp = x2; ! x2 = x1; ! x1 = temp; ! temp = y2; ! y2 = y1; ! y1 = temp; } ! else if (x1 == x2) { // just test along the vertical direction ! if (y1>y2) { ! int temp = y2; y2 = y1; y1 = temp; } ! for (int y=y1; y<y2; ++y) { ! if (geometry->TestPixel(x1,y)) { return PyBool_FromLong(false); } } - return PyBool_FromLong(true); } ! int x, y, xdelta, ydelta; ! float slope = float(y2-y1)/(x2-x1); ! for (x=x1; x<x2; ++x) { ! // determine the y value ! xdelta = x - x1; ! ydelta = int(xdelta*slope); ! y = y1 + ydelta; ! if (geometry->TestPixel(x,y)) { ! return PyBool_FromLong(false); } } --- 198,254 ---- // ss << "testing line from (" << x1 << ", " << y1 << ") to (" << x2 << ", " << y2 << ")"; // test every pixel along the line connecting the two points ! if (x1 == x2 && y1 == y2) { ! return PyBool_FromLong(true); } ! int x, y, xdelta, ydelta; ! xdelta = x2-x1; ! ydelta = y2-y1; ! /* we want to proceed on the direction that will test the most ! points along the line, if we just tested along x the loop would ! have good resolution in the x direction, ! but could be very poor in the y direction, if the x values are ! very close but y values that are not close for example testing ! along the line from (5,1) to (6,20) would only test two points! ! */ ! if (xdelta^2 > ydelta^2){ ! float slope = float(ydelta)/xdelta; ! // make sure the points have x1 < x2 points so I can just write the loop once ! if (x1 > x2) { ! int temp = x2; ! x2 = x1; ! x1 = temp; ! temp = y2; y2 = y1; y1 = temp; } ! for (x=x1; x<x2; ++x) { ! // determine the y value ! xdelta = x - x1; ! ydelta = int(xdelta*slope); ! y = y1 + ydelta; ! if (geometry->TestPixel(x,y)) { return PyBool_FromLong(false); } } } ! else { ! float slope = float(xdelta)/ydelta; ! // make sure the points have y1 < y2 points so I can just write the loop once ! if (y1 > y2) { ! int temp = x2; ! x2 = x1; ! x1 = temp; ! temp = y2; ! y2 = y1; ! y1 = temp; ! } ! for (y=y1; y<y2; ++y) { ! // determine the y value ! ydelta = y - y1; ! xdelta = int(ydelta*slope); ! x = x1 + xdelta; ! if (geometry->TestPixel(x,y)) { ! return PyBool_FromLong(false); ! } } } Index: probe.cpp =================================================================== RCS file: /cvsroot/balder/balder2d/src/probe.cpp,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** probe.cpp 18 Mar 2006 03:12:39 -0000 1.30 --- probe.cpp 21 Mar 2006 20:47:20 -0000 1.31 *************** *** 265,268 **** --- 265,270 ---- bool Probe::Collide(Probe* p) { + // don't collide probes that are exploding + if (p->GetLife() <1 || death_frame) {return false;} double x = p->GetX() - GetX(); double y = p->GetY() - GetY(); |