Class BackendTroopMovementController
In: app/controllers/backend_troop_movement_controller.rb
Parent: ApplicationController

Methods

Public Instance methods

Methode die Ressourcen vom Planeten in einen Transporter verschiebt @params:typ

  • [troop_movement:TroopMovement] (Flotte)
  • [ore:integer] (Anzahl Erz)
  • [crystal:integer] (Anzahl Kristall)
  • [gas:integer] (Anzahl Gas)

@return

  • 0: klappt
  • 1: kein Transporter in der Flotte
  • 2: nicht genug Erz auf dem Planeten vorhanden
  • 3: nicht genug Kristall auf dem Planeten vorhanden
  • 4: nicht genug Gas auf dem Planeten vorhanden
  • 5: nicht genug Lagerplatz in Flotte vorhanden

[Source]

     # File app/controllers/backend_troop_movement_controller.rb, line 125
125:   def add_resources(troop_movement, ore, crystal, gas)
126:     ActiveRecord::Base.transaction do  
127:       if(troop_movement.available_capacity == 0)
128:         return 1
129:       end
130:       if(ore > troop_movement.start_planet.ore)
131:         return 2
132:       end
133:       if(crystal > troop_movement.start_planet.crystal)
134:         return 3
135:       end
136:       if(gas > troop_movement.start_planet.gas)
137:         return 4
138:       end
139:       if(troop_movement.available_capacity < ore+crystal+gas)
140:         return 5
141:       end
142:       troop_movement.ore += ore
143:       troop_movement.crystal += crystal
144:       troop_movement.gas += gas
145:       troop_movement.save
146:       troop_movement.start_planet.ore -= ore
147:       troop_movement.start_planet.crystal -= crystal
148:       troop_movement.start_planet.gas -= gas
149:       troop_movement.start_planet.save
150:       return 0
151:     end
152:   end

Methode die Raumschiffe vom Planeten in eine Flotte verschiebt @params:typ

  • [troop_movement:TroopMovement] (Flotte)
  • [spaceship:Spaceship] (Raumschifftyp)
  • [count:Integer] (Anzahl der Raumschiffe, die in die Flotte verschoben werden sollen)

@return

  • true: klappt
  • false: zu wenig Schiffe auf dem Planeten vorhanden

[Source]

     # File app/controllers/backend_troop_movement_controller.rb, line 67
 67:   def add_ships(troop_movement, spaceship, count)
 68:     
 69:     if(spaceship.name != "Jäger" and
 70:        spaceship.name != "Bomber" and
 71:        spaceship.name != "Kreuzer" and
 72:        spaceship.name != "Zerstörer" and
 73:        spaceship.name != "Schlachtschiff" and
 74:        spaceship.name != "Spionagesonde" and
 75:        spaceship.name != "Transporter" and
 76:        spaceship.name != "Kolonieschiff" and
 77:        spaceship.name != "Truppentransporter")
 78:        
 79:       return false
 80:     end
 81:     
 82:     if spaceship.count < count
 83:       return false
 84:     end
 85:     
 86:     spaceship.count = spaceship.count - count
 87:     
 88:     if((s = troop_movement.spaceships.find(:first, :conditions => {:name => spaceship.name,
 89:                                                          :level => spaceship.level})) != nil)
 90:       s.count += count
 91:       s.save
 92:     else
 93:        
 94:       s = Spaceship.create(:name => spaceship.name,  
 95:                            :level => spaceship.level,
 96:                            :count => count,
 97:                            :user => spaceship.user)
 98:       troop_movement.spaceships << s
 99:     
100:     end
101:   
102:     if(spaceship.count == 0)
103:       spaceship.destroy
104:     else
105:       spaceship.save
106:     end
107:     
108:     return true
109:   end

Führt die zur Mission entsprechende Methode aus @params:typ

[Source]

     # File app/controllers/backend_troop_movement_controller.rb, line 265
265:   def arriving(troop_movement)
266:     case troop_movement.mission
267:       when 1
268:         self.attack(troop_movement)
269:       when 2
270:         self.colonize(troop_movement)
271:       when 3
272:         self.spy(troop_movement)
273:       when 4
274:         self.transport(troop_movement)
275:       when 5
276:         self.station(troop_movement)
277:       when 6
278:         self.sell(troop_movement)
279:     end
280:   end

Greift einen fremden Planeten an @params:typ

[Source]

     # File app/controllers/backend_troop_movement_controller.rb, line 285
285:   def attack(troop_movement)
286:     ActiveRecord::Base.transaction do 
287:       dest = troop_movement.destination_planet
288:       sender = User.find_by_name("System")
289:       att_recipient = troop_movement.user
290:       if(dest.owner == nil)
291:         att_subject = "Angriff auf " + dest.name + " nicht möglich!"
292:         self.flight_back(troop_movement)
293:         att_text = troop_movement.start_planet.name + " ist inzwischen unbewohnt.\n" +
294:                    "Die Flotte kehrt zu " + troop_movement.destination_planet.name + " zurück."
295:       elsif(dest.owner == att_recipient)
296:         att_subject = "Angriff auf " + dest.name + " nicht möglich!"
297:         att_text = dest.name + " wurde bereits von Ihnen erobert.\n" +
298:                    "Die Flotte ist gelandet."
299:         self.gas_surplus_transfer(troop_movement)
300:         self.landing(troop_movement)
301:       elsif(dest.owner.alliance == att_recipient.alliance and att_recipient.alliance)
302:         att_subject = "Angriff auf " + dest.name + " nicht möglich!"
303:         self.flight_back(troop_movement)
304:         att_text = troop_movement.start_planet.name + " ist von einem Allianzmitglied bewohnt.\n" +
305:                    "Die Flotte kehrt zu " + troop_movement.destination_planet.name + " zurück."
306:       else
307:         def_recipient = dest.owner
308:         att_spaceships = Hash.new
309:         troop_movement.spaceships.each do |s|
310:           att_spaceships[s.name + "(Stufe " + s.level.to_s + ")"] = s.count
311:         end
312:         def_spaceships = Hash.new
313:         dest.spaceships.each do |s|
314:           def_spaceships[s.name + "(Stufe " + s.level.to_s + ")"] = s.count
315:         end
316:         bfc = BackendFightController.new
317:         if(bfc.calc_fight(troop_movement))
318:           if(troop_movement.spaceships.length != 0)
319:             def_subject = "Verteidigung von " + dest.name + " durchbrochen!"
320:             att_subject = "Erfolgreicher Angriff auf " + dest.name
321:             att_text = "Die gegnerische Flotte wurde vernichtet!\n\n" + 
322:                        "Die Verluste betragen:\n"
323:             troop_movement.spaceships.each do |s|
324:               if(s.count != att_spaceships[s.name + "(Stufe " + s.level.to_s + ")"])
325:                 att_text += "  " + (att_spaceships[s.name + "(Stufe " + s.level.to_s + ")"] - s.count).to_s + " " + s.name +
326:                             "(Stufe " + s.level.to_s + ")\n"
327:               end
328:               att_spaceships.delete(s.name + "(Stufe " + s.level.to_s + ")")
329:             end
330:             att_spaceships.each do |namelevel, count|
331:               att_text += "  " + count.to_s + " " + namelevel
332:             end
333:             shuttle = troop_movement.spaceships.find(:first, :conditions => {:name => "Truppentransporter" })
334:             fields = dest.fields/RulesAndRegulations::SHUTTLE_CONQUER_FIELDS
335:             if(!dest.homeplanet and shuttle and shuttle.count >= fields)
336:               att_text += "\nDer Planet wurde erobert!"
337:               def_text = "Ihr Planet " + dest.name + " wurde erobert!"
338:               troop_movement.user.planets << dest
339:               dest.last_tick_res = Time.new.to_i      
340:               dest.save
341:     
342:               self.gas_surplus_transfer(troop_movement)
343:                   
344:               troop_movement.spaceships.each do |s|
345:                 s.troop_movement = nil
346:                 dest.spaceships << s
347:               end
348:               if(shuttle.count > fields)
349:                 shuttle.count -= fields
350:                 shuttle.save
351:               else
352:                 shuttle.destroy
353:               end
354:               troop_movement.destroy
355:             elsif(troop_movement.spaceships.find(:first, :conditions => {:name => "Transporter" }))
356:               if(dest.buildings.find(:first, :conditions => {:name => "Lager" }).level > 0)
357:                 ore = [[0, dest.ore - dest.storage_capacity * 0.3].max, troop_movement.available_capacity/3.0].min
358:                 crystal = [[0, dest.crystal - dest.storage_capacity * 0.3].max, troop_movement.available_capacity/3.0].min
359:                 gas = [[0, dest.gas - dest.storage_capacity * 0.3].max, troop_movement.available_capacity/3.0].min
360:               else
361:                 ore = [dest.ore, troop_movement.available_capacity/3.0].min
362:                 crystal = [dest.crystal, troop_movement.available_capacity/3.0].min
363:                 gas = [dest.gas, troop_movement.available_capacity/3.0].min
364:               end
365:               
366:               troop_movement.ore += ore
367:               troop_movement.crystal += crystal
368:               troop_movement.gas += gas
369:               troop_movement.save
370:               dest.ore -= ore
371:               dest.crystal -= crystal
372:               dest.gas -= gas
373:               dest.save
374:               self.flight_back(troop_movement)
375:             
376:               att_text += "\nEs wurden folgende Ressourcen erbeutet:\n" +
377:                           "  " + ore.to_s + " Erz\n" +
378:                           "  " + crystal.to_s + " Kristall\n" +
379:                           "  " + gas.to_s + " Gas\n"
380:               att_text += "\nDer Rest der Flotte kehrt zu " + troop_movement.destination_planet.name + " zurück."            
381:               
382:               def_text = "Ihr Planet " + dest.name + " wurde von " + troop_movement.user.name + " angegriffen und Ihre dort " +
383:                          "stationierte Flotte wurde vernichtet!\n" +
384:                          "\nSie haben folgende Ressourcen verloren:\n" +
385:                           "  " + ore.to_s + " Erz\n" +
386:                           "  " + crystal.to_s + " Kristall\n" +
387:                           "  " + gas.to_s + " Gas\n "
388:             else
389:               def_text = "Ihr Planet " + dest.name + " wurde " + troop_movement.user.name + " angegriffen und Ihre dort " +
390:                          "stationierte Flotte wurde vernichtet!"
391:               self.flight_back(troop_movement)
392:               att_text += "\nDer Rest der Flotte kehrt zu " + troop_movement.destination_planet.name + " zurück."
393:             end
394:           else
395:             att_subject = "Angriff auf " + dest.name
396:             att_text = "unentschieden!"
397:             troop_movement.destroy
398:           end
399:         else
400:           att_subject = "Gescheiterter Angriff auf " + dest.name
401:           att_text = "Ihre gesamte Flotte wurde vernichtet!\n" + 
402:                      "Niemand hat überlebt!\n" +
403:                  "Gegnerische Verluste unbekannt."
404:           def_subject = "Erfolgreiche Verteidigung auf " + dest.name
405:           def_text = "Die gegnerische Flotte von " + troop_movement.user.name + " wurde vernichtet!\n\n" + 
406:                      "Die Verluste betragen:\n"
407:           dest.spaceships.each do |s|
408:             if(s.count != def_spaceships[s.name + "(Stufe " + s.level.to_s + ")"])
409:                 def_text += "  " + (def_spaceships[s.name + "(Stufe " + s.level.to_s + ")"] - s.count).to_s + " " + s.name +
410:                             "(Stufe " + s.level.to_s + ")\n"
411:             end
412:             def_spaceships.delete(s.name + "(Stufe " + s.level.to_s + ")")
413:           end
414:           def_spaceships.each do |namelevel, count|
415:             def_text += "  " + count.to_s + " " + namelevel
416:           end
417:           troop_movement.destroy
418:         end
419:         BackendMessageController.new.send_message(sender, def_recipient, def_subject, def_text)
420:       end
421:       BackendMessageController.new.send_message(sender, att_recipient, att_subject, att_text)
422:     end
423:   end

