OSDN Git Service

[Refactor] #37353 コメント整理。 / Refactor comments.
[hengband/hengband.git] / src / z-util.c
index d11e840..a89c55a 100644 (file)
 /*
  * Convenient storage of the program name
  */
-cptr argv0 = NULL;
+concptr argv0 = NULL;
 
 
 /*
  * Determine if string "t" is equal to string "t"
  */
-bool streq(cptr a, cptr b)
+bool streq(concptr a, concptr b)
 {
        return (!strcmp(a, b));
 }
@@ -31,7 +31,7 @@ bool streq(cptr a, cptr b)
 /*
  * Determine if string "t" is a suffix of string "s"
  */
-bool suffix(cptr s, cptr t)
+bool suffix(concptr s, concptr t)
 {
        int tlen = strlen(t);
        int slen = strlen(s);
@@ -47,7 +47,7 @@ bool suffix(cptr s, cptr t)
 /*
  * Determine if string "t" is a prefix of string "s"
  */
-bool prefix(cptr s, cptr t)
+bool prefix(concptr s, concptr t)
 {
        /* Scan "t" */
        while (*t)
@@ -65,13 +65,13 @@ bool prefix(cptr s, cptr t)
 /*
  * Redefinable "plog" action
  */
-void (*plog_aux)(cptr) = NULL;
+void (*plog_aux)(concptr) = NULL;
 
 /*
  * Print (or log) a "warning" message (ala "perror()")
  * Note the use of the (optional) "plog_aux" hook.
  */
-void plog(cptr str)
+void plog(concptr str)
 {
        /* Use the "alternative" function if possible */
        if (plog_aux) (*plog_aux)(str);
@@ -85,7 +85,7 @@ void plog(cptr str)
 /*
  * Redefinable "quit" action
  */
-void (*quit_aux)(cptr) = NULL;
+void (*quit_aux)(concptr) = NULL;
 
 /*
  * Exit (ala "exit()").  If 'str' is NULL, do "exit(0)".
@@ -93,7 +93,7 @@ void (*quit_aux)(cptr) = NULL;
  * Otherwise, plog() 'str' and exit with an error code of -1.
  * But always use 'quit_aux', if set, before anything else.
  */
-void quit(cptr str)
+void quit(concptr str)
 {
        /* Attempt to use the aux function */
        if (quit_aux) (*quit_aux)(str);
@@ -116,13 +116,13 @@ void quit(cptr str)
 /*
  * Redefinable "core" action
  */
-void (*core_aux)(cptr) = NULL;
+void (*core_aux)(concptr) = NULL;
 
 /*
  * Dump a core file, after printing a warning message
  * As with "quit()", try to use the "core_aux()" hook first.
  */
-void core(cptr str)
+void core(concptr str)
 {
        char *crash = NULL;
 
@@ -282,3 +282,45 @@ int count_bits(BIT_FLAGS x)
 
        return (n);
 }
+
+/*!
+ * @brief 平方根を切り捨て整数で返す
+ * @param n 数値
+ * @return 平方根
+ */
+int mysqrt(int n)
+{
+       int tmp = n >> 1;
+       int tasu = 10;
+       int kaeriti = 1;
+
+       if (!tmp)
+       {
+               if (n) return 1;
+               else return 0;
+       }
+
+       while (tmp)
+       {
+               if ((n / tmp) < tmp)
+               {
+                       tmp >>= 1;
+               }
+               else break;
+       }
+       kaeriti = tmp;
+       while (tasu)
+       {
+               if ((n / tmp) < tmp)
+               {
+                       tasu--;
+                       tmp = kaeriti;
+               }
+               else
+               {
+                       kaeriti = tmp;
+                       tmp += tasu;
+               }
+       }
+       return kaeriti;
+}
\ No newline at end of file