Example #1
0
/*
 * map_strategy:
 *   open always succeeds, I/O always fails, other functions
 *   perform their function
 */
int mapstrategy(RP rp)
{
    switch (rp->rp_cmd) {
    case CMDInit:
        return map_init(rp);
    case CMDClose:
        return map_close(rp);
    case CMDOpen:
        return map_open();
    case CMDShutdown:
        return map_shutdown();
    case CMDGenIOCTL:
        return map_ioctl(rp);
    case CMDINPUT:
    case CMDOUTPUT:
        RWCNT(rp) = 0;
        return RPDONE;
    case CMDOUTPUTV:
    case CMDInputF:
    case CMDOutputF:
    case CMDInputS:
    case CMDOutputS:
    default:
        return RP_EBAD;
    }
}
Example #2
0
int map_alloc(jk_map_t **m)
{
    if(m) {
        return map_open(*m = (jk_map_t *)malloc(sizeof(jk_map_t)));
    }
    
    return JK_FALSE;
}
Example #3
0
int		main(int ac, char **av)
{
  char		*buffer;
  struct stat	st;
  int		size;

  if (ac != 2)
    {
      my_putstr_error("You must have 2 arguments.\n");
      return (1);
    }
  if (stat(av[1], &st) == -1)
    {
      my_putstr_error("Stat has failed\n");
      exit(1);
    }
  size = st.st_size;
  buffer = malloc(size);
  map_open(av[1], buffer, size);
  return (0);
}
Example #4
0
/**
 * @brief Runs the input command.
 *
 *    @param keynum The index of the  keybind.
 *    @param value The value of the keypress (defined above).
 *    @param kabs The absolute value.
 */
static void input_key( int keynum, double value, double kabs, int repeat )
{
   unsigned int t;
   HookParam hparam[3];

   /* Repetition stuff. */
   if (conf.repeat_delay != 0) {
      if ((value == KEY_PRESS) && !repeat) {
         repeat_key        = keynum;
         repeat_keyTimer   = SDL_GetTicks();
         repeat_keyCounter = 0;
      }
      else if (value == KEY_RELEASE) {
         repeat_key        = -1;
         repeat_keyTimer   = 0;
         repeat_keyCounter = 0;
      }
   }

   /*
    * movement
    */
   /* accelerating */
   if (KEY("accel") && !repeat) {
      if (kabs >= 0.) {
         player_restoreControl( PINPUT_MOVEMENT, NULL );
         player_accel(kabs);
         input_accelButton = 1;
      }
      else { /* prevent it from getting stuck */
         if (value==KEY_PRESS) {
            player_restoreControl( PINPUT_MOVEMENT, NULL );
            player_setFlag(PLAYER_ACCEL);
            player_accel(1.);
            input_accelButton = 1;
         }

         else if (value==KEY_RELEASE) {
            player_accelOver();
            player_rmFlag(PLAYER_ACCEL);
            input_accelButton = 0;
         }

         /* double tap accel = afterburn! */
         t = SDL_GetTicks();
         if ((conf.afterburn_sens != 0) &&
               (value==KEY_PRESS) && INGAME() && NOHYP() && NODEAD() &&
               (t-input_accelLast <= conf.afterburn_sens))
            pilot_afterburn( player.p );
         else if (value==KEY_RELEASE)
            pilot_afterburnOver( player.p );

         if (value==KEY_PRESS)
            input_accelLast = t;
      }

   /* turning left */
   } else if (KEY("left") && !repeat) {
      if (kabs >= 0.) {
         player_restoreControl( PINPUT_MOVEMENT, NULL );
         player_setFlag(PLAYER_TURN_LEFT);
         player_left = kabs;
      }
      else {
         /* set flags for facing correction */
         if (value==KEY_PRESS) {
            player_restoreControl( PINPUT_MOVEMENT, NULL );
            player_setFlag(PLAYER_TURN_LEFT);
            player_left = 1.;
         }
         else if (value==KEY_RELEASE) {
            player_rmFlag(PLAYER_TURN_LEFT);
            player_left = 0.;
         }
      }

   /* turning right */
   } else if (KEY("right") && !repeat) {
      if (kabs >= 0.) {
         player_restoreControl( PINPUT_MOVEMENT, NULL );
         player_setFlag(PLAYER_TURN_RIGHT);
         player_right = kabs;
      }
      else {
         /* set flags for facing correction */
         if (value==KEY_PRESS) {
            player_restoreControl( PINPUT_MOVEMENT, NULL );
            player_setFlag(PLAYER_TURN_RIGHT);
            player_right = 1.;
         }
         else if (value==KEY_RELEASE) {
            player_rmFlag(PLAYER_TURN_RIGHT);
            player_right = 0.;
         }
      }

   /* turn around to face vel */
   } else if (KEY("reverse") && !repeat) {
      if (value==KEY_PRESS) {
         player_restoreControl( PINPUT_MOVEMENT, NULL );
         player_setFlag(PLAYER_REVERSE);
      }
      else if ((value==KEY_RELEASE) && player_isFlag(PLAYER_REVERSE)) {
         player_rmFlag(PLAYER_REVERSE);

         if (!player_isFlag(PLAYER_ACCEL))
            player_accelOver();
      }


   /*
    * combat
    */
   /* shooting primary weapon */
   } else if (KEY("primary") && NODEAD() && !repeat) {
      if (value==KEY_PRESS) {
         player_setFlag(PLAYER_PRIMARY);
      }
      else if (value==KEY_RELEASE)
         player_rmFlag(PLAYER_PRIMARY);
   /* targeting */
   } else if (INGAME() && NODEAD() && KEY("target_next")) {
      if (value==KEY_PRESS) player_targetNext(0);
   } else if (INGAME() && NODEAD() && KEY("target_prev")) {
      if (value==KEY_PRESS) player_targetPrev(0);
   } else if (INGAME() && NODEAD() && KEY("target_nearest")) {
      if (value==KEY_PRESS) player_targetNearest();
   } else if (INGAME() && NODEAD() && KEY("target_nextHostile")) {
      if (value==KEY_PRESS) player_targetNext(1);
   } else if (INGAME() && NODEAD() && KEY("target_prevHostile")) {
      if (value==KEY_PRESS) player_targetPrev(1);
   } else if (INGAME() && NODEAD() && KEY("target_hostile")) {
      if (value==KEY_PRESS) player_targetHostile();
   } else if (INGAME() && NODEAD() && KEY("target_clear")) {
      if (value==KEY_PRESS) player_targetClear();
   /* face the target */
   } else if (INGAME() && NODEAD() && KEY("face") && !repeat) {
      if (value==KEY_PRESS) {
         player_restoreControl( PINPUT_MOVEMENT, NULL );
         player_setFlag(PLAYER_FACE);
      }
      else if ((value==KEY_RELEASE) && player_isFlag(PLAYER_FACE))
         player_rmFlag(PLAYER_FACE);

   /* board them ships */
   } else if (KEY("board") && INGAME() && NOHYP() && NODEAD() && !repeat) {
      if (value==KEY_PRESS) {
         player_restoreControl( 0, NULL );
         player_board();
      }


   /*
    * Escorts.
    */
   } else if (INGAME() && NODEAD() && KEY("e_targetNext") && !repeat) {
      if (value==KEY_PRESS) player_targetEscort(0);
   } else if (INGAME() && NODEAD() && KEY("e_targetPrev") && !repeat) {
      if (value==KEY_PRESS) player_targetEscort(1);
   } else if (INGAME() && NODEAD() && KEY("e_attack") && !repeat) {
      if (value==KEY_PRESS) escorts_attack(player.p);
   } else if (INGAME() && NODEAD() && KEY("e_hold") && !repeat) {
      if (value==KEY_PRESS) escorts_hold(player.p);
   } else if (INGAME() && NODEAD() && KEY("e_return") && !repeat) {
      if (value==KEY_PRESS) escorts_return(player.p);
   } else if (INGAME() && NODEAD() && KEY("e_clear") && !repeat) {
      if (value==KEY_PRESS) escorts_clear(player.p);


   /*
    * secondary weapons
    */
   /* shooting secondary weapon */
   } else if (KEY("secondary") && NOHYP() && NODEAD() && !repeat) {
      if (value==KEY_PRESS) {
         player_setFlag(PLAYER_SECONDARY);
      }
      else if (value==KEY_RELEASE)
         player_rmFlag(PLAYER_SECONDARY);

   /* Weapon sets. */
   } else if (KEY("weapset1")) {
      player_weapSetPress( 0, value, repeat );
   } else if (KEY("weapset2")) {
      player_weapSetPress( 1, value, repeat );
   } else if (KEY("weapset3")) {
      player_weapSetPress( 2, value, repeat );
   } else if (KEY("weapset4")) {
      player_weapSetPress( 3, value, repeat );
   } else if (KEY("weapset5")) {
      player_weapSetPress( 4, value, repeat );
   } else if (KEY("weapset6")) {
      player_weapSetPress( 5, value, repeat );
   } else if (KEY("weapset7")) {
      player_weapSetPress( 6, value, repeat );
   } else if (KEY("weapset8")) {
      player_weapSetPress( 7, value, repeat );
   } else if (KEY("weapset9")) {
      player_weapSetPress( 8, value, repeat );
   } else if (KEY("weapset0")) {
      player_weapSetPress( 9, value, repeat );

   /*
    * space
    */
   } else if (KEY("autonav") && INGAME() && NOHYP() && NODEAD()) {
      if (value==KEY_PRESS) player_autonavStart();
   /* target planet (cycles like target) */
   } else if (KEY("target_planet") && INGAME() && NOHYP() && NOLAND() && NODEAD()) {
      if (value==KEY_PRESS) player_targetPlanet();
   /* target nearest planet or attempt to land */
   } else if (KEY("land") && INGAME() && NOHYP() && NOLAND() && NODEAD()) {
      if (value==KEY_PRESS)
         player_land();
   } else if (KEY("thyperspace") && NOHYP() && NOLAND() && NODEAD()) {
      if (value==KEY_PRESS)
         player_targetHyperspace();
   } else if (KEY("starmap") && NOHYP() && NODEAD() && !repeat) {
      if (value==KEY_PRESS) map_open();
   } else if (KEY("jump") && INGAME() && !repeat) {
      if (value==KEY_PRESS) {
         player_restoreControl( 0, NULL );
         player_jump();
      }
   } else if (KEY("overlay") && NODEAD() && INGAME() && !repeat) {
      ovr_key( value );
   } else if (KEY("mousefly") && NODEAD() && !repeat) {
      if (value==KEY_PRESS)
         player_toggleMouseFly();
   } else if (KEY("autobrake") && NOHYP() && NOLAND() && NODEAD() && !repeat) {
      if (value==KEY_PRESS) {
         player_restoreControl( PINPUT_BRAKING, NULL );
         player_brake();
      }

   /*
    * Communication.
    */
   } else if (KEY("log_up") && INGAME() && NODEAD()) {
      if (value==KEY_PRESS) {
         gui_messageScrollUp(5);
      }
   } else if (KEY("log_down") && INGAME() && NODEAD()) {
      if (value==KEY_PRESS) {
         gui_messageScrollDown(5);
      }
   } else if (KEY("hail") && INGAME() && NOHYP() && NODEAD() && !repeat) {
      if (value==KEY_PRESS) {
         player_hail();
      }
   } else if (KEY("autohail") && INGAME() && NOHYP() && NODEAD() && !repeat) {
      if (value==KEY_PRESS) {
         player_autohail();
      }


   /*
    * misc
    */
   /* zooming in */
   } else if (KEY("mapzoomin") && INGAME() && NODEAD()) {
      if (value==KEY_PRESS) gui_setRadarRel(-1);
   /* zooming out */
   } else if (KEY("mapzoomout") && INGAME() && NODEAD()) {
      if (value==KEY_PRESS) gui_setRadarRel(1);
   /* take a screenshot */
   } else if (KEY("screenshot")) {
      if (value==KEY_PRESS) player_screenshot();
#if SDL_VERSION_ATLEAST(2,0,0)
   /* toggle fullscreen */
   } else if (KEY("togglefullscreen") && !repeat) {
      if (value==KEY_PRESS) naev_toggleFullscreen();
#endif /* SDL_VERSION_ATLEAST(2,0,0) */
   /* pause the games */
   } else if (KEY("pause") && !repeat) {
      if (value==KEY_PRESS) {
         if (!toolkit_isOpen()) {
            if (paused)
               unpause_game();
            else
               pause_player();
         }
      }
   /* toggle speed mode */
   } else if (KEY("speed") && !repeat) {
      if ((value==KEY_PRESS) && (!player_isFlag( PLAYER_CINEMATICS_2X ))) {
         if (player_isFlag(PLAYER_DOUBLESPEED)) {
            if (!player_isFlag(PLAYER_AUTONAV))
               pause_setSpeed(1.);
            player_rmFlag(PLAYER_DOUBLESPEED);
         } else {
            if (!player_isFlag(PLAYER_AUTONAV))
               pause_setSpeed(2.);
            player_setFlag(PLAYER_DOUBLESPEED);
         }
      }
   /* opens a small menu */
   } else if (KEY("menu") && NODEAD() && !repeat) {
      if (value==KEY_PRESS) menu_small();

   /* shows pilot information */
   } else if (KEY("info") && NOHYP() && NODEAD() && !repeat) {
      if (value==KEY_PRESS) menu_info( INFO_MAIN );

   /* Opens the Lua console. */
   } else if (KEY("console") && NODEAD() && !repeat) {
      if (value==KEY_PRESS) cli_open();
   }

   /* Key press not used. */
   else {
      return;
   }

   /* Run the hook. */
   hparam[0].type    = HOOK_PARAM_STRING;
   hparam[0].u.str   = input_keybinds[keynum].name;
   hparam[1].type    = HOOK_PARAM_BOOL;
   hparam[1].u.b     = (value > 0.);
   hparam[2].type    = HOOK_PARAM_SENTINEL;
   hooks_runParam( "input", hparam );
}
Example #5
0
/* loads the city level */
void load_city(int populate)
{
    int i,j;
    pml ml;
    char site;
    map *city;
    map *maze;

    initrand(E_CITY, 0);

    /* Get the hedge maze (which is in the city). */
    maze = map_open(MAP_hedges);
    /* Choose a random level from it. */
    map_setLevel(maze, random_range(map_getDepth(maze)));

    /* Get the city. */
    city = map_open(MAP_city);
    map_setLevel(city,0);

    TempLevel = Level;
    if (ok_to_free(TempLevel)) {
#ifndef SAVE_LEVELS
        free_level(TempLevel);
#endif
        TempLevel = NULL;
    }
#ifndef SAVE_LEVELS
    Level = ((plv) checkmalloc(sizeof(levtype)));
#else
    msdos_changelevel(TempLevel,0,-1);
    Level = &TheLevel;
#endif
    clear_level(Level);
    Level->depth = 0;
    Level->environment = E_CITY;

    /* WDT: Rampart, as a special case, has its width stored in a
    * global variable. */
    WIDTH = Level->level_width = map_getWidth(city);
    LENGTH = Level->level_length = map_getLength(city);

    for(j=0; j<Level->level_length; j++) {
        for(i=0; i<Level->level_width; i++) {
            lset(i,j,SEEN);
            site = map_getSiteChar(city,i,j);
            switch(site) {
                /*
                case '@':
                Player.x = i; Player.y = j;
                Level->site[i][j].locchar = FLOOR;
                break;
                */
            case 'g':
                Level->site[i][j].locchar = FLOOR;
                Level->site[i][j].p_locf = L_GARDEN;
                break;
            case 'y':
                Level->site[i][j].locchar = FLOOR;
                Level->site[i][j].p_locf = L_CEMETARY;
                break;
            case 'p': /* WDT: each of these places needs to be assigned
					  * a function (or replaced with an 'x' in the map)
					  */
            case '!':
            case 'I':
            case 'E':
            case 'e':
            case 'x':
                assign_city_function(i,j);
                break;
            case 't':
                Level->site[i][j].locchar = FLOOR;
                Level->site[i][j].p_locf = L_TEMPLE;
                CitySiteList[L_TEMPLE-CITYSITEBASE][0] = TRUE;
                CitySiteList[L_TEMPLE-CITYSITEBASE][1] = i;
                CitySiteList[L_TEMPLE-CITYSITEBASE][2] = j;
                break;
#if 0 /* WDT: HACK!  The new city doesn't use portcullis traps, but has other
                * uses for 'T'.  Um...  I'd rather have a use for them (that's what
                * the jail is supposed to be), so this will stay only for now; with
                    * any luck we'll have things fixed up before the next release. */
                    case 'T':
                    Level->site[i][j].locchar = FLOOR;
                    Level->site[i][j].p_locf = L_PORTCULLIS_TRAP;
                    Level->site[i][j].aux = NOCITYMOVE;
                    break;
#endif /* end of hack */
                    case 'R':
                    Level->site[i][j].locchar = FLOOR;
                    Level->site[i][j].p_locf = L_RAISE_PORTCULLIS;
                    Level->site[i][j].aux = NOCITYMOVE;
                    break;
                    case '7':
                    Level->site[i][j].locchar = FLOOR;
                    Level->site[i][j].p_locf = L_PORTCULLIS;
                    Level->site[i][j].aux = NOCITYMOVE;
                    break;
                    case 'C':
                    Level->site[i][j].locchar = OPEN_DOOR;
                    Level->site[i][j].p_locf = L_COLLEGE;
                    CitySiteList[L_COLLEGE-CITYSITEBASE][0] = TRUE;
                    CitySiteList[L_COLLEGE-CITYSITEBASE][1] = i;
                    CitySiteList[L_COLLEGE-CITYSITEBASE][2] = j;
                    break;
                    case 's':
                    Level->site[i][j].locchar = OPEN_DOOR;
                    Level->site[i][j].p_locf = L_SORCERORS;
                    CitySiteList[L_SORCERORS-CITYSITEBASE][0] = TRUE;
                    CitySiteList[L_SORCERORS-CITYSITEBASE][1] = i;
                    CitySiteList[L_SORCERORS-CITYSITEBASE][2] = j;
                    break;
                    case 'M':
                    Level->site[i][j].locchar = OPEN_DOOR;
                    Level->site[i][j].p_locf = L_MERC_GUILD;
                    CitySiteList[L_MERC_GUILD-CITYSITEBASE][0] = TRUE;
                    CitySiteList[L_MERC_GUILD-CITYSITEBASE][1] = i;
                    CitySiteList[L_MERC_GUILD-CITYSITEBASE][2] = j;
                    break;
                    case 'K':
                    Level->site[i][j].locchar = OPEN_DOOR;
                    Level->site[i][j].p_locf = L_MONASTERY;
                    CitySiteList[L_MONASTERY-CITYSITEBASE][0] = TRUE;
                    CitySiteList[L_MONASTERY-CITYSITEBASE][1] = i;
                    CitySiteList[L_MONASTERY-CITYSITEBASE][2] = j;
                    break;
                    case 'c':
                    Level->site[i][j].locchar = OPEN_DOOR;
                    Level->site[i][j].p_locf = L_CASTLE;
                    CitySiteList[L_CASTLE-CITYSITEBASE][0] = TRUE;
                    CitySiteList[L_CASTLE-CITYSITEBASE][1] = i;
                    CitySiteList[L_CASTLE-CITYSITEBASE][2] = j;
                    break;
                    case '?':
            {
                static int myI = -1, myJ;
                char site;
                if ( myI == -1 )
            {
                /* If this is the first time we've seen the hedge maze,
                * set this as its corner. */
                myI = i;
                myJ = j;
            }
    site = map_getSiteChar(maze, i - myI, j - myJ);
        mazesite(site,i,j,populate);
    }
    break;
    case 'P':
        Level->site[i][j].locchar = OPEN_DOOR;
        Level->site[i][j].p_locf = L_ORDER;
        CitySiteList[L_ORDER-CITYSITEBASE][0] = TRUE;
        CitySiteList[L_ORDER-CITYSITEBASE][1] = i;
        CitySiteList[L_ORDER-CITYSITEBASE][2] = j;
        break;
    case 'H':
        Level->site[i][j].locchar = OPEN_DOOR;
        Level->site[i][j].p_locf = L_CHARITY;
        CitySiteList[L_CHARITY-CITYSITEBASE][0] = TRUE;
        CitySiteList[L_CHARITY-CITYSITEBASE][1] = i;
        CitySiteList[L_CHARITY-CITYSITEBASE][2] = j;
        break;
    case 'h':
        Level->site[i][j].locchar = FLOOR;
        if (populate)
            make_horse(i,j); /* from village.c */
        break;
    case 'j':
        Level->site[i][j].locchar = FLOOR;
        if (populate)
            make_justiciar(i,j);
        break;
    case 'J':
        Level->site[i][j].locchar = CLOSED_DOOR;
        Level->site[i][j].p_locf = L_JAIL;
        break;
    case 'A':
        Level->site[i][j].locchar = OPEN_DOOR;
        Level->site[i][j].p_locf = L_ARENA;
        CitySiteList[L_ARENA-CITYSITEBASE][0] = TRUE;
        CitySiteList[L_ARENA-CITYSITEBASE][1] = i;
        CitySiteList[L_ARENA-CITYSITEBASE][2] = j;
        break;
    case 'B':
        Level->site[i][j].locchar = OPEN_DOOR;
        Level->site[i][j].p_locf = L_BANK;
        CitySiteList[L_BANK-CITYSITEBASE][0] = TRUE;
        CitySiteList[L_BANK-CITYSITEBASE][1] = i;
        CitySiteList[L_BANK-CITYSITEBASE][2] = j;
        lset(i,j,STOPS);
        lset(i,j+1,STOPS);
        lset(i+1,j,STOPS);
        lset(i-1,j,STOPS);
        lset(i,j-1,STOPS);
        break;
    case 'i':
        Level->site[i][j].locchar = OPEN_DOOR;
        Level->site[i][j].p_locf = L_TOURIST;
        CitySiteList[L_TOURIST-CITYSITEBASE][1] = i;
        CitySiteList[L_TOURIST-CITYSITEBASE][2] = j;
        lset(i,j,STOPS);
        lset(i,j+1,STOPS);
        lset(i+1,j,STOPS);
        lset(i-1,j,STOPS);
        lset(i,j-1,STOPS);
        break;
    case 'X':
        Level->site[i][j].locchar = FLOOR;
        Level->site[i][j].p_locf = L_COUNTRYSIDE;
        CitySiteList[L_COUNTRYSIDE-CITYSITEBASE][0] = TRUE;
        CitySiteList[L_COUNTRYSIDE-CITYSITEBASE][1] = i;
        CitySiteList[L_COUNTRYSIDE-CITYSITEBASE][2] = j;
        break;
    case 'v':
        Level->site[i][j].locchar = FLOOR;
        Level->site[i][j].p_locf = L_VAULT;
        Level->site[i][j].aux = NOCITYMOVE;
        lset(i,j,SECRET);
        break;
    case 'S':
        Level->site[i][j].locchar = FLOOR;
        Level->site[i][j].aux = NOCITYMOVE;
        lset(i,j,SECRET);
        break;
    case 'G':
        Level->site[i][j].locchar = FLOOR;
        if (populate) {
            make_site_monster(i,j,GUARD);
            Level->site[i][j].creature->aux1 = i;
            Level->site[i][j].creature->aux2 = j;
        }
        break;
    case 'u':
        Level->site[i][j].locchar = FLOOR;
        if (populate)
            make_minor_undead(i,j);
        break;
    case 'U':
        Level->site[i][j].locchar = FLOOR;
        if (populate)
            make_major_undead(i,j);
        break;
    case 'V':
        Level->site[i][j].showchar = WALL;
        Level->site[i][j].locchar = FLOOR;
        Level->site[i][j].p_locf = L_VAULT;
        if (populate)
            make_site_treasure(i,j,5);
        Level->site[i][j].aux = NOCITYMOVE;
        lset(i,j,SECRET);
        break;
    case '%':
        Level->site[i][j].showchar = WALL;
        Level->site[i][j].locchar = FLOOR;
        Level->site[i][j].p_locf = L_TRAP_SIREN;
        if (populate)
            make_site_treasure(i,j,5);
        Level->site[i][j].aux = NOCITYMOVE;
        lset(i,j,SECRET);
        break;
    case '$':
        Level->site[i][j].locchar = FLOOR;
        if (populate)
            make_site_treasure(i,j,5);
        break;
    case '2':
        Level->site[i][j].locchar = ALTAR;
        Level->site[i][j].p_locf = L_ALTAR;
        Level->site[i][j].aux = ODIN;
        break;
    case '3':
        Level->site[i][j].locchar = ALTAR;
        Level->site[i][j].p_locf = L_ALTAR;
        Level->site[i][j].aux = SET;
        break;
    case '4':
        Level->site[i][j].locchar = ALTAR;
        Level->site[i][j].p_locf = L_ALTAR;
        Level->site[i][j].aux = ATHENA;
        break;
    case '5':
        Level->site[i][j].locchar = ALTAR;
        Level->site[i][j].p_locf = L_ALTAR;
        Level->site[i][j].aux = HECATE;
        break;
    case '6':
        Level->site[i][j].locchar = ALTAR;
        Level->site[i][j].p_locf = L_ALTAR;
        Level->site[i][j].aux = DESTINY;
        break;
    case '^':
        Level->site[i][j].showchar = WALL;
        Level->site[i][j].locchar = FLOOR;
        Level->site[i][j].p_locf = TRAP_BASE+random_range(NUMTRAPS);
        lset(i,j,SECRET);
        break;
    case '"':
        Level->site[i][j].locchar = HEDGE;
        break;
    case '~':
        Level->site[i][j].locchar = WATER;
        Level->site[i][j].p_locf = L_WATER;
        break;
    case '=':
        Level->site[i][j].locchar = WATER;
        Level->site[i][j].p_locf = L_MAGIC_POOL;
        break;
    case '*':
        Level->site[i][j].locchar = WALL;
        Level->site[i][j].aux = 10;
        break;
    case '#':
        Level->site[i][j].locchar = WALL;
        Level->site[i][j].aux = 500;
        break;
    case 'T':/* currently meaningless in large city map. */
    case '>':  /* currently meaningless outside of maze.*/
    case '.':
        Level->site[i][j].locchar = FLOOR;
        break;
    case ',':
        Level->site[i][j].showchar = WALL;
        Level->site[i][j].locchar = FLOOR;
        Level->site[i][j].aux = NOCITYMOVE;
        lset(i,j,SECRET);
        break;
    case '-':
    case 'D': /* WDT: should all Ds be changed to -, or should D be given
					  * special treatment? */
        Level->site[i][j].locchar = CLOSED_DOOR;
        break;
    case '1':
        Level->site[i][j].locchar = STATUE;
        break;
    default:
        printf("\nOops... missed a case [%d,%d]: '%c' (%d)\n", i,j,site,site);
        morewait();
    }

    if (loc_statusp(i,j,SEEN)) {
        if (loc_statusp(i,j,SECRET))
            Level->site[i][j].showchar = WALL;
        else Level->site[i][j].showchar = Level->site[i][j].locchar;
    }
}
}
map_close(maze);
map_close(city);
City = Level;

       /* make all city monsters asleep, and shorten their wakeup range to 2 */
       /* to prevent players from being molested by vicious monsters on */
       /* the streets */
for(ml=Level->mlist; ml!=NULL; ml=ml->next) {
    m_status_reset(ml->m,AWAKE);
    ml->m->wakeup = 2;
}
initrand(E_RESTORE, 0);
}
Example #6
0
File: dropsbr.c Project: dscho/nmh
int
map_write (char *mailbox, int md, int id, long last, off_t start,
           off_t stop, long pos, int size, int noisy)
{
    register int i;
    int clear, fd, td;
    char *file;
    register struct drop *dp;
    struct drop d1, d2, *rp;
    register FILE *fp;
    struct stat st;

    if ((fd = map_open (file = map_name (mailbox), md)) == NOTOK)
	return NOTOK;

    if ((fstat (fd, &st) == OK) && (st.st_size > 0))
	clear = 0;
    else
	clear = 1;

    if (!clear && map_chk (file, fd, &d1, pos, noisy)) {
	(void) m_unlink (file);
	mbx_close (file, fd);
	if ((fd = map_open (file, md)) == NOTOK)
	    return NOTOK;
	clear++;
    }

    if (clear) {
	if ((td = dup (md)) == NOTOK || (fp = fdopen (td, "r")) == NULL) {
	    if (noisy)
		admonish (file, "unable to %s", td != NOTOK ? "fdopen" : "dup");
	    if (td != NOTOK)
		close (td);
	    mbx_close (file, fd);
	    return NOTOK;
	}

	switch (i = mbx_read (fp, 0, &rp, noisy)) {
	    case NOTOK:
		fclose (fp);
		mbx_close (file, fd);
		return NOTOK;

	    case OK:
		fclose (fp);
		break;

	    default:
		d1.d_id = 0;
		for (dp = rp; i-- >0; dp++) {
		    if (dp->d_start == start)
			dp->d_id = id;
		    lseek (fd, (off_t) (++d1.d_id * sizeof(*dp)), SEEK_SET);
		    if (write (fd, (char *) dp, sizeof(*dp)) != sizeof(*dp)) {
			if (noisy)
			    admonish (file, "write error");
			mbx_close (file, fd);
			fclose (fp);
			return NOTOK;
		    }
		}
		free ((char *) rp);
		fclose (fp);
		break;
	}
    }
    else {
	if (last == 0)
	    last = d1.d_start;
	dp = &d2;
	dp->d_id = id;
	dp->d_size = (long) (size ? size : mbx_size (fd, start, stop));
	dp->d_start = start;
	dp->d_stop = stop;
	lseek (fd, (off_t) (++d1.d_id * sizeof(*dp)), SEEK_SET);
	if (write (fd, (char *) dp, sizeof(*dp)) != sizeof(*dp)) {
	    if (noisy)
		admonish (file, "write error");
	    mbx_close (file, fd);
	    return NOTOK;
	}
    }

    dp = &d1;
    dp->d_size = DRVRSN;
    dp->d_start = (long) last;
    dp->d_stop = lseek (md, (off_t) 0, SEEK_CUR);

    lseek (fd, (off_t) 0, SEEK_SET);
    if (write (fd, (char *) dp, sizeof(*dp)) != sizeof(*dp)) {
	if (noisy)
	    admonish (file, "write error");
	mbx_close (file, fd);
	return NOTOK;
    }

    mbx_close (file, fd);

    return OK;
}
Example #7
0
/* loads the house level into Level*/
void load_house(int kind, int populate)
{
  map *home;
  int i,j;
  char site;
  int stops;
  
  TempLevel = Level;
  initrand(Current_Environment, Player.x + Player.y + hour()*10);
  if (ok_to_free(TempLevel)) {
#ifndef SAVE_LEVELS
    free_level(TempLevel);
#endif
    TempLevel = NULL;
  }
#ifndef SAVE_LEVELS
  Level = ((plv) checkmalloc(sizeof(levtype)));
#else
  msdos_changelevel(TempLevel,0,-1);
  Level = &TheLevel;
#endif
  clear_level(Level);
  switch(kind) {
  case E_HOUSE:
    home = map_open(MAP_house);
    break;
  case E_MANSION:
    home = map_open(MAP_mansion);
    break;
  default:
  case E_HOVEL:
    home = map_open(MAP_hovel);
    break;
  }
  Level->level_width=map_getWidth(home);
  Level->level_length=map_getLength(home);
  map_setLevel(home, 0);
  
  stops = 0;
  for(j=0;j<Level->level_length;j++) {
    for(i=0;i<Level->level_width;i++) {
      if (kind == E_HOVEL) Level->site[i][j].lstatus = SEEN;
      else Level->site[i][j].lstatus = 0;
      Level->site[i][j].roomnumber = RS_CORRIDOR;
      Level->site[i][j].p_locf = L_NO_OP;
      site = map_getSiteChar(home,i,j);
      switch(site) {
      case 'N':
	Level->site[i][j].locchar = FLOOR;
	Level->site[i][j].roomnumber = RS_BEDROOM;
	if (random_range(2) && populate) make_house_npc(i,j);
	break;
      case 'H':
	Level->site[i][j].locchar = FLOOR;
	Level->site[i][j].roomnumber = RS_BEDROOM;
	if (random_range(2) && populate) make_mansion_npc(i,j);
	break;
      case 'D':
	Level->site[i][j].locchar = FLOOR;
	Level->site[i][j].roomnumber = RS_DININGROOM;
	break;
      case '.':
	Level->site[i][j].locchar = FLOOR;
	if (stops) {
	  lset(i,j,STOPS);
	  stops = 0;
	}
	break;
      case 'c':
	Level->site[i][j].locchar = FLOOR;
	Level->site[i][j].roomnumber = RS_CLOSET;
	break;
      case 'G':
	Level->site[i][j].locchar = FLOOR;
	Level->site[i][j].roomnumber = RS_BATHROOM;
	break;
      case 'B':
	Level->site[i][j].locchar = FLOOR;
	Level->site[i][j].roomnumber = RS_BEDROOM;
	break;
      case 'K':
	Level->site[i][j].locchar = FLOOR;
	Level->site[i][j].roomnumber = RS_KITCHEN;
	break;
      case 'S':
	Level->site[i][j].locchar = FLOOR;
	Level->site[i][j].showchar = WALL;
	lset(i,j,SECRET);
	Level->site[i][j].roomnumber = RS_SECRETPASSAGE;
	break;
      case '3':
	Level->site[i][j].locchar = SAFE;
	Level->site[i][j].showchar = WALL;
	lset(i,j,SECRET);
	Level->site[i][j].p_locf = L_SAFE;
	break;
      case '^':
	Level->site[i][j].locchar = FLOOR;
	Level->site[i][j].p_locf = TRAP_BASE+random_range(NUMTRAPS);
	break;
      case 'P':
	Level->site[i][j].locchar = PORTCULLIS;
	Level->site[i][j].p_locf = L_PORTCULLIS;
	break;
      case 'R':
	Level->site[i][j].locchar = FLOOR;
	Level->site[i][j].p_locf = L_RAISE_PORTCULLIS;
	break;
      case 'p':
	Level->site[i][j].locchar = FLOOR;
	Level->site[i][j].p_locf = L_PORTCULLIS;
	break;
      case 'T':
	Level->site[i][j].locchar = FLOOR;
	Level->site[i][j].p_locf = L_PORTCULLIS_TRAP;
	break;
      case 'X':
	Level->site[i][j].locchar = FLOOR;
	Level->site[i][j].p_locf = L_HOUSE_EXIT;
	stops = 1;
	break;
      case '#':
	Level->site[i][j].locchar = WALL;
	switch (kind) {
	  case E_HOVEL: Level->site[i][j].aux = 10; break;
	  case E_HOUSE: Level->site[i][j].aux = 50; break;
	  case E_MANSION: Level->site[i][j].aux = 150; break;
	}
	break;
      case '|':
	Level->site[i][j].locchar = OPEN_DOOR;
	Level->site[i][j].roomnumber = RS_CORRIDOR;
	lset(i,j,STOPS);
	break;
      case '+':
	Level->site[i][j].locchar = CLOSED_DOOR;
	Level->site[i][j].roomnumber = RS_CORRIDOR;
	Level->site[i][j].aux = LOCKED;
	lset(i,j,STOPS);
	break;
      case 'd':
	Level->site[i][j].locchar = FLOOR;
	Level->site[i][j].roomnumber = RS_CORRIDOR;
	if (populate)
	  make_site_monster(i,j,DOBERMAN);
	break;
      case 'a':
	Level->site[i][j].locchar = FLOOR;
	Level->site[i][j].roomnumber = RS_CORRIDOR;
	Level->site[i][j].p_locf = L_TRAP_SIREN;
	break;
      case 'A':
	Level->site[i][j].locchar = FLOOR;
	Level->site[i][j].roomnumber = RS_CORRIDOR;
	if (populate)
	  make_site_monster(i,j,AUTO_MINOR); /* automaton */
	break;
      }
      Level->site[i][j].showchar = ' ';
    }
  }
  map_close(home);
  initrand(E_RESTORE, 0);
}
Example #8
0
int main (int argc, char **argv) {

	// variables
	SDL_Surface *screen; // pantalla
	SDL_Event event; // para los eventos de SDL (teclado y/o mouse)
	Uint8 *keystates = SDL_GetKeyState(NULL); // para detectar teclas mantenidas presionadas
	Uint8 salir = 0; // para determinar cuando se cierra la ventana
	int mouse_x=0, mouse_y=0; // coordenadas del mouse
	char info1[100]; // texto para mostrar informacion variada linea 1
	char info2[100]; // texto para mostrar informacion variada linea 2
	short int time; // variable para la hora
	short int ticks; // variable para mover elementos independiente de los FPS

	// cargar configuracion
	struct conf *conf = conf_load();
	if (!conf)
		return EXIT_FAILURE;

	// verificar a donde nos queremos conectar
	// se indicó el servidor como 1er parametro
	if(argc>=2) {
		free(conf->SERVER);
		conf->SERVER = malloc(strlen(argv[1]));
		strcpy(conf->SERVER, argv[1]);
	}
	// se indicó el puerto como 2do parametro
	if(argc>=3) {
		conf->PORT = atoi(argv[2]);
	}

	// conectar al servidor
	int connection = client_init(conf);
	if (!connection)
		return EXIT_FAILURE;
	// buffer para transferencia entre servidor y cliente
	char buffer[BUFFER_SIZE];

	// obtener id del jugador
	int playerID = atoi(query("get;id", connection));

	// recibir y actualizar configuraciones desde el servidor
	conf_update(conf, query("get;conf", connection));

	// inicializar sistema
	sdl_init(&screen);
	// cargar fuente
	TTF_Font *fuente = ttf_load(FONT_NAME, FONT_SIZE, FONT_STYLE);
	// cargar todos los posibles objetos de un mapa
	MapObject *mapobjects = mapobjects_load(screen);
	if (!mapobjects)
		return EXIT_FAILURE;
	// cargar mapa
	char **map = map_open(conf->MAP);
	if (!map)
		return EXIT_FAILURE;
	// cargar armas
	Weapon *weapons = weapons_load();
	if (!weapons)
		return EXIT_FAILURE;
	// crear personaje jugador
	Player *pj = player_create(playerID, conf->PLAYER_NAME, conf->PLAYER_CHARACTER, screen, weapons, conf);
	// asignar armas al personaje
	player_change_weapon(&pj, conf->WEAPON_PRIMARY, 1);
	player_change_weapon(&pj, conf->WEAPON_SECONDARY, 2);
	// ubicar personaje en el mapa
	player_set_position(&pj, map, -1, -1, mapobjects);

	// informar estado del usuario
	bzero(buffer, sizeof(buffer));
	sprintf(buffer, "info;%s;%s", conf->PLAYER_CHARACTER, conf->PLAYER_NAME);
	write(connection, buffer, strlen(buffer));

	// crear bots y ubicar en el mapa
	Player *bots = bots_create(screen, weapons, conf);
	int i;
	for(i=0; i<conf->BOTS; ++i) {
		Player *aux = &bots[i];
		player_set_position(&aux, map, -1, -1, mapobjects);
	}

	// guardar ticks
	ticks = SDL_GetTicks();
	// ciclo infinito para refrescar la imagen de la pantalla
	while (!salir) {

		// solicitar informacion de todos los jugadores (menos el mio)
		char *enemies = query("get;players", connection);

		// enviar posicion del jugador al servidor
		sprintf(buffer, "position;%d;%d", (int)(pj->y), (int)(pj->x));
		write(connection, buffer, strlen(buffer));
		
		// time
		time = SDL_GetTicks()/1000;
		// dibujar mapa
		map_draw(screen, map, mapobjects, conf->BACKGROUND);
		// revisar si existen eventos de SDL
		while (SDL_PollEvent(&event)) {
			// salir del programa
			if(event.type==SDL_QUIT) salir = 1;
			// si se presiona una tecla
			else if(event.type==SDL_KEYDOWN) {
				// cambiar a pantalla completa
				if(event.key.keysym.sym==SDLK_f) SDL_WM_ToggleFullScreen(screen);
				// salir del juego
				else if(event.key.keysym.sym==SDLK_ESCAPE) salir = 1;
				// cambiar arma primaria
				else if(event.key.keysym.sym>=48&&event.key.keysym.sym<=57) player_change_weapon(&pj, event.key.keysym.sym-48, 1);
			}
			// si se mueve el mouse
			else if(event.type==SDL_MOUSEMOTION) {
				// guardar coordenadas del mouse
				mouse_x = event.motion.x;
				mouse_y = event.motion.y;
			}
			// si se presiona el mouse
			else if(event.type == SDL_MOUSEBUTTONDOWN ) {
				// guardar coordenadas del mouse
				mouse_x = event.button.x;
				mouse_y = event.button.y;
				// resetear flag de armas disparadas
				pj->primary->fired = 0;
				pj->secondary->fired = 0;
				// si se presiono el boton izquierdo
				if(event.button.button==SDL_BUTTON_LEFT && pj->primary->ammo) {
					Mix_PlayChannel(-1, pj->primary->sound, 0);
					pj->primary->fired = pj->primary->ammo--;
				}
				// si se presiono el boton derecho
				else if(event.button.button==SDL_BUTTON_RIGHT && pj->secondary->ammo) {
					Mix_PlayChannel(-1, pj->secondary->sound, 0);
					pj->secondary->fired = pj->secondary->ammo--;
				}
				// si se mueve el scroll se cambia el arma principal
				else if (event.button.button==SDL_BUTTON_WHEELUP) {
					player_change_weapon(&pj, WEAPON_PREV, 1);
				}
				else if (event.button.button==SDL_BUTTON_WHEELDOWN) {
					player_change_weapon(&pj, WEAPON_NEXT, 1);
				}
				// determinar si personaje fue herido
				if(mouse_x >= pj->x && mouse_x <= pj->x+SPRITE_SIZE && mouse_y >= pj->y && mouse_y <= pj->y+SPRITE_SIZE) {
					// hacer daño al personaje
					if(event.button.button==SDL_BUTTON_LEFT && pj->primary->fired) {
						pj->health -= pj->primary->damage;
						// reproducir sonido de dolor
						Mix_PlayChannel(-1, pj->sounds[PLAYER_SOUND_DAMAGED], 0);
					}
					else if(event.button.button==SDL_BUTTON_RIGHT && pj->secondary->fired) {
						pj->health -= pj->secondary->damage;
						// reproducir sonido de dolor
						Mix_PlayChannel(-1, pj->sounds[PLAYER_SOUND_DAMAGED], 0);
					}
					// si la salud quedo menor o igual a 0 el personaje muere
					if(pj->health<1) {
						// incrementar contador de muerte
						++pj->dead;
						pj->health = conf->PLAYER_HEALTH;
						// descontar vida
						if(conf->PLAYER_LIFE!=0) {
							--pj->life;
							if(pj->life==0) {
								// GAME OVER
							}
						}
						// reposicionar personaje muerto
						player_set_position(&pj, map, -1, -1, mapobjects);
					}
				}
			}
			// si se suelta el mouse
			else if(event.type==SDL_MOUSEBUTTONUP) {
				// guardar coordenadas del mouse
				mouse_x = event.button.x;
				mouse_y = event.button.y;
				// si se solto el boton izquierdo
				if(event.button.button==SDL_BUTTON_LEFT) {
					
				}
				// si se solto el boton derecho
				else if(event.button.button==SDL_BUTTON_RIGHT) {
					
				}
			}
		}
		// mover jugador
		player_move(&pj, keystates, map, mapobjects, conf, SDL_GetTicks()-ticks);
		player_get_object(&pj, map, conf);
		// primera linea informacion
		sprintf(info1, "time: %02d:%02d, mouse: (%04d,%04d)", time/60, time%60, mouse_x, mouse_y);
		SDL_Surface *s_info1 = TTF_RenderText_Blended(fuente, info1, (SDL_Color) {255,255,255,255});
		SDL_Rect rect = (SDL_Rect) { 10, 0, 100, 20 };
		SDL_BlitSurface(s_info1, NULL, screen, &rect);
		SDL_FreeSurface(s_info1);
		// segunda linea informacion
		sprintf(info2, "[%s] +%03d, life: %02d, dead: %02d, weapon: [%d/%03d/%03d] [%d/%03d/%03d]", conf->PLAYER_NAME, pj->health, pj->life, pj->dead, pj->primary->id, pj->primary->damage, pj->primary->ammo, pj->secondary->id, pj->secondary->damage, pj->secondary->ammo);
		SDL_Surface *s_info2 = TTF_RenderText_Blended(fuente, info2, (SDL_Color) {255,255,255,255});
		rect.y += 12;
		SDL_BlitSurface(s_info2, NULL, screen, &rect);
		SDL_FreeSurface(s_info2);
		// dibujar enemigos
		enemies_draw(screen, enemies);
		// dibujar bots
		/*for(i=0; i<conf->BOTS; ++i) {
			Player *aux = &bots[i];
			SDL_BlitSurface(aux->images[PLAYER_IMAGE_SPRITE], &aux->src, screen, &aux->sprite);
		}*/
		// dibujar jugador
		SDL_BlitSurface(pj->images[PLAYER_IMAGE_SPRITE], &pj->src, screen, &pj->sprite);
		// actualizar screen sdl
		SDL_Flip(screen);
		SDL_Delay(1000/FPS);
		// resetear ticks
		ticks = SDL_GetTicks();
	}

	// cerrar conexion al servidor
	close(connection);

	// liberar jugador
	player_free(&pj);

	// liberar armas
	weapons_free(&weapons);
	
	// libear objetos del mapa
	mapobjects_free(&mapobjects);

	// cerrar fuentes
	TTF_CloseFont(fuente);
	TTF_Quit();

	// cerrar SDL
	SDL_FreeSurface(screen);
	SDL_Quit();

	// retorno del sistema
	return EXIT_SUCCESS;

}
Example #9
0
static void
lka_imsg(struct imsgev *iev, struct imsg *imsg)
{
    struct submit_status	*ss;
    struct secret		*secret;
    struct mapel		*mapel;
    struct rule		*rule;
    struct map		*map;
    struct map		*mp;
    void			*tmp;

    if (imsg->hdr.type == IMSG_DNS_HOST || imsg->hdr.type == IMSG_DNS_MX ||
            imsg->hdr.type == IMSG_DNS_PTR) {
        dns_async(iev, imsg->hdr.type, imsg->data);
        return;
    }

    if (iev->proc == PROC_MFA) {
        switch (imsg->hdr.type) {
        case IMSG_LKA_MAIL:
            ss = imsg->data;
            ss->code = 530;
            if (ss->u.maddr.user[0] == '\0' &&
                    ss->u.maddr.domain[0] == '\0')
                ss->code = 250;
            else if (lka_verify_mail(&ss->u.maddr))
                ss->code = 250;
            imsg_compose_event(iev, IMSG_LKA_MAIL, 0, 0, -1, ss,
                               sizeof *ss);
            return;

        case IMSG_LKA_RULEMATCH:
            ss = imsg->data;
            rule = ruleset_match(&ss->envelope);
            if (rule == NULL)
                ss->code = (errno == EAGAIN) ? 451 : 530;
            else
                ss->code = (rule->r_decision == R_ACCEPT) ?
                           250 : 530;
            imsg_compose_event(iev, IMSG_LKA_RULEMATCH, 0, 0, -1,
                               ss, sizeof *ss);
            return;

        case IMSG_LKA_RCPT:
            lka_session(imsg->data);
            return;
        }
    }

    if (iev->proc == PROC_MTA) {
        switch (imsg->hdr.type) {
        case IMSG_LKA_SECRET: {
            struct map_credentials *map_credentials;

            secret = imsg->data;
            map = map_findbyname(secret->mapname);
            if (map == NULL) {
                log_warn("warn: lka: credentials map %s is missing",
                         secret->mapname);
                imsg_compose_event(iev, IMSG_LKA_SECRET, 0, 0,
                                   -1, secret, sizeof *secret);
                return;
            }
            map_credentials = map_lookup(map->m_id, secret->host,
                                         K_CREDENTIALS);
            log_debug("debug: lka: %s credentials lookup (%d)", secret->host,
                      map_credentials != NULL);
            secret->secret[0] = '\0';
            if (map_credentials == NULL)
                log_warnx("warn: %s credentials not found",
                          secret->host);
            else if (lka_encode_credentials(secret->secret,
                                            sizeof secret->secret, map_credentials) == 0)
                log_warnx("warn: %s credentials parse fail",
                          secret->host);
            imsg_compose_event(iev, IMSG_LKA_SECRET, 0, 0, -1, secret,
                               sizeof *secret);
            free(map_credentials);
            return;
        }
        }
    }

    if (iev->proc == PROC_PARENT) {
        switch (imsg->hdr.type) {
        case IMSG_CONF_START:
            env->sc_rules_reload = xcalloc(1, sizeof *env->sc_rules,
                                           "lka:sc_rules_reload");
            env->sc_maps_reload = xcalloc(1, sizeof *env->sc_maps,
                                          "lka:sc_maps_reload");
            TAILQ_INIT(env->sc_rules_reload);
            TAILQ_INIT(env->sc_maps_reload);
            return;

        case IMSG_CONF_RULE:
            rule = xmemdup(imsg->data, sizeof *rule, "lka:rule");
            TAILQ_INSERT_TAIL(env->sc_rules_reload, rule, r_entry);
            return;

        case IMSG_CONF_MAP:
            map = xmemdup(imsg->data, sizeof *map, "lka:map");
            TAILQ_INIT(&map->m_contents);
            TAILQ_INSERT_TAIL(env->sc_maps_reload, map, m_entry);

            tmp = env->sc_maps;
            env->sc_maps = env->sc_maps_reload;

            mp = map_open(map);
            if (mp == NULL)
                errx(1, "lka: could not open map \"%s\"", map->m_name);
            map_close(map, mp);

            env->sc_maps = tmp;
            return;

        case IMSG_CONF_RULE_SOURCE:
            rule = TAILQ_LAST(env->sc_rules_reload, rulelist);
            tmp = env->sc_maps;
            env->sc_maps = env->sc_maps_reload;
            rule->r_sources = map_findbyname(imsg->data);
            if (rule->r_sources == NULL)
                fatalx("lka: maps inconsistency");
            env->sc_maps = tmp;
            return;

        case IMSG_CONF_MAP_CONTENT:
            map = TAILQ_LAST(env->sc_maps_reload, maplist);
            mapel = xmemdup(imsg->data, sizeof *mapel, "lka:mapel");
            TAILQ_INSERT_TAIL(&map->m_contents, mapel, me_entry);
            return;

        case IMSG_CONF_END:
            if (env->sc_rules)
                purge_config(PURGE_RULES);
            if (env->sc_maps)
                purge_config(PURGE_MAPS);
            env->sc_rules = env->sc_rules_reload;
            env->sc_maps = env->sc_maps_reload;

            /* start fulfilling requests */
            event_add(&env->sc_ievs[PROC_MTA]->ev, NULL);
            event_add(&env->sc_ievs[PROC_MFA]->ev, NULL);
            event_add(&env->sc_ievs[PROC_SMTP]->ev, NULL);
            return;

        case IMSG_CTL_VERBOSE:
            log_verbose(*(int *)imsg->data);
            return;

        case IMSG_PARENT_FORWARD_OPEN:
            lka_session_forward_reply(imsg->data, imsg->fd);
            return;

        }
    }

    if (iev->proc == PROC_CONTROL) {
        switch (imsg->hdr.type) {
        case IMSG_LKA_UPDATE_MAP:
            map = map_findbyname(imsg->data);
            if (map == NULL) {
                log_warnx("warn: lka: no such map \"%s\"",
                          (char *)imsg->data);
                return;
            }
            map_update(map);
            return;
        }
    }

    errx(1, "lka_imsg: unexpected %s imsg", imsg_to_str(imsg->hdr.type));
}