Kolonisiert einen fremden Planeten und zerstört dabei ein Kolonieschiff oder fliegt zum Ausgangspunkt zurück falls schon besiedelt @params:typ

[Source]

     # File app/controllers/backend_troop_movement_controller.rb, line 430
430:   def colonize(troop_movement)
431:     dest = troop_movement.destination_planet
432:     sender = User.find_by_name("System")
433:     recipient = troop_movement.user
434:     if(dest.owner == nil)
435:       subject = "Kolonisierung von " + dest.name
436:       text = dest.name + " wurde erfolgreich besiedelt."
437:       troop_movement.user.planets << dest
438:       dest.last_tick_res = Time.new.to_i      
439:       dest.save
440:       
441:       self.discharge(troop_movement)
442:       self.gas_surplus_transfer(troop_movement)
443:           
444:       troop_movement.spaceships.each do |s|
445:         s.troop_movement = nil
446:         dest.spaceships << s
447:       end
448:       colony = dest.spaceships.find(:first, :conditions => {:name => "Kolonieschiff" })
449:       if(colony.count > 1)
450:         colony.count -= 1
451:         colony.save
452:       else
453:         colony.destroy
454:       end
455:       troop_movement.destroy
456:     else
457:       subject = "Kolonisierung fehlgeschlagen"
458:       text = dest.name + "konnte nicht besiedelt werden, da der Planet inzwischen von " +
459:              dest.owner.name + " besiedelt wurde.\n"          
460:       self.flight_back(troop_movement)
461:       text += "Die Flotte kehrt zu " + troop_movement.start_planet.name + " zurück."
462:     end
463:     BackendMessageController.new.send_message(sender, recipient, subject, text)
464:   end

