Пример #1
0
void heart_beat()
{
	int wimpy_ratio, cnd_flag;
	mapping my;
	object ob;

	my = query_entire_dbase();

	// If we are dying because of mortal wounds?
	if( my["eff_kee"] < 0 || my["eff_sen"] < 0 || my["eff_gin"] < 0) {
		QUEST->quest_kill(this_object());
		remove_all_enemy();
		die();
		return;
	}

	// If we're dying or falling unconcious?
	if( my["kee"] < 0 || my["sen"] < 0 || my["gin"] < 0) {
		QUEST->quest_kill(this_object());
		remove_all_enemy();
		if( !living(this_object()) ) die();
		else unconcious();
		return;
	}

	// Do attack if we are fighting.
	if( is_busy() ) {
		continue_action();
		// We don't want heart beat be halt eventually, so return here.
		return;
	}
 	// added by snowcat, pickle's implementation 
	if ( query_temp("no_move") ) {
		continue_action();
		return;
	} else {
		// Is it time to flee?
		if( is_fighting()
		&&	intp(wimpy_ratio = (int)query("env/wimpy"))
		&&	wimpy_ratio > 0
		&&	(	my["kee"] * 100 / my["max_kee"] <= wimpy_ratio
			||	my["sen"] * 100 / my["max_sen"] <= wimpy_ratio) )
			// ||	my["gin"] * 100 / my["max_gin"] <= wimpy_ratio) )
			GO_CMD->do_flee(this_object());
		// Do attack or clean up enemy if we have fleed.
		attack();
	}

	// mon add check living. 8/3/98
	if( !userp(this_object()) && living(this_object()) ) {
		this_object()->chat();
		// chat() may do anything -- include destruct(this_object())
		if( !this_object() ) return;	
	}

	if( tick--  ) return;
	else tick = 5 + random(10);

	cnd_flag = update_condition();

	// 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 & CND_NO_HEAL_UP) || !heal_up())
	&&	!is_fighting() 
	&&	!interactive(this_object())) {
		if( environment() ) {
			ob = first_inventory(environment());
			while(ob && !interactive(ob))
				ob = next_inventory(ob);
		}
		if( !ob ) set_heart_beat(0);
	}

	if( !interactive(this_object()) ) 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.
	this_object()->update_age();

	if(query_idle(this_object()) > IDLE_TIMEOUT)
		this_object()->user_dump(DUMP_IDLE);
}
Пример #2
0
Файл: int2.c Проект: crinq/cmot
int main(){
	FILE *file;
	//file = fopen("intp.txt","w+");

	struct max_joint_steps max_j_s; // min axis res
	max_j_s.step[0] = 1 / 180 * 3.141526; // 0.1 deg res -> rad
	max_j_s.step[1] = 1 / 180 * 3.141526; // 0.1 mm res
	max_j_s.step[2] = 1 / 180 * 3.141526; // 0.1 mm res

	struct min_axis_steps min_a_s; // min joint res
	min_a_s.step[0] = 1; // 0.1 mm res
	min_a_s.step[1] = 1; // 0.1 mm res
	min_a_s.step[2] = 1; // 0.1 mm res

	struct vec A;
	A.axis_pos[0] = 100;
	A.axis_pos[1] = 0;
	A.axis_pos[2] = 0;

	struct vec B;
	B.axis_pos[0] = 1;
	B.axis_pos[1] = 0;
	B.axis_pos[2] = 0;


	struct path* AB = (struct path *)malloc(sizeof(struct path));
	struct path* AB_head;
	struct path* head = AB;
	AB->next = 0;
	AB->prev = 0;
	AB->pos = A;
	insert(AB, B);


	//insert(AB, A);

	int i = 0;
	AB_head = AB;
	while(AB){
		i++;
		AB = AB->next;
	}

	AB = AB_head;

	double * joint_pos_0 = (double *) malloc(sizeof(double) * i);
	double * joint_pos_1 = (double *) malloc(sizeof(double) * i);
	double * joint_pos_2 = (double *) malloc(sizeof(double) * i);

	i = 0;
	while(AB){
		joint_pos_0[i] = AB->pos.axis_pos[0];
		joint_pos_1[i] = AB->pos.axis_pos[1];
		joint_pos_2[i] = AB->pos.axis_pos[2];

		i++;
		AB = AB->next;
	}

	intp(AB, max_j_s, min_a_s);
	//no_jump(AB);
	/*while(AB){
		//printf("Axis Pos (%f/%f)", AB->pos.axis_pos[0], AB->pos.axis_pos[1]);
		//printf(" -> ");
		//printf("joint Pos (%f/%f)", AB->pos.joint_pos[0], AB->pos.joint_pos[1]);
		//printf("\n");

		//fprintf(file, "%f %f %f %f\n", AB->pos.axis_pos[0], AB->pos.axis_pos[1], AB->pos.joint_pos[0], AB->pos.joint_pos[1]);
		// plot with: gnuplot -e 'set multiplot layout 6,1; plot "intp.txt" using 0:1 title "axis[0]";plot "intp.txt" using 0:2 title "axis[1]";plot "intp.txt" using 0:3 title "joint[0]";plot "intp.txt" using 0:4 title "joint[1]";plot "intp.txt" using 1:2 title "axis"; plot "intp.txt" using 3:4 title "joints"' -p
		fprintf(file, "%f %f %f %f %f %f\n", AB->pos.axis_pos[0], AB->pos.axis_pos[1], AB->pos.axis_pos[2], AB->pos.joint_pos[0], AB->pos.joint_pos[1], AB->pos.joint_pos[2]);
		AB = AB->next;
	}*/

	//fclose(file);
	return(0);
}
Пример #3
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);
}
Пример #4
0
/* cmd_look (string)
  this function 'look's in a room and handles the case of
whether it's just the room or a separate object */
int cmd_look (string str) {
  int oldStatus;   
  string tmp, tmp2;
  mapping exits, doors;
  mixed *hidden_exits, *hidden_doors;
   
  it = 0;
  viewingOb = this_player();
  env = environment (viewingOb);
   
/* standard TMI-2 look blocks for 2 seconds, but I don't like that,
   so we've got another option available on compile-time */
#ifndef BLOCK_ATTACK
  Attacking = ((viewingOb->query_attackers()) ? 1 : 0);
#endif

/* Check to see if we have an argument list.  If we do, see if
we're trying to look at a particular object.  If so, get the
object's description.  Otherwise, ask the room for its description.
*/
  
// are we looking at our immediate environment?
  if (!str || !stringp (str)) {
    // do we have an environment?  If not, write the default message
    if (!env) {
      write ("There is nothing to see here.\n");
#ifdef BLOCK_ATTACK
      viewingOb->block_attack (2);
#endif
      return 1;
    }
/*
write (LANGUAGE_D->garble_string(look_in_room (env, (int)viewingOb->query_temp ("force_to_look")),"orcish")+"\n") ;
*/
    write (look_in_room (env, (int)viewingOb->query_temp ("force_to_look")));
#ifdef BLOCK_ATTACK
    viewingOb->block_attack (2);
#endif
    return 1;
  }

// are we looking at something in a container?
  if (sscanf(str, "at %s in %s", tmp, tmp2) == 2) {
    // we're looking inside a container
    // blocking a look in a locked/opaque container doesn't work yet. -- Fantome
    // hopefully will work soon
#ifndef BLOCK_ATTACK
    if (Attacking) {
      write ("You are too busy to get a detailed look at that!\n");
      return 1;
    }
#endif
    write (sprintf ("%-=75s", look_at_item (tmp, viewingOb, tmp2)));
    return 1;
  }

// are we looking at an object?
  if (sscanf(str, "at %s", tmp)) {
    write (sprintf ("%-=75s", look_at_item (tmp, viewingOb)));
    return 1;
  }
// are we looking in an object?
  if (sscanf(str, "in %s", tmp)) {
#ifndef BLOCK_ATTACK
    if (Attacking) {
      write ("You are too busy to get a detailed look at that!\n");
      return 1;
    }
#endif
    write (sprintf ("%-=75s", look_in_item (tmp, viewingOb)));
    return 1;
  }
// are we looking in the room?
  if (env) {
    exits = env->query ("exits");
    doors = env->query ("doors");
    hidden_exits = env->query ("exit_suppress");
    hidden_doors = env->query ("door_suppress");
    if (mapp (exits) && member_array (str, keys (exits)) != -1) {
      if (doors && doors[str]) {
	if (((!intp (hidden_doors) || (int)hidden_doors[0] != 1) ||
	    (!pointerp (hidden_doors) ||
		member_array (str, hidden_doors) == -1))
	    && doors[str]["status"] != "open") {
	  write ("The door is closed.\n");
#ifdef BLOCK_ATTACK
	  viewingOb->block_attack(2);
#endif
	  return 1;
	}
      }
      if ((!pointerp (hidden_exits) ||
		member_array (str, hidden_exits) == -1) ||
		(!intp (hidden_exits) || (int)hidden_exits[0] != 1)) {
	env = find_object_or_load (exits[str]);
	write (look_in_room (env, 0));
#ifdef BLOCK_ATTACK
	viewingOb->block_attack(2);
#endif
	return 1;
      }
    }
  }
   
  cmd_look (sprintf ("at %s", str));
  return 1;
}