Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2002:
[Freeciv-Dev] Re: dynamic timeout (PR#1356)
Home

[Freeciv-Dev] Re: dynamic timeout (PR#1356)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Mike Kaufman <kaufman@xxxxxxxxxxxxxxxxxxxxxx>
Cc: freeciv-dev@xxxxxxxxxxx, bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: dynamic timeout (PR#1356)
From: Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 3 Apr 2002 20:39:25 +0200
Reply-to: rf13@xxxxxxxxxxxxxxxxxxxxxx

On Sat, Mar 30, 2002 at 09:25:43PM -0800, Mike Kaufman wrote:
> With help from Per, here is the next go around of the magically
> increasing timer. How it works:
> 
> set timeout <timeout>
> 
> people should hopefully be familiar with that part. The new part:
> 
> timeoutincrease <turn> <turninc> <value> <valuemult>

> Description:
>   Every <turn> turns, add <value> to timeout timer, 
>   then add <turninc> to <turn> and multiply <value> 
>   by <valuemult>.

Can you also post a formula?

> sound complicated? yes it is, but with about a minute of thought you'll
> see how powerful and flexible it is.
> 
> I'm not terribly good at parsing text, so please try it out and try to
> break it.

> +/**************************************************************************
> +  Set timeout options.
> +**************************************************************************/
> +static void timeout_command(struct connection *caller, char *str) 
> +{
> +  char buf[MAX_LEN_CONSOLE_LINE];
> +  char *bptr = buf, *arg[4] = {NULL, NULL, NULL, NULL};
> +  int i = 0, noargs = 0, val[4];
> +  int *timeouts[4];
> +
> +  timeouts[0] = &game.timeoutint;
> +  timeouts[1] = &game.timeoutintinc;
> +  timeouts[2] = &game.timeoutinc;
> +  timeouts[3] = &game.timeoutincmult;
> +
> +  assert(str != NULL);
> +
> +  sz_strlcpy(buf, str);
> +  remove_trailing_spaces(buf);

> +  while(*bptr != '\0' && i < 4) {
> +    /* skip intervening whitespace */
> +    while(*bptr == ' ' || *bptr == '\t') {
> +      bptr++;
> +    }
> +
> +    arg[i++] = bptr;
> +
> +    /* skip arg */
> +    while(*bptr != ' ' && *bptr != '\t' && *bptr != '\0') {
> +      bptr++;
> +    }
> +
> +    if (*bptr == '\0') {
> +      break;
> +    } else {
> +      *(bptr++) = '\0';
> +    }
> +  }

This could be replaced with strtok. This may also a good time to
introduce a split method.

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "Any sufficiently advanced technology is indistinguishable from magic."
    -- Arthur C. Clarke


[Prev in Thread] Current Thread [Next in Thread]