Ejemplo n.º 1
0
static bool
apply_condition (struct cldr_plural_condition_ty *condition, int value)
{
  if (condition->type == CLDR_PLURAL_CONDITION_AND)
    return apply_condition (condition->value.conditions[0], value)
      && apply_condition (condition->value.conditions[1], value);
  else if (condition->type == CLDR_PLURAL_CONDITION_OR)
    return apply_condition (condition->value.conditions[0], value)
      || apply_condition (condition->value.conditions[1], value);
  else if (condition->type == CLDR_PLURAL_CONDITION_RELATION)
    {
      struct cldr_plural_relation_ty *relation
        = condition->value.relation;
      int number = value;
      size_t i;

      if (relation->expression->mod > 0)
        number %= relation->expression->mod;
      for (i = 0; i < relation->ranges->nitems; i++)
        {
          struct cldr_plural_range_ty *range = relation->ranges->items[i];
          if (range->start->value.ival <= number
              && number <= range->end->value.ival)
            return relation->type == CLDR_PLURAL_RELATION_EQUAL;
        }
      return relation->type != CLDR_PLURAL_RELATION_EQUAL;
    }
  return false;
}
Ejemplo n.º 2
0
Archivo: alist.c Proyecto: job/irrd
/*
 * return 1 if permit, 0 otherwise
 */
