View Single Post
  #5  
Old 12-18-2011, 07:43 AM
41Sqn_Banks 41Sqn_Banks is offline
Approved Member
 
Join Date: Oct 2007
Posts: 644
Default

Quote:
The problem is likely not in aircrafts, but in the side actors such as smoke, debris and craters from bombs, which creates the game itself, and does not remove properly.
The problem is that the not destroyed aircraft just sit on an airfield with empty tanks and guns and didn't move at all

Quote:
Originally Posted by Octocat View Post
Also, small remark:

Generally, it is better to use explicit conversion, because in case Foo foo = something as Foo; if something is not Foo, operator "as" return null reference, and in the file log.txt you can get uninformative message "Object reference not set to an instance of an object."

If you use explicit cast Foo foo = (Foo)something; if something is not Foo, cast operator throw an exception immediately, and in the log.txt you get more informative "Unable to cast object of type 'Bar' to 'Foo'".


I also want to say thank you for the source of DCE. Nice work.
That's why there is a "if(something is Foo)" before the cast to prevent any exception But I agree if I'd forget the check the cast exception gives better feedback.

As a note to your example:

Code:
private void DestroyAircrafts(IGamePlay game)
{
  foreach (int army in game.gpArmies())
    foreach (var group in game.gpAirGroups(army))
      foreach (var item in group.GetItems())
        ((AiAircraft)item).Destroy();
}
The functions of IGamePlay that return an array of something do not return an empty array but return null if there is nothing to return. In this case your code will throw a reference null exception. It's better to check the return value before using them in the foreach loop, e.g.:

Code:
if (GamePlay.gpAirGroups(army) != null && GamePlay.gpAirGroups(army).Length > 0)

About the initial problem: Looks like I have to look a bit closer to see what causes this.
Reply With Quote