Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Finding Powercells that needs charging
#14
@clop1000 ,
This  program can get the holder of any object that can be carried.
Code:
extern void object::Example()
{
    // list of objects that can be carried
    object obj[];
    
    // ...fill the list...
    
    object holder = GetOwnerOf( obj[0] );
    
        // if this robot has obj[0]
    if (holder == this) /* do stuff */ ;
    
        // if obj[0] is on the ground   or obj[0] == null
    else if (holder == null) /* do stuff */ ;
    
        // if obj[0] is in battery slot of holder
    else if (obj[0] == holder.energyCell ) /* do stuff */ ;
    
        // if obj[0] is carried in claw of holder
    else if (obj[0] == holder.load ) /* do stuff */ ;
}

public object object::GetOwnerOf(object obj)
{
    if (obj == null) return null;
    if (obj.position.x != nan) return null; // obj is on the ground
    
    if (obj == this.energyCell) return this;
    if (obj == this.load) return this;
    
    int types[] = ObjectHolders();
    object objList[] = radarall(types); // find all object holders
    int numObjs = sizeof(objList);
    
    for (int i = 0; i < numObjs; i++)   // check if one holds obj
    {
        if (obj == objList[i].energyCell) return objList[i];
        if (obj == objList[i].load) return objList[i];
    }
    return null;
}

int[] ObjectHolders()
{
    int i=0;
    int list[];
    list[i++] = WingedGrabber;
    list[i++] = TrackedGrabber;
    list[i++] = WheeledGrabber;
    list[i++] = LeggedGrabber;
    list[i++] = WingedShooter;
    list[i++] = TrackedShooter;
    list[i++] = WheeledShooter;
    list[i++] = LeggedShooter;
    list[i++] = WingedOrgaShooter;
    list[i++] = TrackedOrgaShooter;
    list[i++] = WheeledOrgaShooter;
    list[i++] = LeggedOrgaShooter;
    list[i++] = WingedSniffer;
    list[i++] = TrackedSniffer;
    list[i++] = WheeledSniffer;
    list[i++] = LeggedSniffer;
    list[i++] = Thumper;
    list[i++] = PhazerShooter;
    list[i++] = Recycler;
    list[i++] = Shielder;
    list[i++] = Subber;
    list[i++] = DefenseTower;
    list[i++] = ResearchCenter;
    list[i++] = PowerPlant;
    list[i++] = NuclearPlant;
    list[i++] = AutoLab;
    //list[i++] = AlienWasp; // wasp can carry objects too
    return list;
}
This can also be done with a method called on the object, but that is slightly more complicated.


Messages In This Thread
Finding Powercells that needs charging - by Jono - 04-09-2015, 08:14 AM
RE: Finding Powercells that needs charging - by melex750 - 07-05-2016, 11:03 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)