Barbarian

Can you help improve your favourite game? Hardcore C mages, talented artists, and players with any level of experience are welcome!
Post Reply
gm1530
Posts: 27
Joined: Fri Mar 29, 2013 11:48 am

Barbarian

Post by gm1530 »

I follow this guide: http://svn.gna.org/viewcvs/freeciv?view ... sion=29241

I can find UTYF_BARBARIAN_ONLY:

client/helpdata.c

Code: Select all

  if (utype_has_flag(utype, UTYF_BARBARIAN_ONLY)) {
    CATLSTR(buf, bufsz, _("* Only barbarians may build this.\n"));
  }
common/unittype.c

Code: Select all

  if (utype_has_flag(punittype, UTYF_BARBARIAN_ONLY)
      && !is_barbarian(p)) {
    /* Unit can be built by barbarians only and this player is
     * not barbarian */
    return FALSE;
  }
common/unittype.h

Code: Select all

 /* Only barbarians can build this unit */
 #define SPECENUM_VALUE27 UTYF_BARBARIAN_ONLY
 #define SPECENUM_VALUE27NAME N_("?unitflag:BarbarianOnly")
Ok, let's rewrite... I delete "functions" in client/helpdata.c and common/unittype.h, but I edit function in common/unittype.c.
common/unittype.c

Code: Select all

   if (utype_can_do_action(punittype, ACTION_BARBARIAN_ONLY)
      && !is_barbarian(p)) {
    /* Unit can be built by barbarians only and this player is
     * not barbarian */
    return FALSE;
  }
Now I add:
common/actions.h

Code: Select all

 #define SPECENUM_VALUE21 ACTION_BARBARIAN_ONLY
 #define SPECENUM_VALUE21NAME N_("I don't know... maybe Barbarian_only?")
common/actions.c

Code: Select all

 	   actions[ACTION_BARBARIAN_ONLY] =
	  	       action_new(ACTION_BARBARIAN_ONLY,
	  	                  ATK_UNITS,
	  	                  FALSE);
and

Code: Select all

  if (wanted_action == ACTION_BARBARIAN_ONLY) {
    /* Reason: The Freeciv code assumes that I don't know. */
    if (unit_tile(actor_unit) != target_tile) {
      return FALSE;
    }

    /* TODO: Move more individual requirements to the action enabler. */
    if (!is_barbarian(actor_player)) {
      return FALSE;
    }
  }
and

Code: Select all

 	   case ACTION_BARBARIAN_ONLY:
	  	     chance = 200;
	  	     break;
About common/actions.c, where I put "/* ??? */", what I have to write? It's ATK_CITY, ATK_UNITS or ATK_TILES? It's target_tile? Is there a rule? And it's TRUE or FALSE? Is there another rule? I don't know if I have the skills to complete/code this, but I think it's very useful if it's possible define a rule to identify if it's CITY, UNITS or TILES.

The main question is useful vs. pointless.
sveinung
Elite
Posts: 548
Joined: Wed Feb 20, 2013 4:50 pm

Re: Barbarian

Post by sveinung »

gm1530 wrote:About common/actions.c, where I put "/* ??? */", what I have to write? It's ATK_CITY, ATK_UNITS or ATK_TILES? It's target_tile? Is there a rule? And it's TRUE or FALSE? Is there another rule?
See the definition of action_new(). Let me know if the parameter names aren't self explanatory.
gm1530 wrote:I think it's very useful if it's possible define a rule to identify if it's CITY, UNITS or TILES.
The target is who the action is done to. The target_reqs of an action enabler are evaluated against the target. The target kind depends on who doing the action affects and on who rules regulating it may wish to mention. Note that the action enabler system currently only can handle actions where the actor is a unit and the target is a city, a unit, a unit stack or a tile.
gm1530 wrote:The main question is useful vs. pointless.
An action is something a player can do to achieve something in the game. BarbarianOnly isn't an action.

What was the goal behind your suggestion?
gm1530
Posts: 27
Joined: Fri Mar 29, 2013 11:48 am

Re: Barbarian

Post by gm1530 »

Thank you for your prompt reply.
sveinung wrote:See the definition of action_new(). Let me know if the parameter names aren't self explanatory.
Right.. That is clear
sveinung wrote:What was the goal behind your suggestion?
My goal? There was no goal behind my suggestion. I've followed your progress on Freeciv's code (especially on Action). Many times I've read that you turn "UTYF_SOMETHING" into "ACTION_SOMETHING".

So I've thought... "Well... It's fantastic... So the main goal is transformed all "UTYF_SOMETHING".. Maybe I can help if the process isn't too complicated".

My idea of open source project is helping the programmers or coders from repetitive tasks. The same reasoning was behind this http://gna.org/patch/?6127 or http://gna.org/patch/?3332 (only 'requirement_vector reqs' for Nations, others were useless).... but the main question is always: useful or pointless?
sveinung
Elite
Posts: 548
Joined: Wed Feb 20, 2013 4:50 pm

Re: Barbarian

Post by sveinung »

gm1530 wrote:
sveinung wrote:What was the goal behind your suggestion?
My goal? There was no goal behind my suggestion. I've followed your progress on Freeciv's code (especially on Action). Many times I've read that you turn "UTYF_SOMETHING" into "ACTION_SOMETHING".

So I've thought... "Well... It's fantastic... So the main goal is transformed all "UTYF_SOMETHING".. Maybe I can help if the process isn't too complicated".

My idea of open source project is helping the programmers or coders from repetitive tasks.
Sounds like a goal to me. (Language issue?) A goal that can be accomplished. Are you interested in giving Expel Unit a try? It's a new action. It has a unit actor and a unit target. No randomness (battle, dice roll, etc) involved. It isn't a spy action. Rules about who can expel whom belongs in the action enabler in the ruleset. No need to worry about porting the old rules, consistency with similar actions, non supported actor or target kind, battles or what the rules should be. The target player must have a capital to expel the unit to before the expelled unit can be sent to it. That should probably be a hard coded requirement in is_action_possible() and an assertion in the function that executes the action. AI support can probably wait. The down side of no similar actions is that you can't hook into pre existing AI code.
gm1530
Posts: 27
Joined: Fri Mar 29, 2013 11:48 am

Re: Barbarian

Post by gm1530 »

sveinung wrote:Are you interested in giving Expel Unit a try? It's a new action.
Ok.
Post Reply