Methode die ein TroopMovement erstellt @params:typ

  • [user:User] Besitzer der Flotte
  • [start_planet:Planet] Startplanet
  • [dest_planet:Planet] Zielplanet
  • [mission:Integer] Auftrag
  • 1 = Angriff
  • 2 = Besiedeln
  • 3 = Spionage
  • 4 = Transport und Rückflug
  • 5 = Stationieren
  • 6 = Schiffe an andere Spieler schicken

@return

  • troop_movement: hat geklappt
  • 1: keine gültige Missionsnummer
  • 2: Angriff auf Planet, der keinem fremden Spieler gehört
  • 3: Besiedeln eines schon besiedelten Planeten
  • 4: Ausspionieren eines eigenen Planeten
  • 5: Transportieren zu einem unbewohnten Planeten
  • 6: Stationieren auf einem fremden Planeten
  • 7: Verkaufen auf unbewohnten oder eigenen Planeten
  • 8: Angriff auf Planeten eines Allianzmitgliedes

[Source]

    # File app/controllers/backend_troop_movement_controller.rb, line 27
27:   def create_troop_movement(user, start_planet, dest_planet, mission)
28:     if([1, 2, 3, 4, 5, 6].all?{|m| m != mission})
29:       return 1
30:     end
31:     if(mission == 1 and (dest_planet.owner == user or dest_planet.owner == nil))
32:       return 2
33:     end
34:     if(mission == 2 and dest_planet.owner != nil)
35:       return 3
36:     end
37:     if(mission == 3 and dest_planet.owner == user)
38:       return 4
39:     end
40:     if(mission == 4 and dest_planet.owner == nil)
41:       return 5
42:     end
43:     if(mission == 5 and dest_planet.owner != user)
44:       return 6
45:     end
46:     if(mission == 6 and (dest_planet.owner == nil or dest_planet.owner == user)) 
47:       return 7
48:     end
49:     if(mission == 1 and (user.alliance == dest_planet.owner.alliance) and user.alliance != nil)
50:       return 8
51:     end
52:     TroopMovement.create(:user => user,
53:                       :start_planet => start_planet,
54:                       :destination_planet => dest_planet,
55:                       :mission => mission)
56:   end

Bricht eine Flottenbewegung noch vor dem Start ab @params:typ

[Source]

     # File app/controllers/backend_troop_movement_controller.rb, line 703
703:   def delete_troop_movement(troop_movement)
704:     troop_movement.destination_planet = troop_movement.start_planet
705:     troop_movement.save
706:     self.landing(troop_movement)
707:   end

Ressourcen ausladen @params:typ

[Source]

     # File app/controllers/backend_troop_movement_controller.rb, line 634
634:   def discharge(troop_movement)
635:     planet = troop_movement.destination_planet
636:     cap = planet.storage_capacity
637:     if(planet.ore + troop_movement.ore < cap)
638:       planet.ore += troop_movement.ore
639:       troop_movement.ore = 0
640:     else
641:       troop_movement.ore -= cap - planet.ore
642:       planet.ore = cap
643:     end
644:     if(planet.crystal + troop_movement.crystal < cap)
645:       planet.crystal += troop_movement.crystal
646:       troop_movement.crystal = 0
647:     else
648:       troop_movement.crystal -= cap - planet.crystal
649:       planet.crystal = cap
650:     end
651:     if(planet.gas + troop_movement.gas < cap)
652:       planet.gas += troop_movement.gas
653:       troop_movement.gas = 0
654:     else
655:       troop_movement.gas -= cap - planet.gas
656:       planet.gas = cap
657:     end
658:     planet.save
659:     troop_movement.save
660:   end

Rückflug zum Startplaneten

 @*params*:typ
 * [*troop_movement*:TroopMovement] (Flotte)

[Source]

     # File app/controllers/backend_troop_movement_controller.rb, line 665
665:   def flight_back(troop_movement)
666:     start = troop_movement.start_planet
667:     dest = troop_movement.destination_planet
668:     troop_movement.start_planet = dest
669:     if(start.owner == troop_movement.user)
670:       troop_movement.destination_planet = start
671:     else
672:       troop_movement.destination_planet = troop_movement.user.homeplanet
673:     end
674:     troop_movement.mission = 5
675:     troop_movement.save
676:     self.set_approach_time(troop_movement)
677:   end

Gasüberschuss transferieren

 @*params*:typ
 * [*troop_movement*:TroopMovement] (Flotte)

[Source]

     # File app/controllers/backend_troop_movement_controller.rb, line 682
682:   def gas_surplus_transfer(troop_movement)
683:     start = troop_movement.start_planet
684:     dest = troop_movement.destination_planet
685:     gas = 0
686:     if(start.solar_system == dest.solar_system)
687:       troop_movement.spaceships.each do |s|
688:         gas += s.count * RulesAndRegulations.mileage_in_system(s.name)
689:       end
690:     else
691:       distance = start.solar_system.calculate_distance(dest.solar_system)
692:       troop_movement.spaceships.each do |s|
693:         gas +=s.count * (2 * RulesAndRegulations.mileage_in_system(s.name) + RulesAndRegulations.mileage_in_hyperspace(s.name) * distance)
694:       end
695:     end
696:     dest.gas = [RulesAndRegulations.planet_capacity(dest), dest.gas + gas].min
697:     dest.save
698:   end

Landet Flotte auf bewohnten Planeten und lädt eventuelle Ressourcen aus @params:typ

[Source]

     # File app/controllers/backend_troop_movement_controller.rb, line 612
