// Nazwa: CollectTitanium // Krotki opis: Bardzo rozbudowany program typu CollectTitanium // Dlugi opis: Bardzo rozbudowany program typu CollectTitanium z rozszerzonymi funkcjami ladowania/wymiany baterii. Umie je rowniez produkowac jak i decydowac ktora bateria ma w sobie wiecej energii. // Autor: krzys_h // Wersja: 1.0 // Data ostatniej zmiany: 2012-02-11 14:23 void object::TryGrab(int order) { int result = grab(order); if(this.load == null) result = -1; if(result != 0) { message("Podniesienie przedmiotu nie powiodlo sie. Ponawianie proby...", DisplayWarning); do { result = grab(order); if(this.load == null) result = -1; } while(result != 0); } } void object::TryDrop(int order) { int result = drop(order); if(this.load != null) result = -1; if(result != 0) { message("Upuszczenie przedmiotu nie powiodlo sie. Ponawianie proby...", DisplayWarning); do { result = drop(order); if(this.load != null) result = -1; } while(result != 0); } } void object::TryGoto(point position) { int result = goto(position); if(result != 0) { message("Dotarcie nie powiodlo sie. Ponawianie proby...", DisplayWarning); do { result = goto(position); } while(result != 0); } } void object::TryGoto(object item) { int result = goto(item.position); if(result != 0) { message("Dotarcie do " + item.category + " nie powiodlo sie. Ponawianie proby...", DisplayWarning); do { result = goto(item.position); } while(result != 0); } } void object::TryMove(int dist) { int result = move(dist); if(result != 0) { message("Przemieszczenie nie powiodlo sie. Ponawianie proby...", DisplayWarning); do { result = move(dist); } while(result != 0); } } extern void object::CollectTitanium() { errmode(0); if(!(this.category == WheeledGrabber || this.category == TrackedGrabber || this.category == WingedGrabber || this.category == LeggedGrabber || this.category == Subber)) { message("Potrzebujesz robota z chwytakiem!", DisplayError); return; } if(radar(Converter) == null) { message("Potrzebujesz huty!", DisplayError); return; } if(PotrzebneLadowanie()) Naladuj(); //Oprozniamy chwytak if(this.load != null) { if(this.load.category != TitaniumOre) { TryGoto(space()); TryDrop(InFront); } else { ZaniesOre(); ZabierzTytan(); } } while(radar(TitaniumOre) != null) { WezOre(); ZaniesOre(); ZabierzTytan(); if(PotrzebneLadowanie()) Naladuj(); } message("Koniec rudy tytanu!", DisplayError); } void object::WezOre() { object item = radar(TitaniumOre); TryGoto(item); TryGrab(InFront); } void object::ZaniesOre() { int Moveable[]; int a = 0; Moveable[a++] = Titanium; Moveable[a++] = TitaniumOre; Moveable[a++] = UraniumOre; Moveable[a++] = PowerCell; Moveable[a++] = NuclearCell; //Malo prawdopodobne, no ale... Moveable[a++] = KeyA; Moveable[a++] = KeyB; Moveable[a++] = KeyC; Moveable[a++] = KeyD; object item = radar(Converter); TryGoto(item); if(radar(Moveable, 0, 45, 0, 5) != null) { object oldLoad = this.load; if(this.category != Subber) { TryDrop(Behind); } else { turn(180); TryDrop(InFront); turn(180); } TryGrab(InFront); TryGoto(space()); TryDrop(InFront); TryGoto(oldLoad); TryGrab(InFront); TryGoto(item); } TryDrop(InFront); TryMove(-2.5); } void object::ZabierzTytan() { while(radar(Titanium, 0, 45, 0, 5) == null) wait(0.01); TryGoto(radar(Titanium, 0, 45, 0, 5)); TryGrab(InFront); TryGoto(space()); TryDrop(InFront); } bool object::PotrzebneLadowanie() { if(this.energyCell.category == PowerCell) { if(this.energyCell.energyLevel < 0.3) return true; } if(this.energyCell.category == NuclearCell) { if(this.energyCell.energyLevel < 0.05) return true; } return false; } object object::Bateria() { object maxEnergyCell = null; object zajeteBaterie[]; float maxEnergy = -1; int j=0; for(int i=0;i<500;i++) { object item = retobject(i); if(item != null) { if(item.energyCell != null) { zajeteBaterie[j] = item.energyCell; j++; } if(item.load != null) { if(item.load.category == PowerCell || item.load.category == NuclearCell) { zajeteBaterie[j] = item.load; j++; } } } } for(int i=0;i<500;i++) { object item = retobject(i); if(item != null) { bool zajete = false; for(int j=0;jmaxEnergy) { maxEnergy = item.energyLevel*100; maxEnergyCell = item; } if(item.category == PowerCell && item.energyLevel>maxEnergy) { maxEnergy = item.energyLevel; maxEnergyCell = item; } } } return maxEnergyCell; } void object::Naladuj() { if(this.energyCell.category == PowerCell) { if(radar(PowerStation) != null) { object item = radar(PowerStation); TryGoto(item); while(this.energyCell.energyLevel < 1) wait(0.01); return; } if(radar(PowerCaptor) != null) { object item = radar(PowerCaptor); TryGoto(item); while(this.energyCell.energyLevel < 1) wait(0.01); return; } } if(this.category != Subber) { object battery = Bateria(); if(battery != null && battery.energyLevel > this.energyCell.energyLevel && ((battery.category == PowerCell && battery.energyLevel > 0.3) || (battery.category == NuclearCell && battery.energyLevel > 0.05))) { TryGoto(battery); TryGrab(InFront); TryDrop(Behind); TryGrab(EnergyCell); TryDrop(InFront); TryGrab(Behind); TryDrop(EnergyCell); return; } if(radar(NuclearPlant) != null) { object plant = radar(NuclearPlant); if(plant.energyCell != null) { if(plant.energyCell.category == NuclearCell) { TryGoto(plant); TryGrab(InFront); TryDrop(Behind); TryGrab(EnergyCell); TryDrop(InFront); TryGrab(Behind); TryDrop(EnergyCell); TryGrab(InFront); TryGoto(space()); TryDrop(InFront); return; } else if(plant.energyCell.category == UraniumOre) { TryGoto(plant); TryMove(-3); while(plant.energyCell.category != NuclearCell) wait(0.01); TryMove(3); TryGrab(InFront); TryDrop(Behind); TryGrab(EnergyCell); TryDrop(InFront); TryGrab(Behind); TryDrop(EnergyCell); TryGrab(InFront); TryGoto(space()); TryDrop(InFront); return; } else { if(radar(UraniumOre) != null) { TryGoto(plant); TryGrab(InFront); TryGoto(space()); TryDrop(InFront); } } } if(radar(UraniumOre) != null) { object item = radar(UraniumOre); TryGoto(item); TryGrab(InFront); TryGoto(plant); TryDrop(InFront); TryMove(-3); while(plant.energyCell.category != NuclearCell) wait(0.01); TryMove(3); TryGrab(InFront); TryDrop(Behind); TryGrab(EnergyCell); TryDrop(InFront); TryGrab(Behind); TryDrop(EnergyCell); TryGrab(InFront); TryGoto(space()); TryDrop(InFront); return; } } if(radar(PowerPlant) != null) { object plant = radar(PowerPlant); if(plant.energyCell != null) { if(plant.energyCell.category == PowerCell) { TryGoto(plant); TryGrab(InFront); TryDrop(Behind); TryGrab(EnergyCell); TryDrop(InFront); TryGrab(Behind); TryDrop(EnergyCell); TryGrab(InFront); TryGoto(space()); TryDrop(InFront); return; } else if(plant.energyCell.category == Titanium) { TryGoto(plant); while(plant.energyCell.category != PowerCell) wait(0.01); TryGrab(InFront); TryDrop(Behind); TryGrab(EnergyCell); TryDrop(InFront); TryGrab(Behind); TryDrop(EnergyCell); TryGrab(InFront); TryGoto(space()); TryDrop(InFront); return; } else { if(radar(Titanium) != null) { TryGoto(plant); TryGrab(InFront); TryGoto(space()); TryDrop(InFront); } } } if(radar(Titanium) != null) { object item = radar(Titanium); TryGoto(item); TryGrab(InFront); TryGoto(plant); TryDrop(InFront); while(plant.energyCell.category != PowerCell) wait(0.01); TryGrab(InFront); TryDrop(Behind); TryGrab(EnergyCell); TryDrop(InFront); TryGrab(Behind); TryDrop(EnergyCell); TryGrab(InFront); TryGoto(space()); TryDrop(InFront); return; } } } message("Nie ma mozliwosci naladowania. Naladuj recznie.", DisplayError); float oldEnergy = this.energyCell.energyLevel; bool naladowana = false; do { if(this.energyCell != null) { if(this.energyCell.energyLevel > oldEnergy) naladowana = true; } } while(!naladowana); }