Advertisement
Guest User

Daegaladh

a guest
Mar 19th, 2012
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 9.75 KB | None | 0 0
  1. Index: status.c
  2. ===================================================================
  3. --- status.c    (revision 15734)
  4. +++ status.c    (working copy)
  5. @@ -48,10 +48,9 @@
  6.  };
  7.  
  8.  static int max_weight_base[CLASS_COUNT];
  9. -static int hp_coefficient[CLASS_COUNT];
  10. -static int hp_coefficient2[CLASS_COUNT];
  11. -static int hp_sigma_val[CLASS_COUNT][MAX_LEVEL+1];
  12. -static int sp_coefficient[CLASS_COUNT];
  13. +static unsigned int hp_table[CLASS_COUNT][MAX_LEVEL];
  14. +static unsigned int sp_table[CLASS_COUNT][MAX_LEVEL];
  15. +static unsigned int max_level[CLASS_COUNT];
  16.  static int aspd_base[CLASS_COUNT][MAX_WEAPON_TYPE];    //[blackhole89]
  17.  
  18.  // bonus values and upgrade chances for refining equipment
  19. @@ -2022,39 +2021,12 @@
  20.     return 1;
  21.  }
  22.  
  23. -/// Helper function for status_base_pc_maxhp(), used to pre-calculate the hp_sigma_val[] array
  24. -static void status_calc_sigma(void)
  25. -{
  26. -   int i,j;
  27. -
  28. -   for(i = 0; i < CLASS_COUNT; i++)
  29. -   {
  30. -       unsigned int k = 0;
  31. -       hp_sigma_val[i][0] = hp_sigma_val[i][1] = 0;
  32. -       for(j = 2; j <= MAX_LEVEL; j++)
  33. -       {
  34. -           k += (hp_coefficient[i]*j + 50) / 100;
  35. -           hp_sigma_val[i][j] = k;
  36. -           if (k >= INT_MAX)
  37. -               break; //Overflow protection. [Skotlex]
  38. -       }
  39. -       for(; j <= MAX_LEVEL; j++)
  40. -           hp_sigma_val[i][j] = INT_MAX;
  41. -   }
  42. -}
  43. -
  44. -/// Calculates base MaxHP value according to class and base level
  45. -/// The recursive equation used to calculate level bonus is (using integer operations)
  46. -///    f(0) = 35 | f(x+1) = f(x) + A + (x + B)*C/D
  47. -/// which reduces to something close to
  48. -///    f(x) = 35 + x*(A + B*C/D) + sum(i=2..x){ i*C/D }
  49. +//Calculate maxHP from tables
  50.  static unsigned int status_base_pc_maxhp(struct map_session_data* sd, struct status_data* status)
  51.  {
  52. -   unsigned int val = pc_class2idx(sd->status.class_);
  53. -   val = 35 + sd->status.base_level*hp_coefficient2[val]/100 + hp_sigma_val[val][sd->status.base_level];
  54. +   unsigned int val;
  55. +   val = hp_table[pc_class2idx(sd->status.class_)][sd->status.base_level-1];
  56.  
  57. -   if((sd->class_&MAPID_UPPERMASK) == MAPID_NINJA || (sd->class_&MAPID_UPPERMASK) == MAPID_GUNSLINGER)
  58. -       val += 100; //Since their HP can't be approximated well enough without this.
  59.     if((sd->class_&MAPID_UPPERMASK) == MAPID_TAEKWON && sd->status.base_level >= 90 && pc_famerank(sd->status.char_id, MAPID_TAEKWON))
  60.         val *= 3; //Triple max HP for top ranking Taekwons over level 90.
  61.     if((sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE && sd->status.base_level >= 99)
  62. @@ -2069,11 +2041,11 @@
  63.     return val;
  64.  }
  65.  
  66. +//Calculate maxSP from tables
  67.  static unsigned int status_base_pc_maxsp(struct map_session_data* sd, struct status_data *status)
  68.  {
  69.     unsigned int val;
  70. -
  71. -   val = 10 + sd->status.base_level*sp_coefficient[pc_class2idx(sd->status.class_)]/100;
  72. +   val = sp_table[pc_class2idx(sd->status.class_)][sd->status.base_level-1];
  73.     val += val * status->int_/100;
  74.  
  75.     if (sd->class_&JOBL_UPPER)
  76. @@ -10072,7 +10044,7 @@
  77.  
  78.  /*------------------------------------------
  79.   * DB reading.
  80. - * job_db1.txt    - weight, hp, sp, aspd
  81. + * job_db1.txt    - weight, aspd
  82.   * job_db2.txt    - job level stat bonuses
  83.   * size_fix.txt   - size adjustment table for weapons
  84.   * refine_db.txt  - refining data table
  85. @@ -10097,7 +10069,7 @@
  86.  }
  87.  #endif
  88.  static bool status_readdb_job1(char* fields[], int columns, int current)
  89. -{// Job-specific values (weight, HP, SP, ASPD)
  90. +{// Job-specific values (weight, ASPD)
  91.     int idx, class_;
  92.     unsigned int i;
  93.  
  94. @@ -10111,13 +10083,10 @@
  95.     idx = pc_class2idx(class_);
  96.  
  97.     max_weight_base[idx] = atoi(fields[1]);
  98. -   hp_coefficient[idx]  = atoi(fields[2]);
  99. -   hp_coefficient2[idx] = atoi(fields[3]);
  100. -   sp_coefficient[idx]  = atoi(fields[4]);
  101.  
  102.     for(i = 0; i < MAX_WEAPON_TYPE; i++)
  103.     {
  104. -       aspd_base[idx][i] = atoi(fields[i+5]);
  105. +       aspd_base[idx][i] = atoi(fields[i+2]);
  106.     }
  107.     return true;
  108.  }
  109. @@ -10196,9 +10165,6 @@
  110.  
  111.     // job_db1.txt
  112.     memset(max_weight_base, 0, sizeof(max_weight_base));
  113. -   memset(hp_coefficient, 0, sizeof(hp_coefficient));
  114. -   memset(hp_coefficient2, 0, sizeof(hp_coefficient2));
  115. -   memset(sp_coefficient, 0, sizeof(sp_coefficient));
  116.     memset(aspd_base, 0, sizeof(aspd_base));
  117.  #if REMODE
  118.     memset(re_job_db, 0, sizeof(re_job_db));
  119. @@ -10225,7 +10191,7 @@
  120.     // read databases
  121.     //
  122.  
  123. -   sv_readdb(db_path, "job_db1.txt",   ',', 5+MAX_WEAPON_TYPE, 5+MAX_WEAPON_TYPE, -1,                            &status_readdb_job1);
  124. +   sv_readdb(db_path, "job_db1.txt",   ',', 2+MAX_WEAPON_TYPE, 2+MAX_WEAPON_TYPE, -1,                            &status_readdb_job1);
  125.     sv_readdb(db_path, "job_db2.txt",   ',', 1,                 1+MAX_LEVEL,       -1,                            &status_readdb_job2);
  126.     sv_readdb(db_path, "size_fix.txt",  ',', MAX_WEAPON_TYPE,   MAX_WEAPON_TYPE,    ARRAYLENGTH(atkmods),         &status_readdb_sizefix);
  127.  #if REMODE
  128. @@ -10233,6 +10199,145 @@
  129.  #endif
  130.     sv_readdb(db_path, DBPATH"refine_db.txt", ',', 4+MAX_REFINE, 4+MAX_REFINE, ARRAYLENGTH(refine_info), &status_readdb_refine);
  131.  
  132. +   // job_maxhp.txt
  133. +   FILE *fp;
  134. +   char line[1024], path[1024],*p;
  135. +
  136. +   memset(hp_table,0,sizeof(hp_table));
  137. +   memset(max_level,0,sizeof(max_level));
  138. +   sprintf(path, "%s/"DBPATH"job_maxhp.txt", db_path);
  139. +   fp=fopen(path, "r");
  140. +   if(fp==NULL){
  141. +       ShowError("can't read %s\n", path);
  142. +       return 1;
  143. +   }
  144. +   while(fgets(line, sizeof(line), fp))
  145. +   {
  146. +       int jobs[CLASS_COUNT], job_count, job, job_id;
  147. +       unsigned int ui,maxlv;
  148. +       char *split[3];
  149. +       if(line[0]=='/' && line[1]=='/')
  150. +           continue;
  151. +       if (pc_split_str(line,split,3) < 3)
  152. +           continue;
  153. +      
  154. +       job_count = pc_split_atoi(split[1],jobs,':',CLASS_COUNT);
  155. +       if (job_count < 1)
  156. +           continue;
  157. +       job_id = jobs[0];
  158. +       if (!pcdb_checkid(job_id)) {
  159. +           ShowError("status_readdb: Invalid job ID %d.\n", job_id);
  160. +           continue;
  161. +       }
  162. +       maxlv = atoi(split[0]);
  163. +       if (maxlv > MAX_LEVEL) {
  164. +           ShowWarning("status_readdb: Specified max level %u for job %d is beyond server's limit (%u).\n ", maxlv, job_id, MAX_LEVEL);
  165. +           maxlv = MAX_LEVEL;
  166. +       }
  167. +      
  168. +       job = jobs[0] = pc_class2idx(job_id);
  169. +       max_level[job] = pc_split_atoui(split[2], hp_table[job],',',maxlv)+1;
  170. +       while ((ui = max_level[job]) >= 2 && hp_table[job][ui-2] <= 0)
  171. +           max_level[job]--;
  172. +       if (max_level[job] < maxlv) {
  173. +           ShowWarning("status_readdb: Specified max %u for job %d, but that job's hp table only goes up to level %u.\n", maxlv, job_id, max_level[job]);
  174. +           ShowInfo("Filling the missing values with the last hp entry.\n");
  175. +           ui = (max_level[job] <= 2? 0: max_level[job]-2);
  176. +           for (; ui+2 < maxlv; ui++)
  177. +               hp_table[job][ui] = hp_table[job][ui-1];
  178. +           max_level[job] = maxlv;
  179. +       }
  180. +
  181. +       for (i = 1; i < job_count; i++) {
  182. +           job_id = jobs[i];
  183. +           if (!pcdb_checkid(job_id)) {
  184. +               ShowError("status_readdb: Invalid job ID %d.\n", job_id);
  185. +               continue;
  186. +           }
  187. +           job = pc_class2idx(job_id);
  188. +           memcpy(hp_table[job], hp_table[jobs[0]], sizeof(hp_table[0]));
  189. +           max_level[job] = maxlv;
  190. +       }
  191. +   }
  192. +   fclose(fp);
  193. +   for (i = 0; i < JOB_MAX; i++) {
  194. +       if (!pcdb_checkid(i)) continue;
  195. +       if (i == JOB_WEDDING || i == JOB_XMAS || i == JOB_SUMMER)
  196. +           continue;
  197. +       j = pc_class2idx(i);
  198. +       if (!max_level[j])
  199. +           ShowWarning("Class %s (%d) does not has a base hp table.\n", job_name(i), i);
  200. +   }
  201. +   ShowStatus("Done reading '"CL_WHITE"%s"CL_RESET"'.\n",path);
  202. +
  203. +   // job_maxsp.txt
  204. +   memset(sp_table,0,sizeof(sp_table));
  205. +   memset(max_level,0,sizeof(max_level));
  206. +   sprintf(path, "%s/"DBPATH"job_maxsp.txt", db_path);
  207. +   fp=fopen(path, "r");
  208. +   if(fp==NULL){
  209. +       ShowError("can't read %s\n", path);
  210. +       return 1;
  211. +   }
  212. +   while(fgets(line, sizeof(line), fp))
  213. +   {
  214. +       int jobs[CLASS_COUNT], job_count, job, job_id;
  215. +       unsigned int ui,maxlv;
  216. +       char *split[3];
  217. +       if(line[0]=='/' && line[1]=='/')
  218. +           continue;
  219. +       if (pc_split_str(line,split,3) < 3)
  220. +           continue;
  221. +      
  222. +       job_count = pc_split_atoi(split[1],jobs,':',CLASS_COUNT);
  223. +       if (job_count < 1)
  224. +           continue;
  225. +       job_id = jobs[0];
  226. +       if (!pcdb_checkid(job_id)) {
  227. +           ShowError("status_readdb: Invalid job ID %d.\n", job_id);
  228. +           continue;
  229. +       }
  230. +       maxlv = atoi(split[0]);
  231. +       if (maxlv > MAX_LEVEL) {
  232. +           ShowWarning("status_readdb: Specified max level %u for job %d is beyond server's limit (%u).\n ", maxlv, job_id, MAX_LEVEL);
  233. +           maxlv = MAX_LEVEL;
  234. +       }
  235. +      
  236. +       job = jobs[0] = pc_class2idx(job_id);
  237. +       max_level[job] = pc_split_atoui(split[2], sp_table[job],',',maxlv)+1;
  238. +       while ((ui = max_level[job]) >= 2 && sp_table[job][ui-2] <= 0)
  239. +           max_level[job]--;
  240. +       if (max_level[job] < maxlv) {
  241. +           ShowWarning("status_readdb: Specified max %u for job %d, but that job's sp table only goes up to level %u.\n", maxlv, job_id, max_level[job]);
  242. +           ShowInfo("Filling the missing values with the last sp entry.\n");
  243. +           ui = (max_level[job] <= 2? 0: max_level[job]-2);
  244. +           for (; ui+2 < maxlv; ui++)
  245. +               sp_table[job][ui] = sp_table[job][ui-1];
  246. +           max_level[job] = maxlv;
  247. +       }
  248. +
  249. +       for (i = 1; i < job_count; i++) {
  250. +           job_id = jobs[i];
  251. +           if (!pcdb_checkid(job_id)) {
  252. +               ShowError("status_readdb: Invalid job ID %d.\n", job_id);
  253. +               continue;
  254. +           }
  255. +           job = pc_class2idx(job_id);
  256. +           memcpy(sp_table[job], sp_table[jobs[0]], sizeof(sp_table[0]));
  257. +           max_level[job] = maxlv;
  258. +       }
  259. +   }
  260. +   fclose(fp);
  261. +   for (i = 0; i < JOB_MAX; i++) {
  262. +       if (!pcdb_checkid(i)) continue;
  263. +       if (i == JOB_WEDDING || i == JOB_XMAS || i == JOB_SUMMER)
  264. +           continue;
  265. +       j = pc_class2idx(i);
  266. +       if (!max_level[j])
  267. +           ShowWarning("Class %s (%d) does not has a base sp table.\n", job_name(i), i);
  268. +   }
  269. +   ShowStatus("Done reading '"CL_WHITE"%s"CL_RESET"'.\n",path);
  270. +
  271.     return 0;
  272.  }
  273.  
  274. @@ -10247,7 +10352,6 @@
  275.     initChangeTables();
  276.     initDummyData();
  277.     status_readdb();
  278. -   status_calc_sigma();
  279.     natural_heal_prev_tick = gettick();
  280.     sc_data_ers = ers_new(sizeof(struct status_change_entry));
  281.     add_timer_interval(natural_heal_prev_tick + NATURAL_HEAL_INTERVAL, status_natural_heal_timer, 0, 0, NATURAL_HEAL_INTERVAL);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement