1 /*
2     XorGramana Copyright 2009 James W. Morris, james@jwm-art.net
3 
4     This file is part of XorGramana.
5 
6     XorGramana is free software: you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation, either version 3 of the License, or
9     (at your option) any later version.
10 
11     XorGramana is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15 
16     You should have received a copy of the GNU General Public License
17     along with XorGramana.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 #include "teleport.h"
20 #include "game_display.h"
21 #include "player.h"
22 #include "options.h"
23 
24 #include <stdlib.h>
25 
player_teleport(struct xor_move * pmv)26 bool player_teleport(struct xor_move* pmv)
27 {
28 /*
29     struct timespec rpause;
30     struct timespec repause;
31 */
32     unsigned int flimit=SDL_GetTicks()+TICK_COUNT;
33     su_t t;
34     xy_t chkx[4]={1,0,-1,0};
35     xy_t chky[4]={0,-1,0,1};
36     su_t i;
37     xy_t px;
38     xy_t py;
39     if((t=map_get_teleport(pmv->to_x,pmv->to_y)^1)>1)
40         return FALSE;
41     player_teleport_animate(pmv,TP_IN);
42     map->data[pmv->from_y][pmv->from_x]=ICON_FLOOR;
43 
44     game_win_show(map->teleport[t].x,map->teleport[t].y);
45 
46     /* check teleport destination has not been blown up */
47     if(map->data[map->teleport[t].y]
48                [map->teleport[t].x]==ICON_TELEPORT)
49     {
50         /* check teleport exits are not blocked */
51         for(i=0;i<4;i++){
52             px=map->teleport[t].x+chkx[i];
53             py=map->teleport[t].y+chky[i];
54             if(map->data[py][px]==ICON_FLOOR){
55                 map->data[py][px]=pmv->from_obj;
56                 map->player[player.player].x=pmv->to_x=px;
57                 map->player[player.player].y=pmv->to_y=py;
58                 game_win_get_view_for(
59                     map->teleport[t].x,
60                     map->teleport[t].y,
61                     &map->view[player.player].x,
62                     &map->view[player.player].y);
63                 player_teleport_animate(pmv,TP_OUT);
64                 game_win_display();
65                 /*  flushinp(); */
66                 return TRUE;
67             }
68         }
69     }
70     /* sorry, we can't teleport you today due to snow on the road */
71 /*
72     rpause.tv_sec=0;
73     rpause.tv_nsec=750000000L;
74     nanosleep(&rpause,&repause);
75 */
76     delay(flimit);
77     flimit=SDL_GetTicks()+TICK_COUNT;
78     pmv->to_x=pmv->from_x;
79     pmv->to_y=pmv->from_y;
80     game_win_display();
81     player_teleport_animate(pmv,TP_OUT);
82     map->data[pmv->from_y][pmv->from_x]=pmv->from_obj;
83     /*  flushinp(); */
84     return FALSE;
85 }
86 
player_teleport_animate(struct xor_move * pmv,enum TP_ANIM dir)87 void player_teleport_animate(struct xor_move* pmv, enum TP_ANIM dir)
88 {
89 /*
90     struct timespec rpause;
91     struct timespec repause;
92     xy_t x,y,stx,enx,xinc;
93     struct xy* dmxy=0;
94     struct xor_icon* icon=0;
95     if(dir==TP_IN){
96         if(!(dmxy=game_win_map_coord(pmv->from_x,pmv->from_y)))
97             return; */ /* should be unlikely */ /*
98         icon=&icons[pmv->from_obj];
99         wattrset(game_win,COLOR_PAIR(ICON_FLOOR));
100     }
101     else{
102         if(!(dmxy=game_win_map_coord(pmv->to_x,pmv->to_y)))
103             return;*/ /* should be unlikely */ /*
104         icon=&icons[pmv->from_obj];
105         wattrset(game_win,COLOR_PAIR(pmv->from_obj));
106     }
107     rpause.tv_sec=0;
108     if(player.replay)
109         rpause.tv_nsec=options_replay_speed(options->replay_speed)/5;
110     else
111         rpause.tv_nsec=12500000L;
112     for(y=dmxy->y;y<dmxy->y+ICON_H;y++){
113         if(y&1){
114             stx=dmxy->x+ICON_W-1;
115             enx=dmxy->x-1;
116             xinc=-1;
117         }
118         else{
119             stx=dmxy->x;
120             enx=dmxy->x+ICON_W;
121             xinc=1;
122         }
123         for(x=stx;x!=enx;x+=xinc){
124             mvwaddch(game_win,y,x,icon->chrs[y-dmxy->y][x-dmxy->x]);
125             wrefresh(game_win);
126             nanosleep(&rpause,&repause);
127         }
128     }
129     free(dmxy);
130     */
131 }
132