611532352c6dc4831104a7b8530699eccd6e3a8c
12 CELL_TYPE_PLAYER_INV
=1;
13 CELL_TYPE_CREWATIVE_INV
=2;
15 CELL_TYPE_FASTCRAFT
=4;
19 CELL_FLAG_INDICATOR
=$10;
34 procedure ClearLayer(n
:integer);
35 procedure LoadCurImg(img
:image
; i
:integer;);
39 function CellLayer
:integer;
40 procedure setCellLayer(n
:integer);
42 procedure initCell(cell_type
, id
, offset
, data
, x
, y
:integer; indicator
:boolean;);
43 function getCellID(i
:integer):integer;
44 function getCellData(i
:integer):integer;
45 function getCellX(i
:integer):integer;
46 function getCellY(i
:integer):integer;
47 procedure setOffset(newOffset
, i
:integer;);//i - номер смещения
48 function getOffset(i
:integer):integer;//i - номер смещения
49 function getCellOffset(i
:integer):integer;
51 function getItem(i
:integer):integer;
52 procedure setItem(val
, i
:integer);
53 function getSum(i
:integer):integer;
54 procedure setSum(val
, i
:integer);
55 procedure fixNullCell(i
:integer;);
57 procedure DrawCellLayer(i
, x
, y
:integer);
59 procedure SetWindowInfo(n
, i
:integer);
60 function GetWindowInfo(i
:integer):integer;
61 procedure SetCur(i
:integer);
62 function GetCur
:integer;
64 procedure SetCurIndex(n
, i
:integer);
65 function GetCurIndex(i
:integer):integer;
66 procedure SetCurActive(n
:boolean; i
:integer);
67 function GetCurActive(i
:integer):boolean;
68 procedure SetWindowType(wtype
:integer);
69 function GetWindowType
:integer;
71 procedure DrawCursors(n
, x
, y
:integer);
73 procedure ShiftCurrentCur(find
:integer;);
75 function FindCurrentWindowsType
:boolean;
78 uses vars
, Canvas
, console
, furnace
, chest
, inv
, func
, items_store
, Items
, ItemsLogic
;
81 last_cell
: array [0..CONST_MAX_LAYERS
] of integer;
82 inv_type
: array [0..CONST_MAX_LAYERS
, 0..CONST_MAX_CELLS
] of integer;//Name of virtual massive
83 inv_id
: array [0..CONST_MAX_LAYERS
, 0..CONST_MAX_CELLS
] of integer;//ID of real item massive
84 inv_x
, inv_y
: array [0..CONST_MAX_LAYERS
, 0..CONST_MAX_CELLS
] of integer;
85 inv_data
: array [0..CONST_MAX_LAYERS
, 0..CONST_MAX_CELLS
] of integer;
86 inv_flags
: array [0..CONST_MAX_LAYERS
, 0..CONST_MAX_CELLS
] of integer;
88 inv_offset
: array [0..CONST_MAX_LAYERS
, 0..CONST_MAX_OFFSETS
] of integer;//Offset of real item id in inventory
90 WindowType
: array [0..CONST_MAX_LAYERS
] of integer;
91 WindowInfo
: array [0..CONST_MAX_LAYERS
, 0..CONST_MAX_INFO
] of integer;
93 WindowCurCurrent
: array [0..CONST_MAX_LAYERS
] of integer;
94 WindowCurImg
: array [0..CONST_MAX_CURS
] of image
;
95 WindowCurIndex
: array [0..CONST_MAX_LAYERS
, 0..CONST_MAX_CURS
] of integer;
96 WindowCurActive
: array [0..CONST_MAX_LAYERS
, 0..CONST_MAX_CURS
] of boolean;
98 {=====[Inventory interface functions]=====}
99 procedure ClearLayer(n
:integer);
103 for i
:=0 to CONST_MAX_CELLS
do
106 inv_type
[n
, i
]:=CELL_TYPE_NULL
;
114 for i
:=0 to CONST_MAX_OFFSETS
do
117 WindowType
[n
]:=WINDOW_NULL
;
118 WindowCurCurrent
[n
]:=0;
119 for i
:=0 to CONST_MAX_INFO
do
121 for i
:=0 to CONST_MAX_CURS
do
123 WindowCurIndex
[n
, i
]:=0;
124 WindowCurActive
[n
, i
]:=false;
128 procedure LoadCurImg(img
:image
; i
:integer;);
130 WindowCurImg
[i
]:=img
;
144 function CellLayer
:integer;
149 procedure setCellLayer(n
:integer);
154 procedure initCell(cell_type
, id
, offset
, data
, x
, y
:integer; indicator
:boolean;);
159 last_cell
[layer
]:=last_cell
[layer
]+1;
161 inv_type
[layer
, i
]:=cell_type
;
162 inv_id
[layer
, i
]:=id
;
165 inv_data
[layer
, i
]:=data
;
167 inv_flags
[layer
, i
]:=(offset
and CELL_FLAG_OFFSET
);
170 inv_flags
[layer
, i
]:=inv_flags
[layer
, i
] or CELL_FLAG_INDICATOR
;
173 function getCellType(i
:integer):integer;
175 getCellType
:=inv_type
[layer
, i
];
178 function getCellX(i
:integer):integer;
180 getCellX
:=inv_x
[layer
, i
];
183 function getCellY(i
:integer):integer;
185 getCellY
:=inv_y
[layer
, i
];
188 function getCellID(i
:integer):integer;
190 getCellID
:=inv_id
[layer
, i
];
193 function getCellData(i
:integer):integer;
195 getCellData
:=inv_data
[layer
, i
];
198 function getCellFlagIndicator(i
, j
:integer):boolean;
200 getCellFlagIndicator
:=(inv_flags
[i
, j
] and CELL_FLAG_INDICATOR
)>0;
203 procedure setOffset(newOffset
, i
:integer;);
205 inv_offset
[layer
, i
]:=newOffset
;
208 function getOffset(i
:integer):integer;
210 getOffset
:=inv_offset
[layer
, i
];
213 function getCellOffset(i
:integer):integer;
215 getCellOffset
:=inv_flags
[layer
, i
] and CELL_FLAG_OFFSET
;
218 function getItemIdx(i
, n
:integer):integer;
220 id
, data
, _type
:integer;
222 id
:=inv_id
[n
, i
]+inv_offset
[n
, inv_flags
[n
, i
] and CELL_FLAG_OFFSET
];
223 _type
:=inv_type
[n
, i
];
224 data
:=inv_data
[n
, i
];
226 if _type
=CELL_TYPE_PLAYER_INV
then
227 getItemIdx
:=inv
.getItem(id
);
229 if _type
=CELL_TYPE_CREWATIVE_INV
then
230 getItemIdx
:=Items
.GetOrdinary(id
);
232 if _type
=CELL_TYPE_CHEST
then
233 getItemIdx
:=chest
.getItem(id
, data
);
235 if _type
=CELL_TYPE_FASTCRAFT
then
236 getItemIdx
:=getCraftOutItem(id
);
238 if _type
=CELL_TYPE_FURNACE
then
239 getItemIdx
:=GetFurItem(id
, data
);
242 procedure setItemIdx(val
, i
, n
:integer);
244 id
, data
, _type
:integer;
246 id
:=inv_id
[n
, i
]+inv_offset
[n
, inv_flags
[n
, i
] and CELL_FLAG_OFFSET
];
247 _type
:=inv_type
[n
, i
];
248 data
:=inv_data
[n
, i
];
250 if _type
=CELL_TYPE_PLAYER_INV
then
251 inv
.setItem(val
, id
);
253 if _type
=CELL_TYPE_CHEST
then
254 chest
.setItem(val
, id
, data
);
256 if _type
=CELL_TYPE_FURNACE
then
257 SetFurItem(val
, id
, data
);
260 function getSumIdx(i
, n
:integer):integer;
262 id
, data
, _type
:integer;
264 id
:=inv_id
[n
, i
]+inv_offset
[n
, inv_flags
[n
, i
] and CELL_FLAG_OFFSET
];
265 _type
:=inv_type
[n
, i
];
266 data
:=inv_data
[n
, i
];
268 if _type
=CELL_TYPE_PLAYER_INV
then
269 getSumIdx
:=inv
.getSum(id
);
271 if _type
=CELL_TYPE_CREWATIVE_INV
then
272 getSumIdx
:=Items
.GetMaximum(Items
.GetOrdinary(id
));
274 if _type
=CELL_TYPE_CHEST
then
275 getSumIdx
:=chest
.getSum(id
, data
);
277 if _type
=CELL_TYPE_FASTCRAFT
then
278 getSumIdx
:=getCraftOutSum(id
);
280 if _type
=CELL_TYPE_FURNACE
then
281 getSumIdx
:=GetFurSum(id
, data
);
284 procedure setSumIdx(val
, i
, n
:integer);
286 id
, data
, _type
:integer;
288 id
:=inv_id
[n
, i
]+inv_offset
[n
, inv_flags
[n
, i
] and CELL_FLAG_OFFSET
];
289 _type
:=inv_type
[n
, i
];
290 data
:=inv_data
[n
, i
];
292 if _type
=CELL_TYPE_PLAYER_INV
then
295 if _type
=CELL_TYPE_CHEST
then
296 chest
.setSum(val
, id
, data
);
298 if _type
=CELL_TYPE_FURNACE
then
299 SetFurSum(val
, id
, data
);
302 //i - индекс в таблице ячеек
303 function getItem(i
:integer):integer;
305 getItem
:=getItemIdx(i
, CellLayer
);
308 procedure setItem(val
, i
:integer);
310 setItemIdx(val
, i
, CellLayer
);
313 function getSum(i
:integer):integer;
315 getSum
:=getSumIdx(i
, CellLayer
);
318 procedure setSum(val
, i
:integer);
320 setSumIdx(val
, i
, CellLayer
);
323 procedure fixNullCell(i
:integer);
325 if (getItem(i
)<1) or (getSum(i
)<1) then
332 procedure DrawCellLayer(i
, x
, y
:integer);
336 for j
:=0 to CONST_MAX_CELLS
do
337 if inv_type
[i
, j
]<>CELL_TYPE_NULL
then
339 ItemsLogic
.Draw(getItemIdx(j
, i
), getSumIdx(j
, i
), x
+inv_x
[i
, j
], y
+inv_y
[i
, j
], getCellFlagIndicator(i
, j
));
345 procedure SetWindowInfo(n
, i
:integer);
347 WindowInfo
[CellLayer
, i
]:=n
;
350 function GetWindowInfo(i
:integer):integer;
352 GetWindowInfo
:=WindowInfo
[CellLayer
, i
];
355 procedure SetCur(i
:integer);
357 WindowCurCurrent
[CellLayer
]:=i
;
360 function GetCur
:integer;
362 GetCur
:=WindowCurCurrent
[CellLayer
];
365 procedure SetCurIndex(n
, i
:integer);
367 WindowCurIndex
[CellLayer
, i
]:=n
;
370 function GetCurIndex(i
:integer):integer;
372 GetCurIndex
:=WindowCurIndex
[CellLayer
, i
];
375 procedure SetCurActive(n
:boolean; i
:integer);
377 WindowCurActive
[CellLayer
, i
]:=n
;
380 function GetCurActive(i
:integer):boolean;
382 GetCurActive
:=WindowCurActive
[CellLayer
, i
];
385 procedure SetWindowType(wtype
:integer);
387 WindowType
[CellLayer
]:=wtype
;
390 function GetWindowType
:integer;
396 GetWindowType
:=WINDOW_NULL
;
398 GetWindowType
:=WindowType
[CellLayer
];
401 function FindCurrentWindowsType
:boolean;
405 crrwt
:=GetWindowType
;
406 for i
:=0 to CONST_MAX_LAYERS
do
407 if (WindowType
[i
]=crrwt
) and (i
<>CellLayer
) then
409 FindCurrentWindowsType
:=true;
414 procedure DrawCursors(n
, x
, y
:integer);
418 for i
:=0 to CONST_MAX_CURS
do
419 if WindowCurActive
[n
, i
] then
421 idx
:=WindowCurIndex
[n
, i
];
422 DrawImage(WindowCurImg
[i
], x
+inv_x
[n
, idx
], y
+inv_y
[n
, idx
]);
426 procedure ShiftCurrentCur(find
:integer;);
428 find_i
, find_x
, find_y
:integer;
429 res_i
, res_x
, res_y
:integer;
430 i
, tmp_x
, tmp_y
:integer;
432 find_i
:=GetCurIndex(GetCur
);
433 find_x
:=getCellX(find_i
);
434 find_y
:=getCellY(find_i
);
436 if find
=FIND_CELL_UP
then
438 if find
=FIND_CELL_DOWN
then
440 if find
=FIND_CELL_LEFT
then
442 if find
=FIND_CELL_RIGHT
then
445 for i
:=0 to CONST_MAX_CELLS
do
446 if (getCellType(i
)<>CELL_TYPE_NULL
) and (i
<>find_i
) then
450 //debug('['+i+']: tmp_y='+tmp_y+'; res_y='+res_y+';');
451 if find
=FIND_CELL_UP
then
453 if (tmp_y
<find_y
) and (tmp_y
>res_y
) and (tmp_x
>=find_x
-CELL_W
/2) and (tmp_x
<=find_x
+CELL_W
+CELL_W
/2) then
457 if find
=FIND_CELL_DOWN
then
459 if ((tmp_y
>find_y
) and (tmp_y
<res_y
)) and (tmp_x
>=find_x
-CELL_W
/2) and (tmp_x
<=find_x
+CELL_W
+CELL_W
/2) then
463 if find
=FIND_CELL_LEFT
then
465 //debug('LEFT ['+i+']: tmp_x='+tmp_x+'; find_x='+find_x+'; res_x='+res_x+';');
466 if (tmp_x
<find_x
) and (tmp_x
>res_x
) and (tmp_y
>=find_y
-CELL_H
/2) and (tmp_y
<=find_y
+CELL_H
+CELL_H
/2) then
470 if find
=FIND_CELL_RIGHT
then
472 //debug('RIGHT ['+i+']: tmp_x='+tmp_x+'; find_x='+find_x+'; res_x='+res_x+';');
473 if (tmp_x
>find_x
) and (tmp_x
<res_x
) and (tmp_y
>=find_y
-CELL_H
/2) and (tmp_y
<=find_y
+CELL_H
+CELL_H
/2) then
478 if res_i
<>find_i
then
480 res_x
:=getCellX(res_i
);
481 res_y
:=getCellY(res_i
);
484 SetCurIndex(res_i
, GetCur
);
489 WindowCurImg
[0]:=loadimage('/terrain/sun.png');
490 WindowCurImg
[1]:=loadimage('/terrain/moon_phases/moon_phase_0.png');