URL:
  <http://gna.org/patch/?3776>

                 Summary: server/barbarian.c:create_barbarian_player fix
deficencies
                 Project: Freeciv
            Submitted by: imhotep
            Submitted on: Mon 11 Mar 2013 07:51:58 PM GMT
                Category: None
                Priority: 5 - Normal
                  Status: None
                 Privacy: Public
             Assigned to: None
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any
         Planned Release: 

    _______________________________________________________

Details:

This patch is for 2.4.99-dev r22446

Aside from the fact that the name is misleading (it does not normally create a
new barbarian),, the function server/barbarian.c:create_barbarian_player lacks
randomness and prefers recycling of already existing barbarians before
creating new ones.

Existing code:
If there is a barbarian player of the requested type, it is reused.
If there is more than one of them, the first found by iterating the list is
returned. Which one that is might be implementation dependent but in all cases
lacks proper randomness.

Only if no barbarian of the requested type is found, a new one is created.

If for some reason the pick_a_nation-function returns NULL, the server crashes
with segmentation fault.

Patch (intended behavior, probably needs review and more testing): 
One of the existing barbarians with requested type is chosen truly random from
the existing ones.
If an new barbarian player of that type can be created, it is chosen with a
probability equal to the already existing ones.

If there is no available nation for the new barbarian, it is not considered.

Reason for the patch:
the patch removes some hidden bugs (the code where the server crashes is not
reached in the original code only because no new barbarians are created once
one of each type is present).

In view of http://gna.org/bugs/?17606 there will be more than one barbarian
nation for each type, making the random choose more complex than the present
"choose one out of one".

In view of the new gameloss_style options ( https://gna.org/bugs/?20577 ),
when there is only one barbarian this one and only gets far too strong.

Other issues:
In the preexisting code, when an existing barbarian player is reused, it gets
100 gold extra. I don't know if this is really intended, but as I don't know
otherwise, I ported this feature to the new code.

Have a lot of fun.

BTW: I have not found out yet how to see a preview of a submit nor a
description on how to do some common features, so as to cite previous posts or
properly include links. So, until someone cares to give me a hint on any
errors, you all will have to live with my self-made style.





    _______________________________________________________

File Attachments:


-------------------------------------------------------
Date: Mon 11 Mar 2013 07:51:58 PM GMT  Name:
create_barbarian_player_22446.patch  Size: 4kB   By: imhotep

<http://gna.org/patch/download.php?file_id=17419>

    _______________________________________________________

Reply to this item at:

  <http://gna.org/patch/?3776>

_______________________________________________
  Message sent via/by Gna!
  http://gna.org/


_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to