612:   def landing(troop_movement)
613:     planet = troop_movement.destination_planet
614:     self.discharge(troop_movement)
615:     
616:     troop_movement.spaceships.each do |ts|
617:       if((ps = planet.spaceships.find(:first, :conditions => {:name => ts.name,
618:                                                               :level => ts.level})) != nil)
619:         ps.count += ts.count
620:         ps.save
621:         ts.destroy
622:       else
623:         ts.troop_movement = nil
624:         planet.spaceships << ts
625:       end
626:     end
627: 
628:     troop_movement.destroy
629:   end

Berechnet den Gasverbrauch der Flotte und zieht ihn vom Planeten ab @params:typ

@return

  • true: Gas abgezogen
  • false: nicht genug Gas vorhanden

[Source]

     # File app/controllers/backend_troop_movement_controller.rb, line 226
226:   def mileage(troop_movement)
227:     ActiveRecord::Base.transaction do
228:       mileage = 0
229:       if([2, 3, 4, 5].any?{|m| m == troop_movement.mission})
230:         factor = 2
231:       else
232:         factor = 1
233:       end
234:         
235:       if(troop_movement.start_planet.solar_system == troop_movement.destination_planet.solar_system)
236:         troop_movement.spaceships.each do |s|
237:           mileage += factor * s.count * RulesAndRegulations.mileage_in_system(s.name)
238:         end
239:         if(troop_movement.mission == 3)
240:           mileage -= RulesAndRegulations.mileage_in_system("Spionagesonde")
241:         end
242:       else
243:         distance = troop_movement.start_planet.solar_system.calculate_distance(troop_movement.destination_planet.solar_system)
244:         troop_movement.spaceships.each do |s|
245:           mileage += factor * s.count * (2 * RulesAndRegulations.mileage_in_system(s.name) + RulesAndRegulations.mileage_in_hyperspace(s.name) * distance)
246:         end
247:         if(troop_movement.mission == 3)
248:           mileage -= 2 * RulesAndRegulations.mileage_in_system("Spionagesonde") + RulesAndRegulations.mileage_in_hyperspace("Spionagesonde") * distance
249:         end
250:       end
251:       
252:       if(troop_movement.start_planet.gas < mileage)
253:         return false
254:       else
255:         troop_movement.start_planet.gas -= mileage
256:         troop_movement.start_planet.save
257:         return true
258:       end
259:     end
260:   end

Verkauft Flotte an fremden Spieler @params:typ

[Source]

     # File app/controllers/backend_troop_movement_controller.rb, line 586
586:   def sell(troop_movement)
587:     sender = User.find_by_name("System")
588:     recipient = troop_movement.user
589:     if(troop_movement.destination_planet.owner != nil)
590:       subject = "Flottenverkauf an " + troop_movement.destination_planet.owner.name
591:       text = "Die Flotte bestehend aus:\n"
592:       troop_movement.spaceships.each do |s|
593:         text += "  " + s.name + "(Stufe " + s.level.to_s + "): " + s.count.to_s + "\n"
594:         s.user = troop_movement.destination_planet.owner
595:         s.save
596:       end
597:       text += "wurde an " + troop_movement.destination_planet.owner.name + " verkauft."
598:       self.landing(troop_movement)
599:     else
600:       self.flight_back(troop_movement)
601:       subject = "Flottenverkauf gescheitert"
602:       text = troop_movement.start_planet.name + " ist inzwischen unbewohnt.\n" +
603:              "Die Flotte kehrt zu " + troop_movement.destination_planet.name + " zurück."
604:     end
605:     BackendMessageController.new.send_message(sender, recipient, subject, text)
606:   end

Berechnet und setzt die Landezeit einer Flotte @params:typ

[Source]

     # File app/controllers/backend_troop_movement_controller.rb, line 197
