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