Exemple #1
0
t_room	*get_rooms_and_coords(char ***lines, t_room **rooms)
{
	if (lines && *lines && ***lines && ft_strchr((*lines)[0], '-'))
	{
		return (*rooms)++;
	}
	else if (!strcmp((*lines)[0], "##start"))
	{
		(*lines)++;
		*rooms = new_room((*lines)[0]);
		(*rooms)->is_start = 1;
		(*rooms)->is_end = 0;
	}
	else if (!strcmp((*lines)[0], "##end"))
	{
		(*lines)++;
		*rooms = new_room((*lines)[0]);
		(*rooms)->is_start = 0;
		(*rooms)->is_end = 1;
	}
	else if (***lines == '#')
	{
		(*lines)++;
		*rooms = new_room((*lines)[0]);
		(*rooms)->is_start = 0;
		(*rooms)->is_end = 0;
	}
	else if (lines && *lines && **lines && ***lines != EOF)
	{
		*rooms = new_room((*lines)[0]);
		(*rooms)->is_start = 0;
		(*rooms)->is_end = 0;
	}
	return (*rooms);
}
Exemple #2
0
static void		fill_rooms(t_arr *rooms, char *line, enum e_read status)
{
	char		*name;
	t_uint		x;
	t_uint		y;

	if (!ft_strchr(line, ' '))
	{
		link_rooms(rooms, line);
		return ;
	}
	name = line;
	while (*line && *line != ' ')
		line++;
	if (!*line)
		error(E_INVALID, "Weird room.");
	*line++ = 0;
	x = (t_uint)ft_atoi(line);
	while (*line && *line != ' ')
		line++;
	if (!*line)
		error(E_INVALID, "Weird room.");
	y = (t_uint)ft_atoi(++line);
	ft_arrpush(rooms, new_room(name, x, y, status), status == R_START ? 0 : -1);
}
Exemple #3
0
t_room	*list_add_room(char *name, int x, int y)
{
	t_data	*d;
	t_room	*tmp;
	t_room	*room;

	d = data_init();
	tmp = *(d->list_room);
	while (tmp)
	{
		if (!ft_strcmp(tmp->name, name) || (tmp->x == x && tmp->y == y))
			return (NULL);
		tmp = tmp->next;
	}
	if ((room = new_room(name, x, y)) == NULL)
		return (NULL);
	tmp = *(d->list_room);
	while (tmp && tmp->next)
		tmp = tmp->next;
	if (!tmp)
		*(d->list_room) = room;
	else
		tmp->next = room;
	return (room);
}
Exemple #4
0
void NewRoom(int nrnum) {
    if (nrnum < 0)
        quitprintf("!NewRoom: room change requested to invalid room number %d.", nrnum);

    if (displayed_room < 0) {
        // called from game_start; change the room where the game will start
        playerchar->room = nrnum;
        return;
    }


    DEBUG_CONSOLE("Room change requested to room %d", nrnum);
    EndSkippingUntilCharStops();

    can_run_delayed_command();

    if (play.stop_dialog_at_end != DIALOG_NONE) {
        if (play.stop_dialog_at_end == DIALOG_RUNNING)
            play.stop_dialog_at_end = DIALOG_NEWROOM + nrnum;
        else {
            quitprintf("!NewRoom: two NewRoom/RunDialog/StopDialog requests within dialog; last was called in \"%s\", line %d",
                last_in_dialog_request_script_pos.Section.GetCStr(), last_in_dialog_request_script_pos.Line);
        }
        return;
    }

    get_script_position(last_in_dialog_request_script_pos);

    if (in_leaves_screen >= 0) {
        // NewRoom called from the Player Leaves Screen event -- just
        // change which room it will go to
        in_leaves_screen = nrnum;
    }
    else if (in_enters_screen) {
        setevent(EV_NEWROOM,nrnum);
        return;
    }
    else if (in_inv_screen) {
        inv_screen_newroom = nrnum;
        return;
    }
    else if ((inside_script==0) & (in_graph_script==0)) {
        new_room(nrnum,playerchar);
        return;
    }
    else if (inside_script) {
        curscript->queue_action(ePSANewRoom, nrnum, "NewRoom");
        // we might be within a MoveCharacterBlocking -- the room
        // change should abort it
        if ((playerchar->walking > 0) && (playerchar->walking < TURNING_AROUND)) {
            // nasty hack - make sure it doesn't move the character
            // to a walkable area
            mls[playerchar->walking].direct = 1;
            StopMoving(game.playercharacter);
        }
    }
    else if (in_graph_script)
        gs_to_newroom = nrnum;
}
Exemple #5
0
t_map	*new_map(char *str, int cx, int cy)
{
	t_map *res;

	if (!(res = (t_map *)malloc(sizeof(t_map))))
		return (NULL);
	res->room = new_room(str, cx, cy);
	res->next = NULL;
	return (res);
}
Exemple #6
0
static D_ROOM *load_room( lua_State *L )
{
   D_ROOM *r;
   D_EXIT *e;
   int i=0, numExits=0;
   
   if( !L )
      return NULL;
      
   
   if( ( r = new_room() ) == NULL )
   {
      return NULL;
   }
   
   lua_pushstring( L, "vnum" );
   lua_gettable( L, -2 );
   r->vnum = (int)luaL_checknumber( L, -1 );
   lua_pop( L, 1 );
   
   lua_pushstring( L, "name" );
   lua_gettable( L, -2 );
   r->name = strdup( luaL_checkstring( L, -1 ) );
   lua_pop( L, 1 );
   
   lua_pushstring( L, "desc" );
   lua_gettable( L, -2 );
   r->desc = strdup( luaL_checkstring( L, -1 ) );
   lua_pop( L, 1 );
   
   lua_pushstring( L, "exits" );
   lua_gettable( L, -2 );
   //numExits = lua_len( L, -1 );
   lua_len( L, -1 );
   numExits = luaL_checknumber( L, -1 );
   lua_pop( L, 1 );
   for( i = 1; i <= numExits; i++ ) //iterate through the exits
   {
      lua_rawgeti( L, -1, i );
      if( ( e = load_exit( L ) ) == NULL )
      {
         bug( "Error: Unable to allocate memory for new exit." );
         continue;
      }
      AttachToList( e, r->exits ); //attach it to the room's exit list
      lua_pop( L, 1 );
   }
   lua_pop( L, 1 );

   load_room_resets( L, r );
   lua_pop( L, 1 );
   return r;
}
Exemple #7
0
int main(int argc, char* argv[])
{
	openlog(NULL, 0, LOG_USER);
	syslog(LOG_INFO, "Init...");
	
	uint8_t run = 1;
	char refresh_time = 2;
	time_t raw_time = time(NULL);
	 _time = localtime(&raw_time);
	uint8_t c_time = _time->tm_hour;
	uint8_t o_time = c_time - 1;

	struct Room* salon = new_room("salon");	
	syslog(LOG_INFO, "Done. Looping...");
	
	//Main loop
	while (run)
	{
		raw_time = time(NULL);
		_time = localtime(&raw_time);
		c_time = _time->tm_hour;
		syslog(LOG_INFO, "o_time: %d", o_time);
		syslog(LOG_INFO, "c_time: %d", c_time);
		if ( (o_time < c_time) || (c_time == 0 && o_time == 23) ) //Computes is a new hour elapsed
		{
			hour_update = 1;
		}
		update_room(salon);
		
		o_time = c_time;
		hour_update = 0; //Resets the hour update anyway
		
		sleep(refresh_time);
	}
	
	closelog();
	return EXIT_SUCCESS;
}
Exemple #8
0
void post_script_cleanup() {
    // should do any post-script stuff here, like go to new room
    if (ccError) quit(ccErrorString);
    ExecutingScript copyof = scripts[num_scripts-1];
    //  write_log("Instance finished.");
    if (scripts[num_scripts-1].forked)
        delete scripts[num_scripts-1].inst;
    num_scripts--;
    inside_script--;

    if (num_scripts > 0)
        curscript = &scripts[num_scripts-1];
    else {
        curscript = NULL;
    }
    //  if (abort_executor) user_disabled_data2=aborted_ip;

    int old_room_number = displayed_room;

    // run the queued post-script actions
    for (int ii = 0; ii < copyof.numPostScriptActions; ii++) {
        int thisData = copyof.postScriptActionData[ii];

        switch (copyof.postScriptActions[ii]) {
    case ePSANewRoom:
        // only change rooms when all scripts are done
        if (num_scripts == 0) {
            new_room(thisData, playerchar);
            // don't allow any pending room scripts from the old room
            // in run_another to be executed
            return;
        }
        else
            curscript->queue_action(ePSANewRoom, thisData, "NewRoom");
        break;
    case ePSAInvScreen:
        invscreen();
        break;
    case ePSARestoreGame:
        cancel_all_scripts();
        try_restore_save(thisData);
        return;
    case ePSARestoreGameDialog:
        restore_game_dialog();
        return;
    case ePSARunAGSGame:
        cancel_all_scripts();
        load_new_game = thisData;
        return;
    case ePSARunDialog:
        do_conversation(thisData);
        break;
    case ePSARestartGame:
        cancel_all_scripts();
        restart_game();
        return;
    case ePSASaveGame:
        save_game(thisData, copyof.postScriptSaveSlotDescription[ii]);
        break;
    case ePSASaveGameDialog:
        save_game_dialog();
        break;
    default:
        quitprintf("undefined post script action found: %d", copyof.postScriptActions[ii]);
        }
        // if the room changed in a conversation, for example, abort
        if (old_room_number != displayed_room) {
            return;
        }
    }


    int jj;
    for (jj = 0; jj < copyof.numanother; jj++) {
        old_room_number = displayed_room;
        QueuedScript &script = copyof.ScFnQueue[jj];
        RunScriptFunction(script.Instance, script.FnName, script.ParamCount, script.Param1, script.Param2);
        if (script.Instance == kScInstRoom && script.ParamCount == 1)
        {
            // some bogus hack for "on_call" event handler
            play.roomscript_finished = 1;
        }

        // if they've changed rooms, cancel any further pending scripts
        if ((displayed_room != old_room_number) || (load_new_game))
            break;
    }
    copyof.numanother = 0;

}