197:   def set_approach_time(troop_movement)
198:     
199:     start = troop_movement.start_planet
200:     destination = troop_movement.destination_planet
201:     start_time = 0
202:     
203:     troop_movement.spaceships.each do |s|
204:       speed = RulesAndRegulations.movement_speed(s.name, troop_movement.user.speed_techlevel)
205:       if(speed > start_time)
206:         start_time = speed
207:       end
208:     end
209:     
210:     if(start.solar_system == destination.solar_system)
211:       troop_movement.approach_time = Time.now + start_time * 60
212:     else
213:       distance = start.solar_system.calculate_distance(destination.solar_system)
214:       troop_movement.approach_time = Time.new + start_time * 120 + distance * RulesAndRegulations::HYPERSPACE_SPEED * 3600
215:     end
216:   end

Liefert einen Spionagebericht, zerstört eine Spionagesonde und fliegt die restliche Flotte zurück

 @*params*:typ
 * [*troop_movement*:TroopMovement] (Flotte)

[Source]

     # File app/controllers/backend_troop_movement_controller.rb, line 470
470:   def spy(troop_movement)
471:     dest = troop_movement.destination_planet
472:     sender = User.find_by_name("System")
473:     recipient = troop_movement.user
474:     subject = "Spionagebericht vom Planeten " + dest.name
475:     text = "Planet: " + dest.name + "\nGröße: " + dest.fields.to_s + " Felder\n"
476:     if(dest.ore_boni > 1)
477:       text += "Bonus: " + ((dest.ore_boni - 1) * 100).round(2).to_s + "% auf Erzproduktion\n"
478:     elsif(dest.crystal_boni > 1)
479:       text += "Bonus: " + ((dest.crystal_boni - 1) * 100).round(2).to_s + "% auf Kristallproduktion\n"
480:     elsif(dest.gas_boni > 1)
481:       text += "Bonus: " + ((dest.gas_boni - 1) * 100).round(2).to_s + "% auf Gasproduktion\n"
482:     else
483:       text += "keine Boni\n"
484:     end
485:     if(dest.owner == nil)
486:       text += "unbewohnt\n"
487:     else
488:       text += "Besitzer: " + dest.owner.name
489:       if(dest.homeplanet)
490:         text += "(Heimatplanet)"
491:       end
492:       text += "\n\nErz: " + dest.ore.to_s +
493:               "\nKristalle:" + dest.crystal.to_s +
494:               "\nGas: " + dest.gas.to_s + "\n"
495:       if(dest.buildings.find(:first, :conditions => ("level > 0")))
496:         text += "\nvorhandene Gebäude:\n"
497:         dest.buildings.each do |s|
498:           if(s.level > 0)
499:             text += "  " + s.name + "(Stufe " + s.level.to_s + ")\n"
500:           end
501:         end
502:       end
503:       if(dest.spaceships != nil)
504:         text += "\nstationierte Schiffe:\n"
505:         dest.spaceships.each do |s|
506:           text += "  " + s.name + "(Stufe " + s.level.to_s + "): " + s.count.to_s + "\n"
507:         end
508:       end
509:       if(!dest.homeplanet)
510:         text += "\nEs werden " + (dest.fields/RulesAndRegulations::SHUTTLE_CONQUER_FIELDS).to_s +
511:                 " Truppentransporter zum erobern benötigt!"
512:       end
513:     end
514:     
515:     BackendMessageController.new.send_message(sender, recipient, subject, text)
516:       
517:     spion = troop_movement.spaceships.find(:first, :conditions => {:name => "Spionagesonde" })
518:     if(spion.count > 1)
519:       spion.count -= 1
520:       spion.save
521:       self.flight_back(troop_movement)
522:     else
523:       if(troop_movement.spaceships.count == 1)
524:         spion.destroy
525:         troop_movement.destroy
526:       else
527:         spion.destroy
528:         self.flight_back(troop_movement)
529:       end
530:     end
531:   end

Startet eine Flottenbewegung, setzt die Ankunftszeit und überprüft ob die zur Mission nötigen Schiffe vorhanden sind @params:typ

