gen: New emp_quelen(), replacing open-coded counting loops
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
parent
9b33a4c598
commit
4f83ce27b4
4 changed files with 18 additions and 24 deletions
|
@ -27,7 +27,7 @@
|
||||||
* queue.h: Generic vax-like doubly linked list queues
|
* queue.h: Generic vax-like doubly linked list queues
|
||||||
*
|
*
|
||||||
* Known contributors to this file:
|
* Known contributors to this file:
|
||||||
*
|
* Markus Armbruster, 2014
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef QUEUE_H
|
#ifndef QUEUE_H
|
||||||
|
@ -42,6 +42,7 @@ struct emp_qelem {
|
||||||
|
|
||||||
extern void emp_remque(struct emp_qelem *);
|
extern void emp_remque(struct emp_qelem *);
|
||||||
extern void emp_initque(struct emp_qelem *);
|
extern void emp_initque(struct emp_qelem *);
|
||||||
|
extern int emp_quelen(struct emp_qelem *);
|
||||||
extern struct emp_qelem *emp_searchque(struct emp_qelem *, void *,
|
extern struct emp_qelem *emp_searchque(struct emp_qelem *, void *,
|
||||||
int (*)(struct emp_qelem *, void *));
|
int (*)(struct emp_qelem *, void *));
|
||||||
extern void emp_insque(struct emp_qelem *, struct emp_qelem *);
|
extern void emp_insque(struct emp_qelem *, struct emp_qelem *);
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
* queue.c: Various queue routines (for lists)
|
* queue.c: Various queue routines (for lists)
|
||||||
*
|
*
|
||||||
* Known contributors to this file:
|
* Known contributors to this file:
|
||||||
*
|
* Markus Armbruster, 2014
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
@ -58,6 +58,17 @@ emp_remque(struct emp_qelem *elem)
|
||||||
elem->q_back->q_forw = elem->q_forw;
|
elem->q_back->q_forw = elem->q_forw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
emp_quelen(struct emp_qelem *queue)
|
||||||
|
{
|
||||||
|
struct emp_qelem *qp;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
for (qp = queue->q_forw, len = 0; qp != queue; qp = qp->q_forw, len++)
|
||||||
|
;
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
struct emp_qelem *
|
struct emp_qelem *
|
||||||
emp_searchque(struct emp_qelem *queue, void *key,
|
emp_searchque(struct emp_qelem *queue, void *key,
|
||||||
int (*test)(struct emp_qelem *, void *))
|
int (*test)(struct emp_qelem *, void *))
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
* Dave Pare, 1986
|
* Dave Pare, 1986
|
||||||
* Thomas Ruschak, 1992
|
* Thomas Ruschak, 1992
|
||||||
* Steve McClure, 1996
|
* Steve McClure, 1996
|
||||||
* Markus Armbruster, 2006-2012
|
* Markus Armbruster, 2006-2014
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
@ -314,11 +314,7 @@ ac_intercept(struct emp_qelem *bomb_list, struct emp_qelem *esc_list,
|
||||||
sam_intercept(esc_list, def_list, def_own, plane_owner, x, y,
|
sam_intercept(esc_list, def_list, def_own, plane_owner, x, y,
|
||||||
only_mission);
|
only_mission);
|
||||||
|
|
||||||
att_count = 0;
|
att_count = emp_quelen(bomb_list) + emp_quelen(esc_list);
|
||||||
for (qp = bomb_list->q_forw; qp != bomb_list; qp = qp->q_forw)
|
|
||||||
att_count++;
|
|
||||||
for (qp = esc_list->q_forw; qp != esc_list; qp = qp->q_forw)
|
|
||||||
att_count++;
|
|
||||||
if (!att_count)
|
if (!att_count)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -719,20 +719,6 @@ lnd_check_mar(struct lndstr *lp, struct sctstr *sectp)
|
||||||
return LND_STUCK_NOT;
|
return LND_STUCK_NOT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
lnd_count(struct emp_qelem *list)
|
|
||||||
{
|
|
||||||
struct emp_qelem *qp;
|
|
||||||
struct emp_qelem *next;
|
|
||||||
int count = 0;
|
|
||||||
|
|
||||||
for (qp = list->q_back; qp != list; qp = next) {
|
|
||||||
next = qp->q_back;
|
|
||||||
++count;
|
|
||||||
}
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
lnd_damage(struct emp_qelem *list, int totdam)
|
lnd_damage(struct emp_qelem *list, int totdam)
|
||||||
{
|
{
|
||||||
|
@ -742,7 +728,7 @@ lnd_damage(struct emp_qelem *list, int totdam)
|
||||||
int dam;
|
int dam;
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
if (!totdam || !(count = lnd_count(list)))
|
if (!totdam || !(count = emp_quelen(list)))
|
||||||
return 0;
|
return 0;
|
||||||
dam = ldround((double)totdam / count, 1);
|
dam = ldround((double)totdam / count, 1);
|
||||||
for (qp = list->q_back; qp != list; qp = next) {
|
for (qp = list->q_back; qp != list; qp = next) {
|
||||||
|
@ -785,7 +771,7 @@ static int
|
||||||
lnd_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
|
lnd_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
|
||||||
natid victim)
|
natid victim)
|
||||||
{
|
{
|
||||||
int mindam = lnd_count(list) * 20;
|
int mindam = emp_quelen(list) * 20;
|
||||||
int hardtarget = lnd_easiest_target(list);
|
int hardtarget = lnd_easiest_target(list);
|
||||||
int dam, newdam, sublaunch;
|
int dam, newdam, sublaunch;
|
||||||
int stopping = 0;
|
int stopping = 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue