Thread: Spell scribing
View Single Post
  #2  
Old 05-07-2002, 02:08 AM
kathgar
Discordant
 
Join Date: May 2002
Posts: 434
Default Code

Code:
#include <iostream>
#include <vector>
#include <string>
using namespace std;

struct SPLtemp {
	int spelllevel =0;
	int splid =0;
}


void LoadSPDat() {
	FILE *fp;
	FILE SPlist;
	
	for (int j = 0; j < SPDAT_RECORDS; j++)
		memset((char*) &spells[j], 0, sizeof(SPDat_Spell_Struct));

	if (fp = fopen(SPDat_Location, "rb"))
	{
//		if (_filelength(fp) != SPDAT_SIZE) {
//			cout << "SPDat wrong size ('" << SPDat_Location << "'), spells not loaded." << endl;
//		}
//		else
		{
			for (int i = 0; i < SPDAT_RECORDS; i++) {
				fread(&spells[i], sizeof(SPDat_Spell_Struct), 1, fp);
			}
			for (int x = 0;, x < 15; x++) {
				SPlist.open(strcat(iota(x),".spl"),w);
				SPLtemp tempsing;
				tempsing.level =0; tempsing.splid=0;
				vector<SPLtemp> buckets[7][10];
				
				//LinkedList<LinkedList<SPLtemp>> buckets;
				//LinkedList<SPLtemp> templist;
					
				int spllen =0;
				for (int i = 0; i < SPDAT_RECORDS; i++) {
					if ( spells[i].classes[x] <= 60 ) {
						tempsing.level = spells[i].classes[x]; tempsing.splid = i;
						buckets[((spells[i].classes[x])/10)][(spells[i].classes[x])%10).push_back(tempsing);
						spllen++;
						}											
				}
				
				
				
				/*int swap =0;
				do {
					for (int i = 0; i < spllen - 1; i++) {
						if( templist[i].level > templist[i+1].level) {
							tempsing = templist[i];
							templist[i] = templist[i+1];
							templist[i+1]=tempsing;
							swap = 1;
						}
				}while(swap !=0);*/
				/*for (int i =0; i < spllen; i++) {
					SPlist >> templist[i].level >> ' ' >> templist[i].splid;
				{
				*/
				
				for(int x =0; x < 7; x++)
				{
					for(int y =0; y < 10; y++)
					{
					int count = 0;
					while(count > buckets[x][y].size)
					{
						SPlist >> buckets[x][y][count].level >> ' ' >> buckets[x][y][count].splid;
						count++
					};
				}
				SPlist.close();
			
			{ 
			spells_loaded = true;
			cout << "Spells loaded from '" << SPDat_Location << "'." << endl;
		}
		fclose(fp);
	}
	else
		cout << "SPDat not found ('" << SPDat_Location << "'), spells not loaded." << endl;
}
That should parse the file and create 15 spell lists, in 1.spl = 15.spl with the format
level spellid

Now, client.cpp
Code:
client.cpp

if ((strcasecmp(sep.arg[0], "#scribespells") == 0))
		{
			if (target == 0)  {
				Message(0, "Error: #scribespells: No target");
			}
			else if (sep.arg[1][0] == 0) {
				Message(0, "Usage: #scribespells x");
			}
			else {
				int16 level = atoi(sep.arg[1]);
				if (level > 0 && (level <= 60  {
					FILE sp; sp.open(strcat(atoi(sep.arg[6]),".spl); int templvl = 0;int tempid=0; int y =1;
				sp >> templvl >> tempid;
				while(templvl >= level)
				{

					pp. spell_book[y]=tempid;
					sp >>templvl >>tempid; y++;
				};			
				else {
					Message(0, "Error: #scribespells: Invalid Level");
				}
			}
		}
Reply With Quote