@return

  • 0: Flotte ist gestartet
  • 1: keine Schiffe vorhanden
  • 2: Kolonieschiff fehlt trotz Auftrag Besiedeln
  • 3: Spionagesonde fehlt trotz Auftrag Spionieren
  • 4: Transporter fehlt trotz Auftrag Transport
  • 5: nicht genug Gas für den Flug vorhanden

[Source]

     # File app/controllers/backend_troop_movement_controller.rb, line 166
166:   def starting(troop_movement)
167:     if(troop_movement.spaceships.length == 0)
168:       return 1
169:     end
170:     if(troop_movement.mission == 4 and 
171:        troop_movement.spaceships.find(:first, :conditions => {:name => "Transporter" }) == nil)
172:       return 4
173:     end
174:     
175:     if(troop_movement.mission == 3 and 
176:        troop_movement.spaceships.find(:first, :conditions => {:name => "Spionagesonde" }) == nil)
177:       return 3
178:     end
179:     
180:     if(troop_movement.mission == 2 and 
181:        troop_movement.spaceships.find(:first, :conditions => {:name => "Kolonieschiff" }) == nil)
182:       return 2
183:     end
184:     
185:     if(!self.mileage(troop_movement))
186:       return 5
187:     end
188:     
189:     self.set_approach_time(troop_movement)
190:     troop_movement.save
191:     return 0
192:   end

Stationiert Flotte auf eigenem Planeten oder fliegt zurück falls Planet inzwischen erobert wurde @params:typ

[Source]

     # File app/controllers/backend_troop_movement_controller.rb, line 566
566:   def station(troop_movement)
567:     sender = User.find_by_name("System")
568:     recipient = troop_movement.user
569:     subject = "Landung auf " + troop_movement.destination_planet.name
570:     if(troop_movement.destination_planet.owner == troop_movement.user)
571:       text = "Die Flotte ist erfolgreich auf " +
572:              troop_movement.destination_planet.name + " gelandet."
573:       self.gas_surplus_transfer(troop_movement)
574:       self.landing(troop_movement)
575:     else     
576:       self.flight_back(troop_movement)
577:       text = troop_movement.start_planet.name + " wurde inzwischen erobert.\n" +
578:              "Die Flotte kehrt zu " + troop_movement.destination_planet.name + " zurück."
579:     end
580:     BackendMessageController.new.send_message(sender, recipient, subject, text)
581:   end

Transportiert Ressourcen auf bewohnten Planeten und fliegt zum Ausgangspunkt zurück @params:typ

[Source]

     # File app/controllers/backend_troop_movement_controller.rb, line 537
537:   def transport(troop_movement)
538:     sender = User.find_by_name("System")
539:     recipient = troop_movement.user
540:     subject = "Ressourcentransport nach " + troop_movement.destination_planet.name
541:     if(troop_movement.destination_planet.owner != nil)
542:       ore = troop_movement.ore
543:       crystal = troop_movement.crystal
544:       gas = troop_movement.gas
545:       self.discharge(troop_movement)
546:       self.flight_back(troop_movement)
547:       text = "Auf " + troop_movement.start_planet.name + " wurde " +
548:              (ore - troop_movement.ore).to_s + " Erz, " +
549:              (crystal - troop_movement.crystal).to_s + " Kristall und " +
550:              (gas - troop_movement.gas).to_s + " Gas ausgeladen.\n" +
551:              "Die Flotte kehrt zu " + troop_movement.destination_planet.name + " zurück."
552:     else
553:       self.flight_back(troop_movement)
554:       text = troop_movement.start_planet.name + " war bei Ankunft unbewohnt.\n" +
555:              "Die Flotte kehrt mit den Ressourcen zu " +
556:              troop_movement.destination_planet.name + " zurück."
557:     end
558:     BackendMessageController.new.send_message(sender, recipient, subject, text)
559:   end

[Validate]