[Freeciv-Dev] Re: (PR#9763) Not fair: get_defender() fallbacs to tile ar
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: |
undisclosed-recipients: ; |
Subject: |
[Freeciv-Dev] Re: (PR#9763) Not fair: get_defender() fallbacs to tile arrival time when selecting between equal units. |
From: |
"Marko Lindqvist" <marko.lindqvist@xxxxxxxxxxx> |
Date: |
Sun, 22 Aug 2004 15:01:58 -0700 |
Reply-to: |
rt@xxxxxxxxxxx |
<URL: http://rt.freeciv.org/Ticket/Display.html?id=9763 >
Marko Lindqvist wrote:
> change. But I think it would be quite easy to change 2 so that unit
> arriving to tile is placed to random position in list.
Untested patch attached.
- Caz
diff -Nurd -X.diff_ignore freeciv/server/unittools.c freeciv/server/unittools.c
--- freeciv/server/unittools.c 2004-08-22 13:33:08.140625000 +0300
+++ freeciv/server/unittools.c 2004-08-23 00:12:51.375000000 +0300
@@ -2712,7 +2712,7 @@
if (punit->moves_left == 0) {
punit->done_moving = TRUE;
}
- unit_list_insert(&pdesttile->units, punit);
+ unit_list_insert_rnd(&pdesttile->units, punit);
check_unit_activity(punit);
/*
diff -Nurd -X.diff_ignore freeciv/utility/genlist.c freeciv/utility/genlist.c
--- freeciv/utility/genlist.c 2004-08-22 13:33:09.937500000 +0300
+++ freeciv/utility/genlist.c 2004-08-23 00:10:35.609375000 +0300
@@ -119,7 +119,8 @@
Insert a new element in the list, at position 'pos', with the specified
user-data pointer 'data'. Existing elements at >= pos are moved one
space to the "right". Recall 'pos' can be -1 meaning add at the
- end of the list. For an empty list pos has no effect.
+ end of the list. Position can be also random, GENLIST_RANDOM_POS.
+ For an empty list pos has no effect.
A bad 'pos' value for a non-empty list is treated as -1 (is this
a good idea?)
************************************************************************/
@@ -139,6 +140,12 @@
}
else {
+
+ if ( pos == GENLIST_RANDOM_POS ) {
+ /* Possible positions are before any old element or in the end. */
+ pos = myrand( genlist_size(pgenlist) + 1) - 1;
+ }
+
struct genlist_link *plink=(struct genlist_link *)
fc_malloc(sizeof(struct genlist_link));
plink->dataptr=data;
diff -Nurd -X.diff_ignore freeciv/utility/genlist.h freeciv/utility/genlist.h
--- freeciv/utility/genlist.h 2004-08-22 13:33:09.937500000 +0300
+++ freeciv/utility/genlist.h 2004-08-22 23:54:11.937500000 +0300
@@ -27,7 +27,8 @@
Positions in the list are specified starting from 0, up to n-1
for a list with n elements. The position -1 can be used to
refer to the last element (that is, the same as n-1, or n when
- adding a new element), but other negative numbers are not
+ adding a new element). genlist_insert() accepts also special
+ value GENLIST_RANDOM_POS. Other negative numbers are not
meaningful.
There are two memory management issues:
@@ -88,6 +89,8 @@
#define ITERATOR_NEXT(iter) (iter = (iter)->next)
#define ITERATOR_PREV(iter) (iter = (iter)->prev)
+#define GENLIST_RANDOM_POS (-2)
+
/* This is to iterate for a type defined like:
struct unit_list { struct genlist list; };
diff -Nurd -X.diff_ignore freeciv/utility/speclist.h freeciv/utility/speclist.h
--- freeciv/utility/speclist.h 2004-08-22 13:33:10.328125000 +0300
+++ freeciv/utility/speclist.h 2004-08-23 00:12:23.421875000 +0300
@@ -35,6 +35,7 @@
foo_t *foo_list_get(struct foo_list *This, int index);
void foo_list_insert(struct foo_list *This, foo_t *pfoo);
void foo_list_insert_back(struct foo_list *This, foo_t *pfoo);
+ void foo_list_insert_rnd(struct foo_list *This, foo_t *pfoo);
void foo_list_unlink(struct foo_list *This, foo_t *pfoo);
void foo_list_unlink_all(struct foo_list *This);
void foo_list_sort(struct foo_list *This,
@@ -106,6 +107,11 @@
genlist_insert(&tthis->list, pfoo, -1);
}
+static inline void SPECLIST_FOO(_list_insert_rnd) (SPECLIST_LIST *tthis,
SPECLIST_TYPE *pfoo)
+{
+ genlist_insert(&tthis->list, pfoo, GENLIST_RANDOM_POS);
+}
+
static inline void SPECLIST_FOO(_list_unlink_all) (SPECLIST_LIST *tthis)
{
genlist_unlink_all(&tthis->list);
- [Freeciv-Dev] Re: (PR#9763) Not fair: get_defender() fallbacs to tile arrival time when selecting between equal units.,
Marko Lindqvist <=
- [Freeciv-Dev] Re: (PR#9763) Not fair: get_defender() fallbacs to tile arrival time when selecting between equal units., Gregory Berkolaiko, 2004/08/22
- [Freeciv-Dev] Re: (PR#9763) Not fair: get_defender() fallbacs to tile arrival time when selecting between equal units., Jason Short, 2004/08/22
- [Freeciv-Dev] Re: (PR#9763) Not fair: get_defender() fallbacs to tile arrival time when selecting between equal units., Mike Kaufman, 2004/08/22
- [Freeciv-Dev] Re: (PR#9763) Not fair: get_defender() fallbacs to tile arrival time when selecting between equal units., Gregory Berkolaiko, 2004/08/22
- [Freeciv-Dev] Re: (PR#9763) Not fair: get_defender() fallbacs to tile arrival time when selecting between equal units., Jason Short, 2004/08/22
- [Freeciv-Dev] (PR#9763) Not fair: get_defender() fallbacs to tile arrival time when selecting between equal units., Jason Short, 2004/08/23
- [Freeciv-Dev] Re: (PR#9763) Not fair: get_defender() fallbacs to tile arrival time when selecting between equal units., Marko Lindqvist, 2004/08/23
- [Freeciv-Dev] Re: (PR#9763) Not fair: get_defender() fallbacs to tile arrival time when selecting between equal units., Marko Lindqvist, 2004/08/23
- [Freeciv-Dev] Re: (PR#9763) Not fair: get_defender() fallbacs to tile arrival time when selecting between equal units., Jason Short, 2004/08/23
- [Freeciv-Dev] Re: (PR#9763) Not fair: get_defender() fallbacs to tile arrival time when selecting between equal units., Jason Short, 2004/08/23
|
|