Re: [Freeciv-Dev] (PR#39530) Wonders don't allow units

2009-05-04 Thread Marko Lindqvist

URL: http://bugs.freeciv.org/Ticket/Display.html?id=39530 

2007/8/11 ba...@actrix.co.nz ba...@actrix.co.nz:

 Hi

 With rndCiv i use Wonders to define special races,
 ie if you build The Elves wonder you can build Elvish units.

 I found that this didn't work, so i made building The Elves
 allowed you to build Elveshome in your cities which allowed
 you to build Elvish units.

 Only now I understood this bug report; how badly broken that part of
code is. This far I assumed you referred to wonders at different
range, but actually even local wonders cannot enable unit building. So
they do *worse* than normal buildings.

 Untested fix attached


 - ML

diff -Nurd -X.diff_ignore freeciv/common/improvement.c freeciv/common/improvement.c
--- freeciv/common/improvement.c	2008-10-27 04:13:30.0 +0200
+++ freeciv/common/improvement.c	2009-05-05 01:23:15.0 +0300
@@ -532,6 +532,20 @@
 }
 
 /**
+  Get the player owning this small wonder.
+**/
+struct player *great_wonder_owner(const struct impr_type *pimprove)
+{
+  struct city *pcity = find_city_from_great_wonder(pimprove);
+
+  if (!pcity) {
+return NULL;
+  }
+
+  return city_owner(pcity);
+}
+
+/**
   Get the player city with this small wonder.
 **/
 struct city *find_city_from_small_wonder(const struct player *pplayer,
diff -Nurd -X.diff_ignore freeciv/common/improvement.h freeciv/common/improvement.h
--- freeciv/common/improvement.h	2008-10-27 04:13:30.0 +0200
+++ freeciv/common/improvement.h	2009-05-05 01:24:30.0 +0300
@@ -116,6 +116,7 @@
 struct city *find_city_from_great_wonder(const struct impr_type *pimprove);
 struct city *find_city_from_small_wonder(const struct player *pplayer,
 	 const struct impr_type *pimprove);
+struct player *great_wonder_owner(const struct impr_type *pimprove);
 
 /* player related improvement functions */
 bool improvement_obsolete(const struct player *pplayer,
diff -Nurd -X.diff_ignore freeciv/common/unittype.c freeciv/common/unittype.c
--- freeciv/common/unittype.c	2008-10-27 04:13:30.0 +0200
+++ freeciv/common/unittype.c	2009-05-05 01:24:02.0 +0300
@@ -697,9 +697,21 @@
   /* If the unit has a building requirement, we check to see if the player
* can build that building.  Note that individual cities may not have
* that building, so they still may not be able to build the unit. */
-  if (punittype-need_improvement
-   !can_player_build_improvement_direct(p, punittype-need_improvement)) {
-return FALSE;
+  if (punittype-need_improvement) {
+if (is_great_wonder(punittype-need_improvement) 
+great_wonder_was_built(punittype-need_improvement)) {
+  /* It's already built great wonder */
+  if (great_wonder_owner(punittype-need_improvement) != p) {
+/* Not owned by this player. Either destroyed or owned by somebody
+ * else. */
+return FALSE;
+  }
+} else {
+  if (!can_player_build_improvement_direct(p,
+   punittype-need_improvement)) {
+return FALSE;
+  }
+}
   }
 
   return TRUE;
diff -Nurd -X.diff_ignore freeciv/common/improvement.c freeciv/common/improvement.c
--- freeciv/common/improvement.c	2008-07-09 10:44:51.0 +0300
+++ freeciv/common/improvement.c	2009-05-05 01:31:31.0 +0300
@@ -473,6 +473,20 @@
 }
 
 /**
+  Get the player owning this small wonder.
+**/
+struct player *great_wonder_owner(Impr_type_id id)
+{
+  struct city *pcity = find_city_from_great_wonder(id);
+
+  if (!pcity) {
+return NULL;
+  }
+
+  return city_owner(pcity);
+}
+
+/**
   Get the player city with this small wonder.
 **/
 struct city *find_city_from_small_wonder(const struct player *pplayer,
diff -Nurd -X.diff_ignore freeciv/common/improvement.h freeciv/common/improvement.h
--- freeciv/common/improvement.h	2008-07-09 10:44:51.0 +0300
+++ freeciv/common/improvement.h	2009-05-05 01:30:48.0 +0300
@@ -132,6 +132,7 @@
 struct city *find_city_from_great_wonder(Impr_type_id id);
 struct city *find_city_from_small_wonder(const struct player *pplayer,
 	 Impr_type_id id);
+struct player *great_wonder_owner(Impr_type_id id);
 
 bool great_wonder_was_built(Impr_type_id id);
 
diff -Nurd -X.diff_ignore freeciv/common/unittype.c freeciv/common/unittype.c
--- freeciv/common/unittype.c	2007-07-04 14:04:25.0 +0300
+++ freeciv/common/unittype.c	2009-05-05 01:34:53.0 

Re: [Freeciv-Dev] (PR#39530) Wonders don't allow units

2007-08-24 Thread Egor Vyscrebentsov

URL: http://bugs.freeciv.org/Ticket/Display.html?id=39530 

On Thu, 23 Aug 2007 Marko Lindqvist wrote:

  Actual problem is that unit improvement requirement has no ruleset
 defined range. Building is always required in City range. This is
 what we usually want for normal buildings, and for some wonders.
  Just changing hardcoded range to be Player for wonders would
 replace bug with another. Do we want *all* the wonders to provide unit
 building abilities in all cities?

No, please. Several wonders may affect all the nation (or even world),
several may affect only one city. Why this should differ for units?

-- 
Thanks, evyscr



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


Re: [Freeciv-Dev] (PR#39530) Wonders don't allow units

2007-08-23 Thread [EMAIL PROTECTED]

URL: http://bugs.freeciv.org/Ticket/Display.html?id=39530 

[EMAIL PROTECTED] wrote:
 URL: http://bugs.freeciv.org/Ticket/Display.html?id=39530 

 With rndCiv i use Wonders to define special races,
 ie if you build The Elves wonder you can build Elvish units.
 
 I found that this didn't work, so i made building The Elves
 allowed you to build Elveshome in your cities which allowed
 you to build Elvish units.

 It would be simpler for me, and prolly for the code, if Wonders
 could allow certain units to be built, either on a City, Island,
 Nation, or Planet wide basis.
 
 This wouldn't affect the default rulesets, but would allow more
 complexity in mods.

Ive looked through the code, and i find that the functions that check
whether a unit can be built...

   common/city.c:490 can_build_unit
- calls can_build_unit_direct  can_player_build_unit_direct

   common/city.c:463 can_build_unit_direct
- calls can_player_build_unit_direct

   common/unittypes.c:503 can_player_build_unit_direct
  - calls can_player_build_improvement_direct

end up calling...

   common/improvement.c:312 can_player_build_improvement_direct

which returns false, if the improvement is a wonder  the wonder has
been built.

Which means that a unit that's impr_req is a wonder will never be able
to be built as  can_player_build_improvement_direct() will return false.

It seems that can_player_build_improvement_direct() is used for two
purposes, to check if a building can be built  to check if a unit can
be built.

im not a c coder, but my initial solution..

   can_player_build_improvement_direct {
X  = main code
Z  = wonder check
   }

becomes...


   can_player_build_improvement_direct_main {
X
   }

   can_player_build_improvement_direct {
can_player_build_improvement_direct_main()
Z
   }

Tests that come from unit functions use
   can_player_build_improvement_direct_main()

Tests that come from building functions use
   an_player_build_improvement_direct()

or something like that

-billy






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


Re: [Freeciv-Dev] (PR#39530) Wonders don't allow units

2007-08-23 Thread [EMAIL PROTECTED]

URL: http://bugs.freeciv.org/Ticket/Display.html?id=39530 

Marko Lindqvist wrote:
 URL: http://bugs.freeciv.org/Ticket/Display.html?id=39530 
 
 On 23/08/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] wrote:

 With rndCiv i use Wonders to define special races,
 ie if you build The Elves wonder you can build Elvish units.

 I found that this didn't work, so i made building The Elves
 allowed you to build Elveshome in your cities which allowed
 you to build Elvish units.

 It would be simpler for me, and prolly for the code, if Wonders
 could allow certain units to be built, either on a City, Island,
 Nation, or Planet wide basis.

 This wouldn't affect the default rulesets, but would allow more
 complexity in mods.
 Ive looked through the code, and i find that the functions that check
 whether a unit can be built...

common/city.c:490 can_build_unit
 - calls can_build_unit_direct  can_player_build_unit_direct

common/city.c:463 can_build_unit_direct
 - calls can_player_build_unit_direct

common/unittypes.c:503 can_player_build_unit_direct
   - calls can_player_build_improvement_direct

 end up calling...

common/improvement.c:312 can_player_build_improvement_direct

 which returns false, if the improvement is a wonder  the wonder has
 been built.
 
  Actual problem is that unit improvement requirement has no ruleset
 defined range. Building is always required in City range. This is
 what we usually want for normal buildings, and for some wonders.
  Just changing hardcoded range to be Player for wonders would
 replace bug with another. Do we want *all* the wonders to provide unit
 building abilities in all cities?
 
 
  - ML
 
 

Having made a lot of rulesets for rndCiv, ive never wanted to allow a
unit to be buildable globally by everybody if a Wonder existed.

Sometimes ive wanted a unit to be buildable globally by the Wonder
owner, but handle that by having another building be buildable if
you own the wonder, that building allows the unit to be built.

Mostly i want the Wonder to have the same usage as ordinary impr_req
buildings.  If the wonder is in the city, and not obsolete, the unit
is buildable.

That's more than we can do right now, it keeps the standard impr_req
usage, it doesn't break impr_req expectations (ie, it's taken me a long
time to notice the problem), it would make rndCiv much better, and it
could be extended later on if required.

-billy



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


[Freeciv-Dev] (PR#39530) Wonders don't allow units

2007-08-11 Thread [EMAIL PROTECTED]

URL: http://bugs.freeciv.org/Ticket/Display.html?id=39530 

Hi

With rndCiv i use Wonders to define special races,
ie if you build The Elves wonder you can build Elvish units.

I found that this didn't work, so i made building The Elves
allowed you to build Elveshome in your cities which allowed
you to build Elvish units.

Of course, if you build an Elveshome and lose The Elves
you can still build Elvish units.  If you conquer a city with
a Elveshome you can build Elves.

It's fiddly and annoying, but i can live with it.

But i also had, Lizardman Nests as wonders, but couldn't
build Lizardmen warriors unless i create a City Improvement
that can only be built with the Wonder, to allow the units
to be built - it's ugly.

I also wanted special case units, like..
Foreign Legion: requires Eiffel Tower
Men In Black:   requires NSA
Evil Magician:  requires Temple of Doom
Angel:  requires Holy City
etc,

It would be simpler for me, and prolly for the code, if Wonders
could allow certain units to be built, either on a City, Island,
Nation, or Planet wide basis.

This wouldn't affect the default rulesets, but would allow more
complexity in mods.

Civ ties special units to a Nation, i think this is stupid.
Ie, Germany and the Panzer, the real reason Germany had the Panzer
is not that it's inherent in their national makeup, but that tanks
were new and Germany having being beaten in WWI engaged in a complete
rethink of their military doctrine - it's context dependent.

-billy



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