int apply_access_list (int num, prefix_t *prefix) {

    condition_t *condition;

    if (num < 0 || num >= MAX_ALIST)
        return (0);
    if (num == 0)
        return (1); /* cisco feature */
    if (access_list[num] == NULL) {
        /* I'm not sure how cisco works for undefined access lists */
        return (0); /* assuming deny for now */
    }

    LL_Iterate (access_list[num], condition) {
        int value;

        if ((value = apply_condition (condition, prefix)) >= 0)
            return (value);
    }
Ejemplo n.º 3
0
void
cldr_plural_rule_list_print (struct cldr_plural_rule_list_ty *rules, FILE *fp)
{
  size_t i;
  size_t count;
  size_t nplurals;
  int modulus_max = 0;

  /* Prune trivial conditions.  */
  for (i = 0; i < rules->nitems; i++)
    {
      struct cldr_plural_rule_ty *rule = rules->items[i];
      eval_condition (rule->condition);
    }

  /* Omit trivial rules (e.g., the last rule for "ru") with the
     following algorithm:
     1. From all rules, find the largest modulus M
     2. Prepare a bit vector with M elements and initialize it with zeros
     3. Loop over the rules, until all bits are set:
        For each value in the range [1, M], apply a rule, and flip the
        corresponding bit if it evaluates true  */

  /* Find the largest modulus.  */
  for (i = 0; i < rules->nitems; i++)
    {
      struct cldr_plural_rule_ty *rule = rules->items[i];
      int modulus = find_largest_modulus (rule->condition);
      int number = find_largest_number (rule->condition);
      /* If the rule contains a range whose end is larger than
         MODULUS, we can't use MODULUS as the upper bound.  Skip
         it.  */
      if (modulus >= number && modulus > modulus_max)
        modulus_max = modulus;
    }

  if (modulus_max > 0)
    {
      bool *values = XNMALLOC (modulus_max, bool);

      memset (values, 0, sizeof (bool) * modulus_max);
      for (i = 0; i < rules->nitems; i++)
        {
          struct cldr_plural_rule_ty *rule = rules->items[i];
          int j;

          for (j = 0; j < modulus_max; j++)
            {
              bool result = apply_condition (rule->condition, j + 1);
              if (result)
                values[j] = true;
            }

          /* Check if all bits are set.  Then we can omit one more rule.  */
          for (j = 0; j < modulus_max; j++)
            if (values[j] == false)
              break;
          if (j == modulus_max)
            break;
        }

      free (values);

      while (i < rules->nitems)
        cldr_plural_rule_free (rules->items[--rules->nitems]);
    }
Ejemplo n.º 4
0
void heart_beat()
{
        int t;
        int period;
        int wimpy_ratio, cnd_flag;
        mapping my;
        object ob;
	object me;
	string prompt;
	int is_player;

	me = this_object();
        my = query_entire_dbase();

        if (userp(me) && living(me) && mapp(my["env"]))
        {
                // update prompt
		prompt = my["env"]["prompt"];
                if ((prompt == "time" || prompt == "mud" || prompt == "hp") &&
		    is_waiting_command() && ! me->is_attach_system())
                    
                {
                        write_prompt();
                }
                
        }

        // If we're dying or falling unconcious?
        if (my["qi"] < 0 || my["jing"] < 0)
        {
                if (! living(me)) die();
                else unconcious();

                // Why does the living test? Because
                // The wizard may set immortal but his
                // qi was -1, so I don't want return,
                // or the continue_action will never be
                // called in such case.
                if (! me || ! living(me))
                        return;
        }

        if (is_p_busy())
        {
                continue_p_busy();
        }
        
        // Do attack if we are fighting.
        if (is_busy())
        {
                continue_action();
                // We don't want heart beat be halt eventually, so return here.
        } else
	if (living(me))
        {
                string apply;
                object apply_ob;

                // Is it time to flee?
                if (is_fighting() &&
                   intp(wimpy_ratio = (int)query("env/wimpy")) &&
                   wimpy_ratio > 0 &&
                   (my["qi"] * 100 / my["max_qi"] <= wimpy_ratio ||
                    my["jing"] * 100 / my["max_jing"] <= wimpy_ratio))
                {
                        if (stringp(apply = query("env/wimpy_apply")) &&
                            objectp(apply_ob = present(apply, me)) &&
                            apply_ob->query("can_apply_for_wimpy"))
                        {
                                apply_ob->apply_for_wimpy(this_object());
                        } else
                                GO_CMD->do_flee(this_object());
                }
                
                if (query("auto_perform") || me->query_auto_perform())
                {                       
                        if (my["eff_jing"] > 0 && my["jing"] * 100 / my["eff_jing"] <= 70)
                                SKILL_D("force/regenerate")->exert(me, me);
                        if (my["eff_qi"] > 0 && my["qi"] * 100 / my["eff_qi"] <= 70)
                                SKILL_D("force/recover")->exert(me, me);

                        // 如果不在打架而且处于受伤状态,则自行疗伤
                        if (! is_fighting())
                        {
                                if (my["eff_jing"] < my["max_jing"])
                                        SKILL_D("force/inspire")->exert(me, me);
                                if (my["eff_qi"] < my["max_qi"])
                                        SKILL_D("force/heal")->exert(me, me);
                        }
                }
                // Do attack or clean up enemy if we have fleed.
                if (is_busy())
                        continue_action();
                else
                        attack();
        }

        if (my["doing"] == "scheme")
                // executing schedule now
                SCHEME_CMD->execute_schedule(me);

        if (! me) return;

        if (! (is_player = playerp(me)))
        {
                me->scan();
                // scan() may do anything -- include destruct(this_object())
                if (! me) return;
        }

        if ((t = time()) < next_beat) return;
        else next_beat = t + 5 + random(10);

	if (! my["not_living"])
        	cnd_flag = update_condition();
	if (! me) return;

	if (! (cnd_flag & CND_NO_HEAL_UP))
		cnd_flag = heal_up();

        // If we are compeletely in peace, turn off heart beat.
        // heal_up() must be called prior to other two to make sure it is called
        // because the && operator is lazy :P
        if (! cnd_flag &&
	    ! is_player &&
            ! keep_beat_flag &&
            ! is_fighting() &&
	    ! is_busy() &&
            ! interactive(this_object()))
        {
                if (environment() && query("chat_msg"))
                {
                        ob = first_inventory(environment());
                        while (ob && ! interactive(ob))
                                ob = next_inventory(ob);
                } else
                        ob = 0;
                if (! ob) set_heart_beat(0);
        }

        update_all_limb_damage();
        
        if (! me || ! is_player) return;

        // Make us a bit older. Only player's update_age is defined.
        // Note: update_age() is no need to be called every heart_beat, it
        //       remember how much time has passed since last call.
        me->update_age();

#ifdef AUTO_SAVE
        if (living(me))
        {
            	period = t - ((int) my["last_save"]);
                if (period < 0 || period > 15 * 60)
            	{
                	string msg;
                        msg = HBCYN HIW "【档案存储】您的档案已经自动存盘,"
                              "欢迎访问论坛 http://bbs.mudbuilder.com/ 。\n" NOR;
                	if (! me->save())
                    	msg = HIR "【数据保护】由于数据异常,您的档"
                              "案本次存盘失败。\n" NOR;
                	set("last_save", t);
                	tell_object(me, msg);
            }
        }
#endif
	if (! interactive(me))
		return;

        if (my["food"] <= 0 || my["water"] <= 0)
        {
		if (environment() &&
		    ! environment()->is_chat_room() &&
                    ! wizardp(me) &&
                    ! query_condition("hunger"))
		{
			// born & enter the world
                        apply_condition("hunger", 1);
		}
        }

        if (query_idle(me) > IDLE_TIMEOUT && ! wizardp(me) &&
            (! mapp(my["env"]) || ! my["env"]["keep_idle"]))
                me->user_dump(DUMP_IDLE);
}