]> git.lizzy.rs Git - dragonfireclient.git/blob - src/inventory.cpp
changed one forgotten en_US.UTF-8 to C
[dragonfireclient.git] / src / inventory.cpp
1 /*
2 Minetest-c55
3 Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 /*
21 (c) 2010 Perttu Ahola <celeron55@gmail.com>
22 */
23
24 #include "inventory.h"
25 #include "serialization.h"
26 #include "utility.h"
27 #include "debug.h"
28 #include <sstream>
29 #include "main.h"
30 #include "serverobject.h"
31 #include "content_mapnode.h"
32 #include "content_inventory.h"
33 #include "content_sao.h"
34 #include "player.h"
35
36 /*
37         InventoryItem
38 */
39
40 InventoryItem::InventoryItem(u16 count)
41 {
42         m_count = count;
43 }
44
45 InventoryItem::~InventoryItem()
46 {
47 }
48
49 InventoryItem* InventoryItem::deSerialize(std::istream &is)
50 {
51         DSTACK(__FUNCTION_NAME);
52
53         //is.imbue(std::locale("C"));
54         // Read name
55         std::string name;
56         std::getline(is, name, ' ');
57         
58         if(name == "MaterialItem")
59         {
60                 // u16 reads directly as a number (u8 doesn't)
61                 u16 material;
62                 is>>material;
63                 u16 count;
64                 is>>count;
65                 if(material > MAX_CONTENT)
66                         throw SerializationError("Too large material number");
67                 return new MaterialItem(material, count);
68         }
69         else if(name == "MBOItem")
70         {
71                 std::string inventorystring;
72                 std::getline(is, inventorystring, '|');
73                 return new MapBlockObjectItem(inventorystring);
74         }
75         else if(name == "CraftItem")
76         {
77                 std::string subname;
78                 std::getline(is, subname, ' ');
79                 u16 count;
80                 is>>count;
81                 return new CraftItem(subname, count);
82         }
83         else if(name == "ToolItem")
84         {
85                 std::string toolname;
86                 std::getline(is, toolname, ' ');
87                 u16 wear;
88                 is>>wear;
89                 return new ToolItem(toolname, wear);
90         }
91         else
92         {
93                 dstream<<"Unknown InventoryItem name=\""<<name<<"\""<<std::endl;
94                 throw SerializationError("Unknown InventoryItem name");
95         }
96 }
97
98 ServerActiveObject* InventoryItem::createSAO(ServerEnvironment *env, u16 id, v3f pos)
99 {
100         /*
101                 Create an ItemSAO
102         */
103         // Get item string
104         std::ostringstream os(std::ios_base::binary);
105         serialize(os);
106         // Create object
107         ServerActiveObject *obj = new ItemSAO(env, 0, pos, os.str());
108         return obj;
109 }
110
111 /*
112         MaterialItem
113 */
114
115 bool MaterialItem::isCookable()
116 {
117         return item_material_is_cookable(m_content);
118 }
119
120 InventoryItem *MaterialItem::createCookResult()
121 {
122         return item_material_create_cook_result(m_content);
123 }
124
125 /*
126         CraftItem
127 */
128
129 #ifndef SERVER
130 video::ITexture * CraftItem::getImage()
131 {
132         if(g_texturesource == NULL)
133                 return NULL;
134         
135         std::string name = item_craft_get_image_name(m_subname);
136
137         // Get such a texture
138         return g_texturesource->getTextureRaw(name);
139 }
140 #endif
141
142 ServerActiveObject* CraftItem::createSAO(ServerEnvironment *env, u16 id, v3f pos)
143 {
144         // Special cases
145         ServerActiveObject *obj = item_craft_create_object(m_subname, env, id, pos);
146         if(obj)
147                 return obj;
148         // Default
149         return InventoryItem::createSAO(env, id, pos);
150 }
151
152 u16 CraftItem::getDropCount()
153 {
154         // Special cases
155         s16 dc = item_craft_get_drop_count(m_subname);
156         if(dc != -1)
157                 return dc;
158         // Default
159         return InventoryItem::getDropCount();
160 }
161
162 bool CraftItem::isCookable()
163 {
164         return item_craft_is_cookable(m_subname);
165 }
166
167 InventoryItem *CraftItem::createCookResult()
168 {
169         return item_craft_create_cook_result(m_subname);
170 }
171
172 bool CraftItem::use(ServerEnvironment *env, Player *player)
173 {
174         if(item_craft_is_eatable(m_subname))
175         {
176                 s16 hp_change = item_craft_eat_hp_change(m_subname);
177                 if(player->hp + hp_change > 20)
178                         player->hp = 20;
179                 else
180                         player->hp += hp_change;
181                 return true;
182         }
183         return false;
184 }
185
186 /*
187         MapBlockObjectItem DEPRECATED
188         TODO: Remove
189 */
190 #ifndef SERVER
191 video::ITexture * MapBlockObjectItem::getImage()
192 {
193         if(m_inventorystring.substr(0,3) == "Rat")
194                 return g_texturesource->getTextureRaw("rat.png");
195         
196         if(m_inventorystring.substr(0,4) == "Sign")
197                 return g_texturesource->getTextureRaw("sign.png");
198
199         return NULL;
200 }
201 #endif
202 std::string MapBlockObjectItem::getText()
203 {
204         if(m_inventorystring.substr(0,3) == "Rat")
205                 return "";
206         
207         if(m_inventorystring.substr(0,4) == "Sign")
208                 return "";
209
210         return "obj";
211 }
212
213 MapBlockObject * MapBlockObjectItem::createObject
214                 (v3f pos, f32 player_yaw, f32 player_pitch)
215 {
216         std::istringstream is(m_inventorystring);
217         std::string name;
218         std::getline(is, name, ' ');
219         
220         if(name == "None")
221         {
222                 return NULL;
223         }
224         else if(name == "Sign")
225         {
226                 std::string text;
227                 std::getline(is, text, '|');
228                 SignObject *obj = new SignObject(NULL, -1, pos);
229                 obj->setText(text);
230                 obj->setYaw(-player_yaw);
231                 return obj;
232         }
233         else if(name == "Rat")
234         {
235                 RatObject *obj = new RatObject(NULL, -1, pos);
236                 return obj;
237         }
238         else if(name == "ItemObj")
239         {
240                 /*
241                         Now we are an inventory item containing the serialization
242                         string of an object that contains the serialization
243                         string of an inventory item. Fuck this.
244                 */
245                 //assert(0);
246                 dstream<<__FUNCTION_NAME<<": WARNING: Ignoring ItemObj "
247                                 <<"because an item-object should never be inside "
248                                 <<"an object-item."<<std::endl;
249                 return NULL;
250         }
251         else
252         {
253                 return NULL;
254         }
255 }
256
257 /*
258         Inventory
259 */
260
261 InventoryList::InventoryList(std::string name, u32 size)
262 {
263         m_name = name;
264         m_size = size;
265         clearItems();
266         //m_dirty = false;
267 }
268
269 InventoryList::~InventoryList()
270 {
271         for(u32 i=0; i<m_items.size(); i++)
272         {
273                 if(m_items[i])
274                         delete m_items[i];
275         }
276 }
277
278 void InventoryList::clearItems()
279 {
280         for(u32 i=0; i<m_items.size(); i++)
281         {
282                 if(m_items[i])
283                         delete m_items[i];
284         }
285
286         m_items.clear();
287
288         for(u32 i=0; i<m_size; i++)
289         {
290                 m_items.push_back(NULL);
291         }
292
293         //setDirty(true);
294 }
295
296 void InventoryList::serialize(std::ostream &os)
297 {
298         //os.imbue(std::locale("C"));
299         
300         for(u32 i=0; i<m_items.size(); i++)
301         {
302                 InventoryItem *item = m_items[i];
303                 if(item != NULL)
304                 {
305                         os<<"Item ";
306                         item->serialize(os);
307                 }
308                 else
309                 {
310                         os<<"Empty";
311                 }
312                 os<<"\n";
313         }
314
315         os<<"EndInventoryList\n";
316 }
317
318 void InventoryList::deSerialize(std::istream &is)
319 {
320         //is.imbue(std::locale("C"));
321
322         clearItems();
323         u32 item_i = 0;
324
325         for(;;)
326         {
327                 std::string line;
328                 std::getline(is, line, '\n');
329
330                 std::istringstream iss(line);
331                 //iss.imbue(std::locale("C"));
332
333                 std::string name;
334                 std::getline(iss, name, ' ');
335
336                 if(name == "EndInventoryList")
337                 {
338                         break;
339                 }
340                 // This is a temporary backwards compatibility fix
341                 else if(name == "end")
342                 {
343                         break;
344                 }
345                 else if(name == "Item")
346                 {
347                         if(item_i > getSize() - 1)
348                                 throw SerializationError("too many items");
349                         InventoryItem *item = InventoryItem::deSerialize(iss);
350                         m_items[item_i++] = item;
351                 }
352                 else if(name == "Empty")
353                 {
354                         if(item_i > getSize() - 1)
355                                 throw SerializationError("too many items");
356                         m_items[item_i++] = NULL;
357                 }
358                 else
359                 {
360                         throw SerializationError("Unknown inventory identifier");
361                 }
362         }
363 }
364
365 InventoryList::InventoryList(const InventoryList &other)
366 {
367         /*
368                 Do this so that the items get cloned. Otherwise the pointers
369                 in the array will just get copied.
370         */
371         *this = other;
372 }
373
374 InventoryList & InventoryList::operator = (const InventoryList &other)
375 {
376         m_name = other.m_name;
377         m_size = other.m_size;
378         clearItems();
379         for(u32 i=0; i<other.m_items.size(); i++)
380         {
381                 InventoryItem *item = other.m_items[i];
382                 if(item != NULL)
383                 {
384                         m_items[i] = item->clone();
385                 }
386         }
387         //setDirty(true);
388
389         return *this;
390 }
391
392 std::string InventoryList::getName()
393 {
394         return m_name;
395 }
396
397 u32 InventoryList::getSize()
398 {
399         return m_items.size();
400 }
401
402 u32 InventoryList::getUsedSlots()
403 {
404         u32 num = 0;
405         for(u32 i=0; i<m_items.size(); i++)
406         {
407                 InventoryItem *item = m_items[i];
408                 if(item != NULL)
409                         num++;
410         }
411         return num;
412 }
413
414 u32 InventoryList::getFreeSlots()
415 {
416         return getSize() - getUsedSlots();
417 }
418
419 InventoryItem * InventoryList::getItem(u32 i)
420 {
421         if(i > m_items.size() - 1)
422                 return NULL;
423         return m_items[i];
424 }
425
426 InventoryItem * InventoryList::changeItem(u32 i, InventoryItem *newitem)
427 {
428         assert(i < m_items.size());
429
430         InventoryItem *olditem = m_items[i];
431         m_items[i] = newitem;
432         //setDirty(true);
433         return olditem;
434 }
435
436 void InventoryList::deleteItem(u32 i)
437 {
438         assert(i < m_items.size());
439         InventoryItem *item = changeItem(i, NULL);
440         if(item)
441                 delete item;
442 }
443
444 InventoryItem * InventoryList::addItem(InventoryItem *newitem)
445 {
446         if(newitem == NULL)
447                 return NULL;
448         
449         /*
450                 First try to find if it could be added to some existing items
451         */
452         for(u32 i=0; i<m_items.size(); i++)
453         {
454                 // Ignore empty slots
455                 if(m_items[i] == NULL)
456                         continue;
457                 // Try adding
458                 newitem = addItem(i, newitem);
459                 if(newitem == NULL)
460                         return NULL; // All was eaten
461         }
462
463         /*
464                 Then try to add it to empty slots
465         */
466         for(u32 i=0; i<m_items.size(); i++)
467         {
468                 // Ignore unempty slots
469                 if(m_items[i] != NULL)
470                         continue;
471                 // Try adding
472                 newitem = addItem(i, newitem);
473                 if(newitem == NULL)
474                         return NULL; // All was eaten
475         }
476
477         // Return leftover
478         return newitem;
479 }
480
481 InventoryItem * InventoryList::addItem(u32 i, InventoryItem *newitem)
482 {
483         if(newitem == NULL)
484                 return NULL;
485         
486         //setDirty(true);
487         
488         // If it is an empty position, it's an easy job.
489         InventoryItem *to_item = getItem(i);
490         if(to_item == NULL)
491         {
492                 m_items[i] = newitem;
493                 return NULL;
494         }
495         
496         // If not addable, return the item
497         if(newitem->addableTo(to_item) == false)
498                 return newitem;
499         
500         // If the item fits fully in the slot, add counter and delete it
501         if(newitem->getCount() <= to_item->freeSpace())
502         {
503                 to_item->add(newitem->getCount());
504                 delete newitem;
505                 return NULL;
506         }
507         // Else the item does not fit fully. Add all that fits and return
508         // the rest.
509         else
510         {
511                 u16 freespace = to_item->freeSpace();
512                 to_item->add(freespace);
513                 newitem->remove(freespace);
514                 return newitem;
515         }
516 }
517
518 bool InventoryList::itemFits(u32 i, InventoryItem *newitem)
519 {
520         // If it is an empty position, it's an easy job.
521         InventoryItem *to_item = getItem(i);
522         if(to_item == NULL)
523         {
524                 return true;
525         }
526         
527         // If not addable, return the item
528         if(newitem->addableTo(to_item) == false)
529                 return false;
530         
531         // If the item fits fully in the slot, add counter and delete it
532         if(newitem->getCount() <= to_item->freeSpace())
533         {
534                 return true;
535         }
536
537         return false;
538 }
539
540 InventoryItem * InventoryList::takeItem(u32 i, u32 count)
541 {
542         if(count == 0)
543                 return NULL;
544         
545         //setDirty(true);
546
547         InventoryItem *item = getItem(i);
548         // If it is an empty position, return NULL
549         if(item == NULL)
550                 return NULL;
551         
552         if(count >= item->getCount())
553         {
554                 // Get the item by swapping NULL to its place
555                 return changeItem(i, NULL);
556         }
557         else
558         {
559                 InventoryItem *item2 = item->clone();
560                 item->remove(count);
561                 item2->setCount(count);
562                 return item2;
563         }
564         
565         return false;
566 }
567
568 void InventoryList::decrementMaterials(u16 count)
569 {
570         for(u32 i=0; i<m_items.size(); i++)
571         {
572                 InventoryItem *item = takeItem(i, count);
573                 if(item)
574                         delete item;
575         }
576 }
577
578 void InventoryList::print(std::ostream &o)
579 {
580         o<<"InventoryList:"<<std::endl;
581         for(u32 i=0; i<m_items.size(); i++)
582         {
583                 InventoryItem *item = m_items[i];
584                 if(item != NULL)
585                 {
586                         o<<i<<": ";
587                         item->serialize(o);
588                         o<<"\n";
589                 }
590         }
591 }
592
593 /*
594         Inventory
595 */
596
597 Inventory::~Inventory()
598 {
599         clear();
600 }
601
602 void Inventory::clear()
603 {
604         for(u32 i=0; i<m_lists.size(); i++)
605         {
606                 delete m_lists[i];
607         }
608         m_lists.clear();
609 }
610
611 Inventory::Inventory()
612 {
613 }
614
615 Inventory::Inventory(const Inventory &other)
616 {
617         *this = other;
618 }
619
620 Inventory & Inventory::operator = (const Inventory &other)
621 {
622         clear();
623         for(u32 i=0; i<other.m_lists.size(); i++)
624         {
625                 m_lists.push_back(new InventoryList(*other.m_lists[i]));
626         }
627         return *this;
628 }
629
630 void Inventory::serialize(std::ostream &os)
631 {
632         for(u32 i=0; i<m_lists.size(); i++)
633         {
634                 InventoryList *list = m_lists[i];
635                 os<<"List "<<list->getName()<<" "<<list->getSize()<<"\n";
636                 list->serialize(os);
637         }
638
639         os<<"EndInventory\n";
640 }
641
642 void Inventory::deSerialize(std::istream &is)
643 {
644         clear();
645
646         for(;;)
647         {
648                 std::string line;
649                 std::getline(is, line, '\n');
650
651                 std::istringstream iss(line);
652
653                 std::string name;
654                 std::getline(iss, name, ' ');
655
656                 if(name == "EndInventory")
657                 {
658                         break;
659                 }
660                 // This is a temporary backwards compatibility fix
661                 else if(name == "end")
662                 {
663                         break;
664                 }
665                 else if(name == "List")
666                 {
667                         std::string listname;
668                         u32 listsize;
669
670                         std::getline(iss, listname, ' ');
671                         iss>>listsize;
672
673                         InventoryList *list = new InventoryList(listname, listsize);
674                         list->deSerialize(is);
675
676                         m_lists.push_back(list);
677                 }
678                 else
679                 {
680                         throw SerializationError("Unknown inventory identifier");
681                 }
682         }
683 }
684
685 InventoryList * Inventory::addList(const std::string &name, u32 size)
686 {
687         s32 i = getListIndex(name);
688         if(i != -1)
689         {
690                 if(m_lists[i]->getSize() != size)
691                 {
692                         delete m_lists[i];
693                         m_lists[i] = new InventoryList(name, size);
694                 }
695                 return m_lists[i];
696         }
697         else
698         {
699                 m_lists.push_back(new InventoryList(name, size));
700                 return m_lists.getLast();
701         }
702 }
703
704 InventoryList * Inventory::getList(const std::string &name)
705 {
706         s32 i = getListIndex(name);
707         if(i == -1)
708                 return NULL;
709         return m_lists[i];
710 }
711
712 s32 Inventory::getListIndex(const std::string &name)
713 {
714         for(u32 i=0; i<m_lists.size(); i++)
715         {
716                 if(m_lists[i]->getName() == name)
717                         return i;
718         }
719         return -1;
720 }
721
722 /*
723         InventoryAction
724 */
725
726 InventoryAction * InventoryAction::deSerialize(std::istream &is)
727 {
728         std::string type;
729         std::getline(is, type, ' ');
730
731         InventoryAction *a = NULL;
732
733         if(type == "Move")
734         {
735                 a = new IMoveAction(is);
736         }
737
738         return a;
739 }
740
741 void IMoveAction::apply(InventoryContext *c, InventoryManager *mgr)
742 {
743 #if 1
744
745         /*dstream<<"from_inv="<<from_inv<<" to_inv="<<to_inv<<std::endl;
746         dstream<<"from_list="<<from_list<<" to_list="<<to_list<<std::endl;
747         dstream<<"from_i="<<from_i<<" to_i="<<to_i<<std::endl;*/
748
749         Inventory *inv_from = mgr->getInventory(c, from_inv);
750         Inventory *inv_to = mgr->getInventory(c, to_inv);
751
752         if(!inv_from || !inv_to)
753         {
754                 dstream<<__FUNCTION_NAME<<": Operation not allowed "
755                                 <<"(inventories not found)"<<std::endl;
756                 return;
757         }
758
759         InventoryList *list_from = inv_from->getList(from_list);
760         InventoryList *list_to = inv_to->getList(to_list);
761
762         /*dstream<<"list_from="<<list_from<<" list_to="<<list_to
763                         <<std::endl;*/
764         /*if(list_from)
765                 dstream<<" list_from->getItem(from_i)="<<list_from->getItem(from_i)
766                                 <<std::endl;
767         if(list_to)
768                 dstream<<" list_to->getItem(to_i)="<<list_to->getItem(to_i)
769                                 <<std::endl;*/
770         
771         /*
772                 If a list doesn't exist or the source item doesn't exist
773         */
774         if(!list_from || !list_to)
775         {
776                 dstream<<__FUNCTION_NAME<<": Operation not allowed "
777                                 <<"(a list doesn't exist)"
778                                 <<std::endl;
779                 return;
780         }
781         if(list_from->getItem(from_i) == NULL)
782         {
783                 dstream<<__FUNCTION_NAME<<": Operation not allowed "
784                                 <<"(the source item doesn't exist)"
785                                 <<std::endl;
786                 return;
787         }
788         /*
789                 If the source and the destination slots are the same
790         */
791         if(inv_from == inv_to && list_from == list_to && from_i == to_i)
792         {
793                 dstream<<__FUNCTION_NAME<<": Operation not allowed "
794                                 <<"(source and the destination slots are the same)"<<std::endl;
795                 return;
796         }
797         
798         // Take item from source list
799         InventoryItem *item1 = NULL;
800         if(count == 0)
801                 item1 = list_from->changeItem(from_i, NULL);
802         else
803                 item1 = list_from->takeItem(from_i, count);
804
805         // Try to add the item to destination list
806         InventoryItem *olditem = item1;
807         item1 = list_to->addItem(to_i, item1);
808
809         // If something is returned, the item was not fully added
810         if(item1 != NULL)
811         {
812                 // If olditem is returned, nothing was added.
813                 bool nothing_added = (item1 == olditem);
814                 
815                 // If something else is returned, part of the item was left unadded.
816                 // Add the other part back to the source item
817                 list_from->addItem(from_i, item1);
818
819                 // If olditem is returned, nothing was added.
820                 // Swap the items
821                 if(nothing_added)
822                 {
823                         // Take item from source list
824                         item1 = list_from->changeItem(from_i, NULL);
825                         // Adding was not possible, swap the items.
826                         InventoryItem *item2 = list_to->changeItem(to_i, item1);
827                         // Put item from destination list to the source list
828                         list_from->changeItem(from_i, item2);
829                 }
830         }
831
832         mgr->inventoryModified(c, from_inv);
833         if(from_inv != to_inv)
834                 mgr->inventoryModified(c, to_inv);
835 #endif
836 }
837
838 /*
839         Craft checking system
840 */
841
842 bool ItemSpec::checkItem(InventoryItem *item)
843 {
844         if(type == ITEM_NONE)
845         {
846                 // Has to be no item
847                 if(item != NULL)
848                         return false;
849                 return true;
850         }
851         
852         // There should be an item
853         if(item == NULL)
854                 return false;
855
856         std::string itemname = item->getName();
857
858         if(type == ITEM_MATERIAL)
859         {
860                 if(itemname != "MaterialItem")
861                         return false;
862                 MaterialItem *mitem = (MaterialItem*)item;
863                 if(mitem->getMaterial() != num)
864                         return false;
865         }
866         else if(type == ITEM_CRAFT)
867         {
868                 if(itemname != "CraftItem")
869                         return false;
870                 CraftItem *mitem = (CraftItem*)item;
871                 if(mitem->getSubName() != name)
872                         return false;
873         }
874         else if(type == ITEM_TOOL)
875         {
876                 // Not supported yet
877                 assert(0);
878         }
879         else if(type == ITEM_MBO)
880         {
881                 // Not supported yet
882                 assert(0);
883         }
884         else
885         {
886                 // Not supported yet
887                 assert(0);
888         }
889         return true;
890 }
891
892 bool checkItemCombination(InventoryItem **items, ItemSpec *specs)
893 {
894         u16 items_min_x = 100;
895         u16 items_max_x = 100;
896         u16 items_min_y = 100;
897         u16 items_max_y = 100;
898         for(u16 y=0; y<3; y++)
899         for(u16 x=0; x<3; x++)
900         {
901                 if(items[y*3 + x] == NULL)
902                         continue;
903                 if(items_min_x == 100 || x < items_min_x)
904                         items_min_x = x;
905                 if(items_min_y == 100 || y < items_min_y)
906                         items_min_y = y;
907                 if(items_max_x == 100 || x > items_max_x)
908                         items_max_x = x;
909                 if(items_max_y == 100 || y > items_max_y)
910                         items_max_y = y;
911         }
912         // No items at all, just return false
913         if(items_min_x == 100)
914                 return false;
915         
916         u16 items_w = items_max_x - items_min_x + 1;
917         u16 items_h = items_max_y - items_min_y + 1;
918
919         u16 specs_min_x = 100;
920         u16 specs_max_x = 100;
921         u16 specs_min_y = 100;
922         u16 specs_max_y = 100;
923         for(u16 y=0; y<3; y++)
924         for(u16 x=0; x<3; x++)
925         {
926                 if(specs[y*3 + x].type == ITEM_NONE)
927                         continue;
928                 if(specs_min_x == 100 || x < specs_min_x)
929                         specs_min_x = x;
930                 if(specs_min_y == 100 || y < specs_min_y)
931                         specs_min_y = y;
932                 if(specs_max_x == 100 || x > specs_max_x)
933                         specs_max_x = x;
934                 if(specs_max_y == 100 || y > specs_max_y)
935                         specs_max_y = y;
936         }
937         // No specs at all, just return false
938         if(specs_min_x == 100)
939                 return false;
940
941         u16 specs_w = specs_max_x - specs_min_x + 1;
942         u16 specs_h = specs_max_y - specs_min_y + 1;
943
944         // Different sizes
945         if(items_w != specs_w || items_h != specs_h)
946                 return false;
947
948         for(u16 y=0; y<specs_h; y++)
949         for(u16 x=0; x<specs_w; x++)
950         {
951                 u16 items_x = items_min_x + x;
952                 u16 items_y = items_min_y + y;
953                 u16 specs_x = specs_min_x + x;
954                 u16 specs_y = specs_min_y + y;
955                 InventoryItem *item = items[items_y * 3 + items_x];
956                 ItemSpec &spec = specs[specs_y * 3 + specs_x];
957
958                 if(spec.checkItem(item) == false)
959                         return false;
960         }
961
962         return true;
963 }
964         
965 //END