Adding backend support for missiles

Programmers discuss here anything related to FreeOrion programming. Primarily for the developers to discuss.

Moderators: Committer, Committer

Post Reply
Message
Author
User avatar
Oberlus
Cosmic Dragon
Posts: 1941
Joined: Mon Apr 10, 2017 4:25 pm

Adding backend support for missiles

#1 Post by Oberlus » Mon Feb 10, 2020 11:54 am

I'm trying to add backend support for a new type of weapon, missiles, much alike fighters with two key diferencies:
- Apply their damage after ships and fighters (and planets), so they can be shot down before they hit anything.
- Self-destruct on successful hit.

There's a lot of files and stuff to be changed but most of what must be done seems obvious, but my ignorance about C++ makes some parts rather obcure to me. My C++ knowledge reduces to the basic concepts of OOP and some spare coding before 2000. There're some pieces of code that I have no clue what they could do (I mean the general syntax like the constructors' or those <name>::<name>::<name> I see everywhere).

My first serious doubt:

How to differentiate between missiles and fighters in std::string FighterOrPublicNameLink

https://github.com/freeorion/freeorion/ ... #L102-L109

Code: Select all

    /// Creates a link tag of the appropriate type for either a fighter or another object.
    std::string FighterOrPublicNameLink(
        int viewing_empire_id, int object_id, int object_empire_id) {
        if (object_id >= 0)   // ship
            return PublicNameLink(viewing_empire_id, object_id);
        else                  // fighter
            return EmpireColorWrappedText(object_empire_id, UserString("OBJ_FIGHTER"));
    }
I shall add this to account for the missile's case:

Code: Select all

            return EmpireColorWrappedText(object_empire_id, UserString("OBJ_MISSILE"));
But I can't tell appart fighters from missiles based on object_id since they both share the same range of negative values.

How can I check the type of the object from its object_id?

Or what should I be passing to FighterOrPublicNameLink() (from the multiple places it's called) instead of object_id to have access to the object type/class?
Last edited by Oberlus on Mon Feb 10, 2020 5:31 pm, edited 1 time in total.

User avatar
Oberlus
Cosmic Dragon
Posts: 1941
Joined: Mon Apr 10, 2017 4:25 pm

Re: Adding backend support for missiles [help wanted]

#2 Post by Oberlus » Mon Feb 10, 2020 12:03 pm

Maybe I asked too fast. I guess I can use

Code: Select all

auto object = GetUniverseObject(object_id)
and then

Code: Select all

object->ObjectType() == OBJ_FIGHTER // or OBJ_MISSILE

User avatar
adrian_broher
Programmer
Posts: 1100
Joined: Fri Mar 01, 2013 9:52 am
Location: Germany

Re: Adding backend support for missiles [help wanted]

#3 Post by adrian_broher » Mon Feb 10, 2020 12:07 pm

Is there any first class object for missles? If yes pass the object and cast toward a missle. If not how is a missle represented in the first place?
Resident code gremlin
Attached patches are released under GPL 2.0 or later.
Git author: Marcel Metz

User avatar
Oberlus
Cosmic Dragon
Posts: 1941
Joined: Mon Apr 10, 2017 4:25 pm

Re: Adding backend support for missiles [help wanted]

#4 Post by Oberlus » Mon Feb 10, 2020 12:19 pm

adrian_broher wrote:
Mon Feb 10, 2020 12:07 pm
Is there any first class object for missles? If yes pass the object and cast toward a missle. If not how is a missle represented in the first place?
I have no clear idea how are fighters represented, or ships.
I'm creating universe/Missile.cpp and .h (copied from universe/Fighter.cpp and .h).
If I understand what I'm doing, missiles will be a class derived from UniverseObject, same as fighters.
I'm not sure I've answered your question.

User avatar
adrian_broher
Programmer
Posts: 1100
Joined: Fri Mar 01, 2013 9:52 am
Location: Germany

Re: Adding backend support for missiles [help wanted]

#5 Post by adrian_broher » Mon Feb 10, 2020 12:34 pm

Oberlus wrote:
Mon Feb 10, 2020 12:19 pm
]I'm not sure I've answered your question.
Somewhat. When you've created a new Missle class and have added a new OBJ_MISSLE enum entry the selection by ObjectType() is feasible. The negative IDs are there to identify temporary UniverseObjects, that only exist during the lifetime of a combat. It may be possible that those IDs don'r resolve to an UniverseObject, that is why LGMDolye chose to select the negative value comparision.
Resident code gremlin
Attached patches are released under GPL 2.0 or later.
Git author: Marcel Metz

User avatar
Oberlus
Cosmic Dragon
Posts: 1941
Joined: Mon Apr 10, 2017 4:25 pm

Re: Adding backend support for missiles [help wanted]

#6 Post by Oberlus » Mon Feb 10, 2020 4:22 pm

I've added enum entries for OBJ_MISSILE, PC_MISSILE_HANGAR and PC_MISSILE_BAY in universe/Enum.h.
I found no mentions to fighter, weapon, part or damage at universe/Enum.cpp so I changed nothing there.

I'll keep in mind that negative IDs could not resolve to a UniverseObj and look for a viable way if that happens.
Ultimately, I could let the combat log to not differenciate between fighters and missiles and just say "fighter or missile" (in such case, look for a single word to convey both types).

User avatar
Oberlus
Cosmic Dragon
Posts: 1941
Joined: Mon Apr 10, 2017 4:25 pm

Re: Adding backend support for missiles

#7 Post by Oberlus » Wed Feb 12, 2020 5:35 pm

While I'm at this, I've spotted the following:

The Or condition in line 321 of CombatSystem.cpp is redundant.

Starting from the previous line, it is:

Code: Select all

Or
  Or
    Ship with structure > 0.0
    Fighter
  Planet with shields, defense or infrastructure > 0.0
It could be simplified to

Code: Select all

Or
  Ship with structure > 0.0
  Fighter
  Planet with shields, defense or infrastructure > 0.0
Is it OK if I do this kind of simplifications while I'm working on the missiles and commit them undocumented in the same PR?

Ophiuchus
Programmer
Posts: 1158
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Adding backend support for missiles

#8 Post by Ophiuchus » Thu Feb 13, 2020 8:31 am

Oberlus wrote:
Wed Feb 12, 2020 5:35 pm
While I'm at this, I've spotted the following:

The Or condition in line 321 of CombatSystem.cpp is redundant.
...
Is it OK if I do this kind of simplifications while I'm working on the missiles and commit them undocumented in the same PR?
It is maybe redundant, but necessary ATM as the backend only supports two-param Or conditions, you have to nest.

If you fix anything unrelated to missiles, put it (also) in another PR.

If you want to extend Or/And to support multiple subconditions that would be great IMHO. Or even better allow those conditions to be specified in FOCS.
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Furthermore, I propse... we should default to four combat rounds instead of three ...for the good of playerkind.

User avatar
Oberlus
Cosmic Dragon
Posts: 1941
Joined: Mon Apr 10, 2017 4:25 pm

Re: Adding backend support for missiles

#9 Post by Oberlus » Thu Feb 13, 2020 8:46 am

Ophiuchus wrote:
Thu Feb 13, 2020 8:31 am
It is maybe redundant, but necessary ATM as the backend only supports two-param Or conditions, you have to nest.
That's what I thought at the first moment, but I also found a Or condition with three params, the OR(defense>0,shield>0,construction>0) for armed planets.. So is it supported or not?
Ophiuchus wrote:
Thu Feb 13, 2020 8:31 am
If you fix anything unrelated to missiles, put it (also) in another PR.
Noted.
Ophiuchus wrote:
Thu Feb 13, 2020 8:31 am
Or even better allow those conditions to be specified in FOCS.
Whoa, I have no idea how that works. But I keep understanding things while skimming through the code.

Ophiuchus
Programmer
Posts: 1158
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Adding backend support for missiles

#10 Post by Ophiuchus » Thu Feb 13, 2020 10:48 am

Oberlus wrote:
Thu Feb 13, 2020 8:46 am
Ophiuchus wrote:
Thu Feb 13, 2020 8:31 am
It is maybe redundant, but necessary ATM as the backend only supports two-param Or conditions, you have to nest.
That's what I thought at the first moment, but I also found a Or condition with three params, the OR(defense>0,shield>0,construction>0) for armed planets.. So is it supported or not?
Outdated knowledge on my side. Seems we already added support for two to four arguments. Could be probably made variadic.
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Furthermore, I propse... we should default to four combat rounds instead of three ...for the good of playerkind.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 12528
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Adding backend support for missiles

#11 Post by Geoff the Medio » Thu Feb 13, 2020 3:34 pm

Support for more than 2 arguments as single condition pointers was relatively recent, so the code that doesn't use it might predate the possibility...

https://github.com/freeorion/freeorion/ ... 4deb27a8a8

Post Reply