Example #1
0
/**
* This function is invoked by the application level software to inject new events into the simulation
*
* @author Francesco Quaglia
*
* @param gid_receiver Global id of logical process at which the message must be delivered
* @param timestamp Logical Virtual Time associated with the event enveloped into the message
* @param event_type Type of the event
* @param event_content Payload of the event
* @param event_size Size of event's payload
*/
void ParallelScheduleNewEvent(unsigned int gid_receiver, simtime_t timestamp, unsigned int event_type, void *event_content, unsigned int event_size) {
	msg_t event;

	// In Silent execution, we do not send again already sent messages
	if(LPS[current_lp]->state == LP_STATE_SILENT_EXEC) {
		return;
	}

	// Check whether the destination LP is out of range
	if(gid_receiver > n_prc_tot - 1) {	// It's unsigned, so no need to check whether it's < 0
		rootsim_error(false, "Warning: the destination LP %d is out of range. The event has been ignored\n", gid_receiver);
		return;
	}

	// Check if the associated timestamp is negative
	if(timestamp < lvt(current_lp)) {
		rootsim_error(true, "LP %d is trying to generate an event (type %d) to %d in the past! (Current LVT = %f, generated event's timestamp = %f) Aborting...\n", current_lp, event_type, gid_receiver, lvt(current_lp), timestamp);
	}

        // Check if the event type is mapped to an internal control message
        if(event_type >= MIN_VALUE_CONTROL) {
                rootsim_error(true, "LP %d is generating an event with type %d which is a reserved type. Switch event type to a value less than %d. Aborting...\n", current_lp, event_type, MIN_VALUE_CONTROL);
        }


	// Copy all the information into the event structure
	bzero(&event, sizeof(msg_t));
	event.sender = LidToGid(current_lp);
	event.receiver = gid_receiver;
	event.type = event_type;
	event.timestamp = timestamp;
	event.send_time = lvt(current_lp);
	event.message_kind = positive;
	event.mark = generate_mark(current_lp);
	event.size = event_size;

	if(event.type == RENDEZVOUS_START) {
		event.rendezvous_mark = current_evt->rendezvous_mark;
	}

	if(event_size > MAX_EVENT_SIZE) {
		rootsim_error(true, "Event size (%d) exceeds MAX_EVENT_SIZE\n", event_size);
	}

	if (event_content != NULL) {
		memcpy(&event.event_content, event_content, event_size);
	}

	insert_outgoing_msg(&event);
}
Example #2
0
/**
 * Funtion for placing appropriate monsters in a room of chambers
 *
 * \param c the current chunk being generated
 * \param y1 the limits of the vault
 * \param x1 the limits of the vault
 * \param y2 the limits of the vault
 * \param x2 the limits of the vault
 * \param name the name of the monster type for use in mon_select()
 * \param area the total room area, used for scaling monster quantity
 */
void get_chamber_monsters(struct chunk *c, int y1, int x1, int y2, int x2, 
						  char *name, int area)
{
	int i, y, x;
	s16b monsters_left, depth;
	bool random = one_in_(20);

	/* Get a legal depth. */
	depth = c->depth + randint0(11) - 5;

	/* Choose a pit profile, using that depth. */
	if (!random)
		set_pit_type(depth, 0);

	/* Allow (slightly) tougher monsters. */
	depth = c->depth + (c->depth < 60 ? c->depth / 12 : 5);

	/* Set monster generation restrictions. Occasionally random. */
	if (random) {
		if (!mon_restrict("random", depth, true))
			return;
		my_strcpy(name, "random", sizeof(name));
	} else {
		if (!mon_restrict(dun->pit_type->name, depth, true))
			return;
		my_strcpy(name, dun->pit_type->name, sizeof(name));
	}

	/* Build the monster probability table. */
	if (!get_mon_num(depth)) {
		(void) mon_restrict(NULL, depth, false);
		name = NULL;
		return;
	}

	/* No normal monsters. */
	generate_mark(c, y1, x1, y2, x2, SQUARE_MON_RESTRICT);

	/* Allow about a monster every 20-30 grids. */
	monsters_left = area / (30 - c->depth / 10);

	/* Place the monsters. */
	for (i = 0; i < 300; i++) {
		/* Check for early completion. */
		if (!monsters_left)
			break;

		/* Pick a random in-room square. */
		y = y1 + randint0(1 + ABS(y2 - y1));
		x = x1 + randint0(1 + ABS(x2 - x1));

		/* Require a passable square with no monster in it already. */
		if (!square_isempty(c, y, x))
			continue;

		/* Place a single monster.  Sleeping 2/3rds of the time. */
		pick_and_place_monster(c, y, x, c->depth, (randint0(3) != 0), false,
											 ORIGIN_DROP_SPECIAL);

		/* One less monster to place. */
		monsters_left--;
	}

	/* Remove our restrictions. */
	(void) mon_restrict(NULL, depth, false);
}
Example #3
0
extern void get_chamber_monsters(int y1, int x1, int y2, int x2)
{
    bool dummy;
    int i, y, x;
    s16b monsters_left, depth;
    char symbol;

    /* Description of monsters in room */
    char *name;

    /* Get a legal depth. */
    depth = p_ptr->danger + randint0(11) - 5;
    if (depth > 60)
	depth = 60;
    if (depth < 5)
	depth = 5;

    /* Choose a monster type, using that depth. */
    symbol = mon_symbol_at_depth[depth / 5 - 1][randint0(13)];

    /* Allow (slightly) tougher monsters. */
    depth = p_ptr->danger + (p_ptr->danger < 60 ? p_ptr->danger / 12 : 5);

    /* Set monster generation restrictions.  Describe the monsters. */
    name = mon_restrict(symbol, (byte) depth, &dummy, TRUE);

    /* A default description probably means trouble, so stop. */
    if (streq(name, "misc") || !name[0])
	return;

    /* Build the monster probability table. */
    if (!get_mon_num(depth))
	return;

    /* No normal monsters. */
    generate_mark(y1, x1, y2, x2, CAVE_TEMP);


    /* Usually, we want 35 monsters. */
    monsters_left = 35;

    /* Fewer monsters near the surface. */
    if (p_ptr->danger < 45)
	monsters_left = 5 + 2 * p_ptr->danger / 3;

    /* More monsters of kinds that tend to be weak. */
    if (strstr("abciBCFKRS", d_char_req))
	monsters_left += 15;

    /* Place the monsters. */
    for (i = 0; i < 300; i++) {
	/* Check for early completion. */
	if (!monsters_left)
	    break;

	/* Pick a random in-room square. */
	y = y1 + randint0(1 + ABS(y2 - y1));
	x = x1 + randint0(1 + ABS(x2 - x1));

	/* Require a floor square with no monster in it already. */
	if (!cave_naked_bold(y, x))
	    continue;

	/* Place a single monster.  Sleeping 2/3rds of the time. */
	place_monster_aux(y, x, get_mon_num_quick(depth), (randint0(3) != 0),
			  FALSE);

	/* One less monster to place. */
	monsters_left--;
    }

    /* Remove our restrictions. */
    (void) mon_restrict('\0', (byte) depth, &dummy, FALSE);

    /* Describe */
    if (OPT(cheat_room)) {
	/* Room type */
	msg("Room of chambers (%s)", name);
    }
}