forked from github/server
making ct_find faster, since it's the slowest function in the game.
This commit is contained in:
parent
32659cddb6
commit
0dce9060e9
|
@ -35,8 +35,9 @@
|
|||
#include "objtypes.h"
|
||||
|
||||
/* util includes */
|
||||
#include <resolve.h>
|
||||
#include <base36.h>
|
||||
#include <util/resolve.h>
|
||||
#include <util/base36.h>
|
||||
#include <util/goodies.h>
|
||||
|
||||
/* libc includes */
|
||||
#include <stdio.h>
|
||||
|
@ -224,12 +225,14 @@ typedef struct cursetype_list {
|
|||
const curse_type * type;
|
||||
} cursetype_list;
|
||||
|
||||
cursetype_list * cursetypes;
|
||||
#define CMAXHASH 63
|
||||
cursetype_list * cursetypes[CMAXHASH];
|
||||
|
||||
void
|
||||
ct_register(const curse_type * ct)
|
||||
{
|
||||
cursetype_list ** ctlp = &cursetypes;
|
||||
unsigned int hash = hashstring(ct->cname);
|
||||
cursetype_list ** ctlp = &cursetypes[hash];
|
||||
while (*ctlp) {
|
||||
cursetype_list * ctl = *ctlp;
|
||||
if (ctl->type==ct) return;
|
||||
|
@ -242,7 +245,8 @@ ct_register(const curse_type * ct)
|
|||
const curse_type *
|
||||
ct_find(const char *c)
|
||||
{
|
||||
cursetype_list * ctl = cursetypes;
|
||||
unsigned int hash = hashstring(c);
|
||||
cursetype_list * ctl = cursetypes[hash];
|
||||
while (ctl) {
|
||||
int k = min(strlen(c), strlen(ctl->type->cname));
|
||||
if (!strncasecmp(c, ctl->type->cname, k)) return ctl->type;
|
||||
|
|
|
@ -161,6 +161,12 @@ do_shock(unit *u, const char *reason)
|
|||
/* Spruchanalyse - Ausgabe von curse->info und curse->name */
|
||||
/* ------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
curse_chance(const struct curse * c, int force)
|
||||
{
|
||||
return 100 + (int)((force - c->vigour)*10);
|
||||
}
|
||||
|
||||
void
|
||||
magicanalyse_region(region *r, unit *mage, int force)
|
||||
{
|
||||
|
@ -178,7 +184,7 @@ magicanalyse_region(region *r, unit *mage, int force)
|
|||
|
||||
/* ist der curse schwächer als der Analysezauber, so ergibt sich
|
||||
* mehr als 100% chance und damit immer ein Erfolg. */
|
||||
chance = (force - c->vigour)*10 + 100;
|
||||
chance = curse_chance(c, force);
|
||||
mon = c->duration + (rand()%10) - 5;
|
||||
mon = max(1,mon);
|
||||
found = true;
|
||||
|
@ -220,7 +226,7 @@ magicanalyse_unit(unit *u, unit *mage, int force)
|
|||
c = (curse*)a->data.v;
|
||||
/* ist der curse schwächer als der Analysezauber, so ergibt sich
|
||||
* mehr als 100% chance und damit immer ein Erfolg. */
|
||||
chance = (force - c->vigour)*10 + 100;
|
||||
chance = chance = curse_chance(c, force);
|
||||
mon = c->duration + (rand()%10) - 5;
|
||||
mon = max(1,mon);
|
||||
|
||||
|
@ -261,7 +267,7 @@ magicanalyse_building(building *b, unit *mage, int force)
|
|||
c = (curse*)a->data.v;
|
||||
/* ist der curse schwächer als der Analysezauber, so ergibt sich
|
||||
* mehr als 100% chance und damit immer ein Erfolg. */
|
||||
chance = (force - c->vigour)*10 + 100;
|
||||
chance = curse_chance(c, force);
|
||||
mon = c->duration + (rand()%10) - 5;
|
||||
mon = max(1,mon);
|
||||
|
||||
|
@ -303,7 +309,7 @@ magicanalyse_ship(ship *sh, unit *mage, int force)
|
|||
c = (curse*)a->data.v;
|
||||
/* ist der curse schwächer als der Analysezauber, so ergibt sich
|
||||
* mehr als 100% chance und damit immer ein Erfolg. */
|
||||
chance = (force - c->vigour)*10 + 100;
|
||||
chance = curse_chance(c, force);
|
||||
mon = c->duration + (rand()%10) - 5;
|
||||
mon = max(1,mon);
|
||||
|
||||
|
|
Loading…
Reference in New Issue