Loads a group from disk
| 751 | |
| 752 | // Loads a group from disk |
| 753 | group *LoadGroup(char *filename) { |
| 754 | CFILE *ifile; |
| 755 | char tag[4]; |
| 756 | int version, level_version; |
| 757 | group *g; |
| 758 | int i; |
| 759 | |
| 760 | ifile = cfopen(filename, "rb"); |
| 761 | |
| 762 | if (!ifile) |
| 763 | return NULL; |
| 764 | |
| 765 | // Read & check tag |
| 766 | cf_ReadBytes((uint8_t *)tag, 4, ifile); |
| 767 | if (strncmp(tag, GROUP_FILE_TAG, 4)) { |
| 768 | cfclose(ifile); |
| 769 | return NULL; |
| 770 | } |
| 771 | |
| 772 | // Read & check version number |
| 773 | version = cf_ReadInt(ifile); |
| 774 | if (version > GROUP_FILE_VERSION) { |
| 775 | cfclose(ifile); |
| 776 | return NULL; |
| 777 | } |
| 778 | |
| 779 | // Check for out-of-date groups |
| 780 | if (version < 2) { |
| 781 | OutrageMessageBox("Sorry - segment groups no longer supported."); |
| 782 | cfclose(ifile); |
| 783 | return NULL; |
| 784 | } |
| 785 | |
| 786 | // Read & check level file version number |
| 787 | level_version = cf_ReadInt(ifile); |
| 788 | if (level_version > LEVEL_FILE_VERSION) { |
| 789 | cfclose(ifile); |
| 790 | return NULL; |
| 791 | } |
| 792 | |
| 793 | // Read the textures & build xlate table |
| 794 | ReadTextureList(ifile); |
| 795 | |
| 796 | // Allocate group |
| 797 | g = (group *)mem_malloc(sizeof(*g)); |
| 798 | |
| 799 | // Read group info |
| 800 | g->nrooms = cf_ReadInt(ifile); |
| 801 | g->attachroom = cf_ReadInt(ifile); |
| 802 | g->attachface = cf_ReadInt(ifile); |
| 803 | |
| 804 | // Read object, door, & trigger info |
| 805 | if (version >= 3) { |
| 806 | g->nobjects = cf_ReadInt(ifile); |
| 807 | g->ndoors = cf_ReadInt(ifile); |
| 808 | g->ntriggers = cf_ReadInt(ifile); |
| 809 | } else |
| 810 | g->nobjects = g->ndoors = g->ntriggers = 0; |
no test coverage detected