It's not impossible.
I'm testing your program now.
Your program needs to be modified to search for a "robot" which has an empty PowerCell.
Wow that was tough. I re-wrote most of it. Tell me if you find any bugs.
I'm testing your program now.
Your program needs to be modified to search for a "robot" which has an empty PowerCell.
Wow that was tough. I re-wrote most of it. Tell me if you find any bugs.
Code:
extern void object::Power_Rescue()
{
while (true)
{
if (this.load != null)
{
goto(space(position));
drop();
}
FindObjectReplaceCell();
if (this.load != null) continue;
wait(10);
}
}
void object::GrabNearestFullCell()
{
object item, NearestItem = null;
int i = 0;
while (true)
{
item = retobject(i++);
if (item == null) break;
if (item.category != NuclearCell) continue;
if (item.position.x == nan) continue;
if (item.energyLevel == 1)
{
if (NearestItem == null)
{
NearestItem = item;
continue;
}
if (distance(this.position, item.position) < distance(this.position, NearestItem.position) )
{
NearestItem = item;
}
}
}
if (NearestItem == null) return; // did not find an item
goto(NearestItem.position);
grab(InFront);
return;
}
void object::ChangeCell()
{
drop(Behind);
grab(InFront);
turn(-90);
drop(InFront);
turn(90);
grab(Behind);
drop(InFront);
turn(-90);
grab(InFront);
}
void object::FindObjectReplaceCell()
{
object item;
int i = 0, t = 0;
float speed;
int types[];
types[t++] = WheeledShooter;
types[t++] = WheeledGrabber;
types[t++] = TrackedGrabber;
while (true)
{
item = retobject(i++);
if (item == null) break;
for (int k = 0; k < sizeof(types); k++)
{
if (item.category == types[k]) // must be in the list
{
if (item.id == this.id) break; // <--------- not this bot
if (item.energyCell == null)
{
message("INFO: "+item.category+" Has No energyCell");
break; //<--------------------------------------- must have an energyCell
}
if (item.energyCell.energyLevel < 0.1)
{
if (item.velocity.x != nan)
{
speed = abs(item.velocity.x);
speed += abs(item.velocity.y);
speed += abs(item.velocity.z);
} else speed = 0.0;
if (speed != 0.0 and item.altitude > 0.0) break;// not moving or flying
GrabNearestFullCell();
if (this.load == null) return; // did not find a FuelCell
goto(item.position);
ChangeCell();
return;
}
}
}
}
return;
}